CppWAMP
C++11 client library for the WAMP protocol
wamp::Payload< TDerived, TMessage > Class Template Reference

Wrapper around a WAMP message containing payload arguments and an options dictionary. More...

#include <cppwamp/payload.hpp>

Inheritance diagram for wamp::Payload< TDerived, TMessage >:

Public Member Functions

template<typename... Ts>
TDerived & withArgs (Ts &&... args)
 Sets the positional arguments for this payload.
 
template<typename... Ts>
TDerived & withArgsTuple (const std::tuple< Ts... > &tuple)
 Sets the positional arguments for this payload from a tuple.
 
TDerived & withArgList (Array args)
 Sets the positional arguments for this payload from an array of variants. More...
 
TDerived & withKwargs (Object kwargs)
 Sets the keyword arguments for this payload. More...
 
const Arrayargs () const &
 Accesses the constant list of positional arguments. More...
 
Array args () &&
 Returns the moved list of positional arguments.
 
const Objectkwargs () const &
 Accesses the constant map of keyword arguments. More...
 
Object kwargs () &&
 Returns the moved map of keyword arguments.
 
Variantoperator[] (size_t index)
 Accesses a positional argument by index. More...
 
const Variantoperator[] (size_t index) const
 Accesses a constant positional argument by index. More...
 
Variantoperator[] (const String &keyword)
 Accesses a keyword argument by key. More...
 
template<typename... Ts>
size_t convertTo (Ts &... values) const
 Converts the payload's positional arguments to the given value types. More...
 
template<typename... Ts>
size_t convertToTuple (std::tuple< Ts... > &tuple) const
 Converts the payload's positional arguments to the given std::tuple.
 
template<typename... Ts>
size_t moveTo (Ts &... values)
 Moves the payload's positional arguments to the given value references. More...
 
template<typename... Ts>
size_t moveToTuple (std::tuple< Ts... > &tuple)
 Moves the payload's positional arguments to the given std::tuple.
 
template<typename... Ts>
D & withArgs (Ts &&... args)
 Each argument is converted to a Variant using Variant::from. More...
 
template<typename... Ts>
D & withArgsTuple (const std::tuple< Ts... > &tuple)
 Each tuple element is converted to a Variant using Variant::from. More...
 
- Public Member Functions inherited from wamp::Options< TDerived, TMessage >
TDerived & withOption (String key, Variant value)
 Adds an option.
 
TDerived & withOptions (Object opts)
 Sets all options at once.
 
const Objectoptions () const
 Accesses the entire dictionary of options.
 
Variant optionByKey (const String &key) const
 Obtains an option by key.
 
template<typename T >
ValueTypeOf< T > optionOr (const String &key, T &&fallback) const
 Obtains an option by key or a fallback value. More...
 

Protected Member Functions

template<typename... TArgs>
 Payload (TArgs &&... args)
 Constructor taking message construction aruments.
 
- Protected Member Functions inherited from wamp::Options< TDerived, TMessage >
template<typename... TArgs>
 Options (TArgs &&... args)
 Constructor taking message construction aruments.
 

Detailed Description

template<typename TDerived, typename TMessage>
class wamp::Payload< TDerived, TMessage >

Wrapper around a WAMP message containing payload arguments and an options dictionary.

Member Function Documentation

◆ withArgList()

template<typename D , typename M >
D & wamp::Payload< D, M >::withArgList ( Array  list)

Sets the positional arguments for this payload from an array of variants.

Postcondition
std::equal(args.begin(), args.end(), this->args()) == true

◆ withKwargs()

template<typename D , typename M >
D & wamp::Payload< D, M >::withKwargs ( Object  map)

Sets the keyword arguments for this payload.

Postcondition
std::equal(kwargs.begin(), kwargs.end(), this->kwargs()) == true

◆ args()

template<typename D , typename M >
Array wamp::Payload< D, M >::args

Accesses the constant list of positional arguments.

This overload takes effect when *this is an r-value. For example:

Array mine = std::move(payload).args();
Postcondition
this->args().empty() == true

◆ kwargs()

template<typename D , typename M >
Object wamp::Payload< D, M >::kwargs

Accesses the constant map of keyword arguments.

This overload takes effect when *this is an r-value. For example:

Object mine = std::move(payload).kwargs();
Postcondition
this->kwargs().empty() == true

◆ operator[]() [1/3]

template<typename D , typename M >
Variant & wamp::Payload< D, M >::operator[] ( size_t  index)

Accesses a positional argument by index.

Precondition
this->args().size() > index
Exceptions
std::out_of_rangeif the given index is not within the range of this->args().

◆ operator[]() [2/3]

template<typename D , typename M >
const Variant & wamp::Payload< D, M >::operator[] ( size_t  index) const

Accesses a constant positional argument by index.

Precondition
this->args().size() > index
Exceptions
std::out_of_rangeif the given index is not within the range of this->args().

◆ operator[]() [3/3]

template<typename D , typename M >
Variant & wamp::Payload< D, M >::operator[] ( const String keyword)

Accesses a keyword argument by key.

If the key doesn't exist, a null variant is inserted under the key before the reference is returned.

◆ convertTo()

template<typename D , typename M >
template<typename... Ts>
size_t wamp::Payload< D, M >::convertTo ( Ts &...  values) const

Converts the payload's positional arguments to the given value types.

Example
// Result derives from Payload
Result result = session->call("rpc", yield);
std::string s;
int n = 0;
result.convertTo(s, n);
Returns
The number of elements that were converted
Precondition
this->args() elements are convertible to their target types
Postcondition
std::min(this->args()->size(), sizeof...(Ts)) elements are converted
Exceptions
error::Conversionif an argument cannot be converted to the target type.

◆ moveTo()

template<typename D , typename M >
template<typename... Ts>
size_t wamp::Payload< D, M >::moveTo ( Ts &...  values)

Moves the payload's positional arguments to the given value references.

Example
// Result derives from Payload
Result result = session->call("rpc", yield);
Int n = 0;
result.moveTo(s, n);
Returns
The number of elements that were moved
Precondition
Args::list elements are accessible as their target types
Postcondition
std::min(this->list->size(), sizeof...(Ts)) elements are moved
The moved elements in this->args() are nullified
Exceptions
error::Accessif an argument's dynamic type does not match its associated target type.

◆ withArgs()

template<typename TDerived , typename TMessage >
template<typename... Ts>
D& wamp::Payload< TDerived, TMessage >::withArgs ( Ts &&...  args)

Each argument is converted to a Variant using Variant::from.

This allows custom types to be passed in, as long as the convert function is specialized for those custom types.

◆ withArgsTuple()

template<typename TDerived , typename TMessage >
template<typename... Ts>
D& wamp::Payload< TDerived, TMessage >::withArgsTuple ( const std::tuple< Ts... > &  tuple)

Each tuple element is converted to a Variant using Variant::from.

This allows custom types to be passed in, as long as the convert function is specialized for those custom types.


The documentation for this class was generated from the following file:
wamp::Object
std::map< String, Variant > Object
Variant bound type for maps of variants.
Definition: variantdefs.hpp:52
wamp::Array
std::vector< Variant > Array
Variant bound type for arrays of variants.
Definition: variantdefs.hpp:51
wamp::Int
std::int64_t Int
Variant bound type for signed integers.
Definition: variantdefs.hpp:47
wamp::String
std::string String
Variant bound type for text strings.
Definition: variantdefs.hpp:50