CppWAMP
C++11 client library for the WAMP protocol
|
Go to the documentation of this file.
7 #ifndef CPPWAMP_OPTIONS_HPP
8 #define CPPWAMP_OPTIONS_HPP
14 #include "./internal/passkey.hpp"
15 #include "./internal/wampmessage.hpp"
28 template <
typename TDerived,
typename TMessage>
35 message_.options().emplace(std::move(key), std::move(value));
36 return static_cast<TDerived&
>(*this);
42 message_.options() = std::move(opts);
43 return static_cast<TDerived&
>(*this);
53 auto iter = options().find(key);
54 if (iter != options().end())
55 result = iter->second;
67 auto iter = options().find(key);
68 if (iter != options().end())
69 return iter->second.template to<ValueTypeOf<T>>();
71 return std::forward<T>(fallback);
75 using MessageType = TMessage;
78 template <
typename... TArgs>
80 : message_(std::forward<TArgs>(args)...)
83 MessageType& message() {
return message_;}
85 const MessageType& message()
const {
return message_;}
92 MessageType& message(internal::PassKey) {
return message_;}
97 #endif // CPPWAMP_OPTIONS_HPP
Variant optionByKey(const String &key) const
Obtains an option by key.
Definition: options.hpp:50
Discriminated union container that represents a JSON value.
Definition: variant.hpp:134
TDerived & withOptions(Object opts)
Sets all options at once.
Definition: options.hpp:40
TDerived & withOption(String key, Variant value)
Adds an option.
Definition: options.hpp:33
Defines macros related to exporting/importing APIs.
std::map< String, Variant > Object
Variant bound type for maps of variants.
Definition: variantdefs.hpp:52
Options(TArgs &&... args)
Constructor taking message construction aruments.
Definition: options.hpp:79
Definition: anyhandler.hpp:36
Wrapper around a WAMP message containing an options dictionary.
Definition: options.hpp:29
typename std::remove_cv< typename std::remove_reference< T >::type >::type ValueTypeOf
Metafunction used to obtain the plain value type of a parameter passed by universal reference.
Definition: traits.hpp:51
Contains the declaration of Variant and other closely related types/functions.
Contains general-purpose type traits.
const Object & options() const
Accesses the entire dictionary of options.
Definition: options.hpp:47
ValueTypeOf< T > optionOr(const String &key, T &&fallback) const
Obtains an option by key or a fallback value.
Definition: options.hpp:61
std::string String
Variant bound type for text strings.
Definition: variantdefs.hpp:50