duvc-ctl 2.0.0
USB Video Class Camera Control Library
Loading...
Searching...
No Matches
duvc::Result< T > Class Template Reference

Result type that can contain either a value or an error. More...

#include <duvc-ctl/core/result.h>

Collaboration diagram for duvc::Result< T >:

Public Member Functions

 Result (T value)
 Create successful result with value.
 
 Result (Error error)
 Create error result.
 
 Result (ErrorCode code, std::string message="")
 Create error result from error code.
 
bool is_ok () const
 Check if result contains a value (success)
 
bool is_error () const
 Check if result contains an error.
 
const T & value () const &
 Get the value (assumes success)
 
T && value () &&
 Get the value (assumes success)
 
const Errorerror () const
 Get the error (assumes error)
 
value_or (const T &default_value) const &
 Get value or default if error.
 
value_or (T &&default_value) &&
 Get value or default if error.
 
 operator bool () const
 Boolean conversion (true if success)
 

Detailed Description

template<typename T>
class duvc::Result< T >

Result type that can contain either a value or an error.

Template Parameters
TValue type (use void for operations that don't return values)

Definition at line 75 of file result.h.

Constructor & Destructor Documentation

◆ Result() [1/3]

template<typename T >
duvc::Result< T >::Result ( T value)
inline

Create successful result with value.

Parameters
valueResult value

Definition at line 81 of file result.h.

Referenced by duvc::Result< T >::value_or().

Here is the caller graph for this function:

◆ Result() [2/3]

template<typename T >
duvc::Result< T >::Result ( Error error)
inline

Create error result.

Parameters
errorError information

Definition at line 87 of file result.h.

◆ Result() [3/3]

template<typename T >
duvc::Result< T >::Result ( ErrorCode code,
std::string message = "" )
inline

Create error result from error code.

Parameters
codeError code
messageOptional error message

Definition at line 94 of file result.h.

Member Function Documentation

◆ error()

template<typename T >
const Error & duvc::Result< T >::error ( ) const
inline

Get the error (assumes error)

Returns
Reference to error
Exceptions
std::bad_variant_accessif result is success

Definition at line 128 of file result.h.

Referenced by duvc::logitech::get_logitech_property_typed(), and duvc::KsPropertySet::get_property_typed().

Here is the caller graph for this function:

◆ is_error()

template<typename T >
bool duvc::Result< T >::is_error ( ) const
inline

Check if result contains an error.

Returns
true if error

Definition at line 107 of file result.h.

◆ is_ok()

template<typename T >
bool duvc::Result< T >::is_ok ( ) const
inline

Check if result contains a value (success)

Returns
true if successful

Definition at line 101 of file result.h.

Referenced by duvc::get(), duvc::get(), duvc::logitech::get_logitech_property_typed(), duvc::KsPropertySet::get_property_typed(), duvc::get_range(), duvc::get_range(), duvc::Result< T >::operator bool(), duvc::Result< void >::operator bool(), duvc::set(), duvc::set(), duvc::logitech::supports_logitech_properties(), duvc::Result< T >::value_or(), and duvc::Result< T >::value_or().

Here is the caller graph for this function:

◆ operator bool()

template<typename T >
duvc::Result< T >::operator bool ( ) const
inlineexplicit

Boolean conversion (true if success)

Definition at line 151 of file result.h.

References duvc::Result< T >::is_ok().

Here is the call graph for this function:

◆ value() [1/2]

template<typename T >
T && duvc::Result< T >::value ( ) &&
inline

Get the value (assumes success)

Returns
Moved value
Exceptions
std::bad_variant_accessif result is error

Definition at line 121 of file result.h.

◆ value() [2/2]

template<typename T >
const T & duvc::Result< T >::value ( ) const &
inline

Get the value (assumes success)

Returns
Reference to value
Exceptions
std::bad_variant_accessif result is error

Definition at line 114 of file result.h.

Referenced by duvc::DeviceConnection::get(), duvc::get(), duvc::get(), duvc::DeviceConnection::get(), duvc::logitech::get_logitech_property_typed(), duvc::KsPropertySet::get_property_typed(), duvc::get_range(), duvc::get_range(), duvc::DeviceConnection::set(), duvc::DeviceConnection::set(), duvc::logitech::supports_logitech_properties(), duvc::Result< T >::value_or(), and duvc::Result< T >::value_or().

Here is the caller graph for this function:

◆ value_or() [1/2]

template<typename T >
T duvc::Result< T >::value_or ( const T & default_value) const &
inline

Get value or default if error.

Parameters
default_valueDefault value to return on error
Returns
Value or default

Definition at line 135 of file result.h.

References duvc::Result< T >::is_ok(), duvc::Result< T >::Result(), and duvc::Result< T >::value().

Here is the call graph for this function:

◆ value_or() [2/2]

template<typename T >
T duvc::Result< T >::value_or ( T && default_value) &&
inline

Get value or default if error.

Parameters
default_valueDefault value to return on error
Returns
Value or default

Definition at line 144 of file result.h.

References duvc::Result< T >::is_ok(), and duvc::Result< T >::value().

Here is the call graph for this function:

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