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

Wrapper around a destination 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

 ToVariantConverter (Variant &var)
 Constructor taking a variant reference.
 
ToVariantConvertersize (SizeType n)
 Makes the variant become an Array variant. More...
 
template<typename T >
ToVariantConverteroperator() (T &&value)
 Assigns a value to the variant. More...
 
template<typename T >
ToVariantConverteroperator[] (T &&value)
 Appends an array element to the variant. More...
 
template<typename T >
ToVariantConverteroperator() (String key, T &&value)
 Appends an object member to the variant. More...
 
template<typename T , typename U >
ToVariantConverteroperator() (String key, T &&value, U &&ignored)
 Appends an object member to the variant. More...
 
Variantvariant ()
 Returns a reference to the wrapped variant.
 

Static Public Attributes

static constexpr bool convertingToVariant = true
 Indicates that this converter is used to convert to a variant.
 

Detailed Description

Wrapper around a destination Variant, used for conversions.

This wrapper provides a convenient, uniform syntax for inserting values into a destination variant.

Member Function Documentation

◆ size()

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

Makes the variant become an Array variant.

The array will reserve space for n elements.

Postcondition
this->variant().is<Array> == true
this->variant().as<Array>.capacity() >= n

◆ operator()() [1/3]

template<typename T >
ToVariantConverter & wamp::ToVariantConverter::operator() ( T &&  value)

Assigns a value to the variant.

The given value is converted to a Variant via Variant::from before being assigned.

◆ operator[]()

template<typename T >
ToVariantConverter & wamp::ToVariantConverter::operator[] ( T &&  value)

Appends an array element to the variant.

If the destination Variant is not already an Array, it will be transformed into an array and all previously stored values will be cleared.

Postcondition
this->variant().is<Array> == true

◆ operator()() [2/3]

template<typename T >
ToVariantConverter & wamp::ToVariantConverter::operator() ( String  key,
T &&  value 
)

Appends an object member to the variant.

If the destination Variant is not already an Object, it will be transformed into an object and all previously stored values will be cleared.

Postcondition
this->variant().is<Object> == true

◆ operator()() [3/3]

template<typename T , typename U >
ToVariantConverter & wamp::ToVariantConverter::operator() ( String  key,
T &&  value,
U &&  ignored 
)

Appends an object member to the variant.

If the destination Variant is not already an Object, it will be transformed into an object and all previously stored values will be cleared.

Postcondition
this->variant().is<Object> == true

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