CppWAMP
C++11 client library for the WAMP protocol
variant.hpp File Reference

Contains the declaration of Variant and other closely related types/functions. More...

#include <algorithm>
#include <cstdint>
#include <map>
#include <ostream>
#include <sstream>
#include <stdexcept>
#include <string>
#include <type_traits>
#include <utility>
#include <vector>
#include "api.hpp"
#include "blob.hpp"
#include "conversionaccess.hpp"
#include "error.hpp"
#include "null.hpp"
#include "traits.hpp"
#include "variantdefs.hpp"
#include "visitor.hpp"
#include "internal/varianttraits.hpp"
#include "internal/variantvisitors.hpp"
#include "internal/variant.ipp"

Go to the source code of this file.

Classes

class  wamp::Variant
 Discriminated union container that represents a JSON value. More...
 
class  wamp::ToVariantConverter
 Wrapper around a destination Variant, used for conversions. More...
 
class  wamp::FromVariantConverter
 Wrapper around a source Variant, used for conversions. More...
 

Namespaces

 wamp
 

Macros

#define CPPWAMP_CONVERSION_SPLIT_FREE(Type)
 Splits the convert free function for the given custom type. More...
 
#define CPPWAMP_CONVERSION_SPLIT_MEMBER(Type)
 Splits the convert member function for the given custom type. More...
 

Functions

template<typename TConverter , typename TValue , DisableIf< std::is_enum< TValue >::value > = 0>
void wamp::convert (TConverter &c, TValue &val)
 General function for converting custom types to/from Variant. More...
 
template<typename TEnum , EnableIf< std::is_enum< TEnum >::value > = 0>
void wamp::convert (const FromVariantConverter &c, TEnum &e)
 Converts an integer variant to an enumerator.
 
template<typename TEnum , EnableIf< std::is_enum< TEnum >::value > = 0>
void wamp::convert (ToVariantConverter &c, const TEnum &e)
 Converts an enumerator to an integer variant.
 

Detailed Description

Contains the declaration of Variant and other closely related types/functions.

Macro Definition Documentation

◆ CPPWAMP_CONVERSION_SPLIT_FREE

#define CPPWAMP_CONVERSION_SPLIT_FREE (   Type)
Value:
inline void convert(::wamp::FromVariantConverter& c, Type& obj) \
{ \
convertFrom(c, obj); \
} \
\
inline void convert(::wamp::ToVariantConverter& c, Type& obj) \
{ \
convertTo(c, const_cast<const Type&>(obj)); \
}

Splits the convert free function for the given custom type.

When split, the user must provide overloads for the covertFrom and convertTo functions. This can be useful when different behavior is required when converting to/from custom types.

The convertFrom function converts from a Variant to the custom type, and should have the following signature:

void convertFrom(FromVariantConverter&, Type&)

The convertTo function converts to a Variant from a custom type, and should have the following signature:

void convertTo(ToVariantConverter&, const Type&)

◆ CPPWAMP_CONVERSION_SPLIT_MEMBER

#define CPPWAMP_CONVERSION_SPLIT_MEMBER (   Type)
Value:
inline void convert(::wamp::FromVariantConverter& c, Type& obj) \
{ \
wamp::ConversionAccess::convertFrom(c, obj); \
} \
\
inline void convert(::wamp::ToVariantConverter& c, Type& obj) \
{ \
const auto& constObj = obj; \
wamp::ConversionAccess::convertTo(c, constObj); \
}

Splits the convert member function for the given custom type.

When split, the user must provide the covertFrom and convertTo member functions. This can be useful when different behavior is required when converting to/from custom types.

The convertFrom member function converts from a Variant to the custom type, and should have the following signature:

void CustomType::convertFrom(FromVariantConverter&)

The convertTo member function converts to a Variant from a custom type, and should have the following signature:

void CustomType::convertTo(ToVariantConverter&) const
wamp::ToVariantConverter
Wrapper around a destination Variant, used for conversions.
Definition: variant.hpp:604
wamp::FromVariantConverter
Wrapper around a source Variant, used for conversions.
Definition: variant.hpp:650
wamp::convert
void convert(ToVariantConverter &c, const TEnum &e)
Converts an enumerator to an integer variant.
Definition: variant.hpp:731