Oboe
A library for creating real-time audio apps on Android
|
#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< T > | createBasedOnSign (T numericResult) |
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()); }
|
inline |
Construct a ResultWithValue containing an error result.
error | The error |
|
inlineexplicit |
Construct a ResultWithValue containing an OK result and a value.
value | the value to store |
|
inlinestatic |
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.
|
inline |
Get the result.
|
inlineexplicit |
|
inline |
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 }
|
inline |
Quick way to check for an error.
The caller could write something like this: if (!result) { printf("Got error %s\n", convertToText(result.error())); }
|
inline |
Get the value