![]() |
Fove SDK
v1.3.1
|
Class for return values from the C++ API. More...
#include <FoveAPI.h>
Public Member Functions | |
Result ()=default | |
Constructs a result with None a default-initialized value. | |
Result (const ErrorCode err) | |
Constructs a result with an error and a default-initialized value. | |
Result (const ErrorCode err, const Value &data) | |
Constructs a result with an error and a value. | |
Result (const ErrorCode err, Value &&data) | |
Constructs a result with an error and a value. | |
Result (const Value &data) | |
Constructs a result with None and a value. | |
Result (Value &&data) | |
Constructs a result with None and a value. | |
ErrorCode | getError () const |
Returns the error code. | |
ErrorCode & | getErrorMutable () |
Value & | getValue () & |
Returns the value if isValid() is true, otherwise throws. | |
Value && | getValue () && |
Returns the value if isValid() is true, otherwise throws. | |
const Value & | getValue () const & |
Returns the value if isValid() is true, otherwise throws. | |
const Value & | getValueUnchecked () const |
Returns the value without checking the error field. More... | |
Value & | getValueUncheckedMutable () |
bool | isReliable () const |
Returns true if the returned data is reliable, this is a subset of isValid() | |
bool | isValid () const |
Returns true if the returned data is valid. | |
operator bool () const | |
Explicit conversion to bool, for use in if statements. | |
Value & | operator* () |
Pointer-like semantics to fetch value, throws if invalid. | |
Value const & | operator* () const |
Pointer-like semantics to fetch value, throws if invalid. | |
Value * | operator-> () |
Pointer-like semantics to fetch value, throws if invalid. | |
Value const * | operator-> () const |
Pointer-like semantics to fetch value, throws if invalid. | |
void | throwIfInvalid () const |
Throws if there is an error, otherwise is a no-op. More... | |
Value | valueOr (Value defValue) const |
Returns the value if available, otherwise returns the provided default. More... | |
Static Public Member Functions | |
template<typename Call , typename... Args> | |
static Result | invoke (Call *call, const Args... args) |
Helper function to create an error by calling a C API function. | |
template<typename ItemType , typename Call , typename Callback , typename... Args> | |
static Result | invokeCallback (Call *call, Callback &&callback, const Args... args) |
Variant of invoke for functions that return a client-provided callback. | |
template<typename Call , typename... Args> | |
static Result | invokeStereo (Call *call, const Args... args) |
Variant of invoke for functions that have a left and a right output. | |
template<typename ItemType , typename Call , typename... Args> | |
static Result | invokeThroughCallback (Call *call, const Args... args) |
Variant of invoke for functions that get the value through a callback. | |
template<typename ItemType , typename Call , typename... Args> | |
static Result | invokeVector (Call *call, const Args... args) |
Variant of invoke for functions that return a client-side-allocated array. | |
Class for return values from the C++ API.
This class hold an error code, and possible a value if there was not a severe error. Usually there is an error OR a value, but some errors (eg Data_LowAccuracy) coexist with a value.
Whether or not there is a value is determined by isValid(). If the value of an invalid result is requested, an exception is thrown. If you do not want exceptions to be thrown, make sure to check the isValid() first.
nullptr_t is a special type that indicates "no value", just an error field.
const Value& Fove::Result< Value >::getValueUnchecked | ( | ) | const |
Returns the value without checking the error field.
It is expected that the error was checked manually before calling this field, for example via throwIfInvalid(). The return value is undefined if isValid() is false.
void Fove::Result< Value >::throwIfInvalid | ( | ) | const |
Throws if there is an error, otherwise is a no-op.
If exceptions are disabled, this will terminate the program instead of throwing.
Value Fove::Result< Value >::valueOr | ( | Value | defValue | ) | const |
Returns the value if available, otherwise returns the provided default.
defValue | A value to return if this object is not valid |