CppWAMP
C++11 client library for the WAMP protocol
|
Wrapper around a source Variant, used for conversions. More...
#include <cppwamp/variant.hpp>
Public Types | |
using | SizeType = size_t |
Integer type used to represent the size of array variants. | |
using | String = std::string |
String type used to represent an object variant key. | |
Public Member Functions | |
FromVariantConverter (const Variant &var) | |
Constructor taking a constant variant reference. | |
SizeType | size () const |
Obtains the current size of the variant. More... | |
FromVariantConverter & | size (SizeType &n) |
Obtains the current size of the variant. More... | |
template<typename T > | |
FromVariantConverter & | operator() (T &value) |
Retrieves a non-composite value from the variant. More... | |
template<typename T > | |
FromVariantConverter & | operator[] (T &value) |
Retrieves the next element from an Array variant. More... | |
template<typename T > | |
FromVariantConverter & | operator() (const String &key, T &value) |
Retrieves a member from an Object variant. More... | |
template<typename T , typename U > | |
FromVariantConverter & | operator() (const String &key, T &value, U &&fallback) |
Retrieves a member from an Object variant, with a fallback value if the member is not found. More... | |
const Variant & | variant () const |
Returns a constant reference to the wrapped variant. | |
Static Public Attributes | |
static constexpr bool | convertingToVariant = false |
Indicates that this converter is used to convert from a variant. | |
Wrapper around a source Variant, used for conversions.
This wrapper provides a convenient, uniform syntax for retrieving values from a source variant.
|
inline |
|
inline |
FromVariantConverter & wamp::FromVariantConverter::operator() | ( | T & | value | ) |
Retrieves a non-composite value from the variant.
The variant's value is converted to the destination type via Variant::to.
error::Conversion | if the variant is not convertible to the destination type. |
FromVariantConverter & wamp::FromVariantConverter::operator[] | ( | T & | value | ) |
Retrieves the next element from an Array variant.
The element is converted to the destination type via Variant::to.
error::Conversion | if the variant is not an array. |
error::Conversion | if there are no elements left in the variant array. |
error::Conversion | if the element is not convertible to the destination type. |
FromVariantConverter & wamp::FromVariantConverter::operator() | ( | const String & | key, |
T & | value | ||
) |
Retrieves a member from an Object variant.
The member is converted to the destination type via Variant::to.
error::Conversion | if the variant is not an object. |
error::Conversion | if there doesn't exist a member with the given key. |
error::Conversion | if the member is not convertible to the destination type. |
FromVariantConverter & wamp::FromVariantConverter::operator() | ( | const String & | key, |
T & | value, | ||
U && | fallback | ||
) |
Retrieves a member from an Object variant, with a fallback value if the member is not found.
The member is converted to the destination type via Variant::to.
error::Conversion | if the variant is not an object. |
error::Conversion | if the existing member is not convertible to the destination type. |