open62541pp 0.15.0
C++ wrapper of open62541
Loading...
Searching...
No Matches
opcua::Result< T > Class Template Reference

#include <result.hpp>

Detailed Description

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

The template class Result encapsulates a StatusCode and optionally a value.

A result may have one of the following contents:

Result<void> is a template specialization containing only a StatusCode.

The design is inspired by:

Examples
method/client_method_async.cpp.

Definition at line 53 of file result.hpp.

Public Types

using ValueType = T
 

Public Member Functions

constexpr Result () noexcept(std::is_nothrow_default_constructible_v< T >)
 
constexpr Result (const T &value, StatusCode code=UA_STATUSCODE_GOOD) noexcept(std::is_nothrow_copy_constructible_v< T >)
 
constexpr Result (T &&value, StatusCode code=UA_STATUSCODE_GOOD) noexcept(std::is_nothrow_move_constructible_v< T >)
 
constexpr Result (BadResult error) noexcept
 
constexpr T * operator-> () noexcept
 
constexpr const T * operator-> () const noexcept
 
constexpr T & operator* () &noexcept
 
constexpr const T & operator* () const &noexcept
 
constexpr T && operator* () &&noexcept
 
constexpr const T && operator* () const &&noexcept
 
constexpr StatusCode code () const noexcept
 
constexpr operator bool () const noexcept
 
constexpr bool hasValue () const noexcept
 
constexpr T & value () &
 
constexpr const T & value () const &
 
constexpr T && value () &&
 
constexpr const T && value () const &&
 
template<typename U >
constexpr T valueOr (U &&defaultValue) const &
 
template<typename U >
constexpr T valueOr (U &&defaultValue) &&
 
template<typename F >
constexpr auto transform (F &&func) &
 
template<typename F >
constexpr auto transform (F &&func) const &
 
template<typename F >
constexpr auto transform (F &&func) &&
 
template<typename F >
constexpr auto transform (F &&func) const &&
 
template<typename F >
constexpr auto andThen (F &&func) &
 
template<typename F >
constexpr auto andThen (F &&func) const &
 
template<typename F >
constexpr auto andThen (F &&func) &&
 
template<typename F >
constexpr auto andThen (F &&func) const &&
 
template<typename F >
constexpr auto orElse (F &&func) &
 
template<typename F >
constexpr auto orElse (F &&func) const &
 
template<typename F >
constexpr auto orElse (F &&func) &&
 
template<typename F >
constexpr auto orElse (F &&func) const &&
 

Member Typedef Documentation

◆ ValueType

template<typename T >
using opcua::Result< T >::ValueType = T

Definition at line 55 of file result.hpp.

Constructor & Destructor Documentation

◆ Result() [1/4]

template<typename T >
opcua::Result< T >::Result ( )
inlineconstexprnoexcept

Default constructor (default-initialized value and good StatusCode).

Definition at line 60 of file result.hpp.

◆ Result() [2/4]

template<typename T >
opcua::Result< T >::Result ( const T & value,
StatusCode code = UA_STATUSCODE_GOOD )
inlineconstexprnoexcept

Construct a Result with a value and a StatusCode (good or uncertain).

Definition at line 69 of file result.hpp.

◆ Result() [3/4]

template<typename T >
opcua::Result< T >::Result ( T && value,
StatusCode code = UA_STATUSCODE_GOOD )
inlineconstexprnoexcept

Construct a Result with a value and a StatusCode (good or uncertain).

Definition at line 80 of file result.hpp.

◆ Result() [4/4]

template<typename T >
opcua::Result< T >::Result ( BadResult< T > error)
inlineconstexprnoexcept

Create a Result with the given error.

Definition at line 91 of file result.hpp.

Member Function Documentation

◆ operator->() [1/2]

template<typename T >
T * opcua::Result< T >::operator-> ( )
inlineconstexprnoexcept

Get the value of the Result.

Accessing a Result without a value leads to undefined behavior.

Definition at line 103 of file result.hpp.

◆ operator->() [2/2]

template<typename T >
const T * opcua::Result< T >::operator-> ( ) const
inlineconstexprnoexcept

Get the value of the Result.

Accessing a Result without a value leads to undefined behavior.

Definition at line 108 of file result.hpp.

◆ operator*() [1/4]

template<typename T >
T & opcua::Result< T >::operator* ( ) &
inlineconstexprnoexcept

Get the value of the Result.

Accessing a Result without a value leads to undefined behavior.

Definition at line 116 of file result.hpp.

◆ operator*() [2/4]

template<typename T >
const T & opcua::Result< T >::operator* ( ) const &
inlineconstexprnoexcept

Get the value of the Result.

Accessing a Result without a value leads to undefined behavior.

Definition at line 121 of file result.hpp.

◆ operator*() [3/4]

template<typename T >
T && opcua::Result< T >::operator* ( ) &&
inlineconstexprnoexcept

Get the value of the Result.

Accessing a Result without a value leads to undefined behavior.

Definition at line 126 of file result.hpp.

◆ operator*() [4/4]

template<typename T >
const T && opcua::Result< T >::operator* ( ) const &&
inlineconstexprnoexcept

Get the value of the Result.

Accessing a Result without a value leads to undefined behavior.

Definition at line 131 of file result.hpp.

◆ code()

template<typename T >
StatusCode opcua::Result< T >::code ( ) const
inlineconstexprnoexcept

Get the StatusCode of the Result.

Definition at line 140 of file result.hpp.

Referenced by opcua::services::browseAll(), and opcua::Result< void >::value().

◆ operator bool()

template<typename T >
opcua::Result< T >::operator bool ( ) const
inlineexplicitconstexprnoexcept

Check if the Result has a value.

Definition at line 147 of file result.hpp.

◆ hasValue()

template<typename T >
bool opcua::Result< T >::hasValue ( ) const
inlineconstexprnoexcept

Check if the Result has a value.

Definition at line 154 of file result.hpp.

Referenced by opcua::Result< T >::operator bool(), and opcua::Result< void >::operator bool().

◆ value() [1/4]

template<typename T >
T & opcua::Result< T >::value ( ) &
inlineconstexpr

Get the value of the Result.

Exceptions
BadStatusIf the Result does not have a value (bad StatusCode).

Definition at line 162 of file result.hpp.

Referenced by opcua::services::browseAll().

◆ value() [2/4]

template<typename T >
const T & opcua::Result< T >::value ( ) const &
inlineconstexpr

Get the value of the Result.

Exceptions
BadStatusIf the Result does not have a value (bad StatusCode).

Definition at line 168 of file result.hpp.

◆ value() [3/4]

template<typename T >
T && opcua::Result< T >::value ( ) &&
inlineconstexpr

Get the value of the Result.

Exceptions
BadStatusIf the Result does not have a value (bad StatusCode).

Definition at line 174 of file result.hpp.

◆ value() [4/4]

template<typename T >
const T && opcua::Result< T >::value ( ) const &&
inlineconstexpr

Get the value of the Result.

Exceptions
BadStatusIf the Result does not have a value (bad StatusCode).

Definition at line 180 of file result.hpp.

◆ valueOr() [1/2]

template<typename T >
template<typename U >
T opcua::Result< T >::valueOr ( U && defaultValue) const &
inlineconstexpr

Get the value of the Result or a default value.

The default value is returned in case of an bad StatusCode.

Definition at line 190 of file result.hpp.

◆ valueOr() [2/2]

template<typename T >
template<typename U >
T opcua::Result< T >::valueOr ( U && defaultValue) &&
inlineconstexpr

Get the value of the Result or a default value.

The default value is returned in case of an bad StatusCode.

Definition at line 196 of file result.hpp.

◆ transform() [1/4]

template<typename T >
template<typename F >
auto opcua::Result< T >::transform ( F && func) &
inlineconstexpr

Transforms Result<T> to Result<U> using the given value transformation function.

The function is only applied if the Result has a value. Otherwise Result<U> with the same bad StatusCode is returned.

Parameters
funcCallable with the signature U(T&&)

Definition at line 207 of file result.hpp.

◆ transform() [2/4]

template<typename T >
template<typename F >
auto opcua::Result< T >::transform ( F && func) const &
inlineconstexpr

Transforms Result<T> to Result<U> using the given value transformation function.

The function is only applied if the Result has a value. Otherwise Result<U> with the same bad StatusCode is returned.

Parameters
funcCallable with the signature U(T&&)

Definition at line 213 of file result.hpp.

◆ transform() [3/4]

template<typename T >
template<typename F >
auto opcua::Result< T >::transform ( F && func) &&
inlineconstexpr

Transforms Result<T> to Result<U> using the given value transformation function.

The function is only applied if the Result has a value. Otherwise Result<U> with the same bad StatusCode is returned.

Parameters
funcCallable with the signature U(T&&)

Definition at line 219 of file result.hpp.

◆ transform() [4/4]

template<typename T >
template<typename F >
auto opcua::Result< T >::transform ( F && func) const &&
inlineconstexpr

Transforms Result<T> to Result<U> using the given value transformation function.

The function is only applied if the Result has a value. Otherwise Result<U> with the same bad StatusCode is returned.

Parameters
funcCallable with the signature U(T&&)

Definition at line 225 of file result.hpp.

◆ andThen() [1/4]

template<typename T >
template<typename F >
auto opcua::Result< T >::andThen ( F && func) &
inlineconstexpr

Transforms Result<T> to Result<U> using the given function.

The function is only applied if the Result has a value. Otherwise Result<U> with the same bad StatusCode is returned.

Parameters
funcCallable with the signature Result<U>(T&&) or Result<U>(T&&, StatusCode)

Definition at line 236 of file result.hpp.

◆ andThen() [2/4]

template<typename T >
template<typename F >
auto opcua::Result< T >::andThen ( F && func) const &
inlineconstexpr

Transforms Result<T> to Result<U> using the given function.

The function is only applied if the Result has a value. Otherwise Result<U> with the same bad StatusCode is returned.

Parameters
funcCallable with the signature Result<U>(T&&) or Result<U>(T&&, StatusCode)

Definition at line 242 of file result.hpp.

◆ andThen() [3/4]

template<typename T >
template<typename F >
auto opcua::Result< T >::andThen ( F && func) &&
inlineconstexpr

Transforms Result<T> to Result<U> using the given function.

The function is only applied if the Result has a value. Otherwise Result<U> with the same bad StatusCode is returned.

Parameters
funcCallable with the signature Result<U>(T&&) or Result<U>(T&&, StatusCode)

Definition at line 248 of file result.hpp.

◆ andThen() [4/4]

template<typename T >
template<typename F >
auto opcua::Result< T >::andThen ( F && func) const &&
inlineconstexpr

Transforms Result<T> to Result<U> using the given function.

The function is only applied if the Result has a value. Otherwise Result<U> with the same bad StatusCode is returned.

Parameters
funcCallable with the signature Result<U>(T&&) or Result<U>(T&&, StatusCode)

Definition at line 254 of file result.hpp.

◆ orElse() [1/4]

template<typename T >
template<typename F >
auto opcua::Result< T >::orElse ( F && func) &
inlineconstexpr

Transforms Result<T> with a bad StatusCode to Result<T> using the given function.

The function is only applied if the Result has no value. Otherwise the same Result<T> is returned.

Parameters
funcCallable with the signature Result<T>(StatusCode)

Definition at line 265 of file result.hpp.

◆ orElse() [2/4]

template<typename T >
template<typename F >
auto opcua::Result< T >::orElse ( F && func) const &
inlineconstexpr

Transforms Result<T> with a bad StatusCode to Result<T> using the given function.

The function is only applied if the Result has no value. Otherwise the same Result<T> is returned.

Parameters
funcCallable with the signature Result<T>(StatusCode)

Definition at line 271 of file result.hpp.

◆ orElse() [3/4]

template<typename T >
template<typename F >
auto opcua::Result< T >::orElse ( F && func) &&
inlineconstexpr

Transforms Result<T> with a bad StatusCode to Result<T> using the given function.

The function is only applied if the Result has no value. Otherwise the same Result<T> is returned.

Parameters
funcCallable with the signature Result<T>(StatusCode)

Definition at line 277 of file result.hpp.

◆ orElse() [4/4]

template<typename T >
template<typename F >
auto opcua::Result< T >::orElse ( F && func) const &&
inlineconstexpr

Transforms Result<T> with a bad StatusCode to Result<T> using the given function.

The function is only applied if the Result has no value. Otherwise the same Result<T> is returned.

Parameters
funcCallable with the signature Result<T>(StatusCode)

Definition at line 283 of file result.hpp.