CppWAMP
C++11 client library for the WAMP protocol
wamp::FromVariantConverter Class Reference

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...
 
FromVariantConvertersize (SizeType &n)
 Obtains the current size of the variant. More...
 
template<typename T >
FromVariantConverteroperator() (T &value)
 Retrieves a non-composite value from the variant. More...
 
template<typename T >
FromVariantConverteroperator[] (T &value)
 Retrieves the next element from an Array variant. More...
 
template<typename T >
FromVariantConverteroperator() (const String &key, T &value)
 Retrieves a member from an Object variant. More...
 
template<typename T , typename U >
FromVariantConverteroperator() (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 Variantvariant () 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.
 

Detailed Description

Wrapper around a source Variant, used for conversions.

This wrapper provides a convenient, uniform syntax for retrieving values from a source variant.

Member Function Documentation

◆ size() [1/2]

FromVariantConverter::SizeType wamp::FromVariantConverter::size ( ) const
inline

Obtains the current size of the variant.

Returns this->variant()->size().

See also
Variant::size

◆ size() [2/2]

FromVariantConverter & wamp::FromVariantConverter::size ( SizeType n)
inline

Obtains the current size of the variant.

Returns this->variant()->size().

See also
Variant::size

◆ operator()() [1/3]

template<typename T >
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.

Precondition
The variant is convertible to the destination type.
Exceptions
error::Conversionif the variant is not convertible to the destination type.

◆ operator[]()

template<typename T >
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.

Precondition
The variant is an array.
There are elements left in the variant array.
The element is convertible to the destination type.
Exceptions
error::Conversionif the variant is not an array.
error::Conversionif there are no elements left in the variant array.
error::Conversionif the element is not convertible to the destination type.

◆ operator()() [2/3]

template<typename T >
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.

Precondition
The variant is an object.
There exists a member with the given key.
The member is convertible to the destination type.
Exceptions
error::Conversionif the variant is not an object.
error::Conversionif there doesn't exist a member with the given key.
error::Conversionif the member is not convertible to the destination type.

◆ operator()() [3/3]

template<typename T , typename U >
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.

Precondition
The variant is an object.
The member, if it exists, is convertible to the destination type.
Exceptions
error::Conversionif the variant is not an object.
error::Conversionif the existing member is not convertible to the destination type.

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