Fove SDK  v0.16.0
Public Member Functions | Static Public Member Functions | List of all members
Fove::Result< Value > Class Template Reference

Class for return values from the C++ API. More...

#include <FoveAPI.h>

Public Member Functions

 Result ()=default
 Constructs a result with a default-initialized value.
 
 Result (const ErrorCode err)
 Constructs a result with an error.
 
 Result (const Value &data)
 Constructs a result with a value.
 
 Result (Value &&data)
 Move constructor.
 
ErrorCode getError () const
 Returns the error code.
 
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...
 
bool isValid () const
 Returns true if there is no error.
 
 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 Call , typename... Args>
static Result invokeStereo (Call *call, const Args... args)
 Variant of invoke for functions that have a left and a right output.
 

Detailed Description

template<typename Value = std::nullptr_t>
class Fove::Result< Value >

Class for return values from the C++ API.

This class represents either an error or a value, similar to std::variant<ErrorCode, Value> but without including C++17 The there is an error and the value is requested, an exception will be thrown.

nullptr_t is a special type that indicates "no value", just an error field.

Member Function Documentation

◆ getValueUnchecked()

template<typename Value = std::nullptr_t>
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.

Here is the caller graph for this function:

◆ throwIfInvalid()

template<typename Value = std::nullptr_t>
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.

◆ valueOr()

template<typename Value = std::nullptr_t>
Value Fove::Result< Value >::valueOr ( Value  defValue) const

Returns the value if available, otherwise returns the provided default.

Parameters
defValueA value to return if this object is not valid