A library for creating real-time audio apps on Android
No Matches
Public Member Functions | Static Public Member Functions | List of all members
oboe::ResultWithValue< T > Class Template Reference

#include <ResultWithValue.h>

Public Member Functions

 ResultWithValue (oboe::Result error)
 ResultWithValue (T value)
oboe::Result error () const
T value () const
 operator bool () const
bool operator! () const
 operator Result () const

Static Public Member Functions

static ResultWithValue< TcreateBasedOnSign (T numericResult)

Detailed Description

template<typename T>
class oboe::ResultWithValue< T >

A ResultWithValue can store both the result of an operation (either OK or an error) and a value.

It has been designed for cases where the caller needs to know whether an operation succeeded and, if it did, a value which was obtained during the operation.

For example, when reading from a stream the caller needs to know the result of the read operation and, if it was successful, how many frames were read. Note that ResultWithValue can be evaluated as a boolean so it's simple to check whether the result is OK.

ResultWithValue<int32_t> resultOfRead = myStream.read(&buffer, numFrames, timeoutNanoseconds);

if (resultOfRead) { LOGD("Frames read: %d", resultOfRead.value()); } else { LOGD("Error reading from stream: %s", resultOfRead.error()); }

Constructor & Destructor Documentation

◆ ResultWithValue() [1/2]

template<typename T >
oboe::ResultWithValue< T >::ResultWithValue ( oboe::Result  error)

Construct a ResultWithValue containing an error result.

errorThe error

◆ ResultWithValue() [2/2]

template<typename T >
oboe::ResultWithValue< T >::ResultWithValue ( T  value)

Construct a ResultWithValue containing an OK result and a value.

valuethe value to store

Member Function Documentation

◆ createBasedOnSign()

template<typename T >
static ResultWithValue< T > oboe::ResultWithValue< T >::createBasedOnSign ( T  numericResult)

Create a ResultWithValue from a number. If the number is positive the ResultWithValue will have a result of Result::OK and the value will contain the number. If the number is negative the result will be obtained from the negative number (numeric error codes can be found in AAudio.h) and the value will be null.

◆ error()

template<typename T >
oboe::Result oboe::ResultWithValue< T >::error ( ) const

Get the result.

the result

◆ operator bool()

template<typename T >
oboe::ResultWithValue< T >::operator bool ( ) const
true if OK

◆ operator Result()

template<typename T >
oboe::ResultWithValue< T >::operator Result ( ) const

Implicitly convert to a Result. This enables easy comparison with Result values. Example:

ResultWithValue result = openStream(); if (result == Result::ErrorNoMemory){ // tell user they're out of memory }

◆ operator!()

template<typename T >
bool oboe::ResultWithValue< T >::operator! ( ) const

Quick way to check for an error.

The caller could write something like this: if (!result) { printf("Got error %s\n", convertToText(result.error())); }

true if an error occurred

◆ value()

template<typename T >
T oboe::ResultWithValue< T >::value ( ) const

Get the value


The documentation for this class was generated from the following file: