Class VarValue¶
Defined in File Variable.h
Class Documentation¶
-
class
URI::Template
::
VarValue
¶ URI-template variable value.
This class represent type-safe union for value instances. The value can hold either std::string or std::vector<std::string> or std::unordered_map<std::string, std::string> instance.
Public Functions
-
VarValue
(VarType var_type = VarType::UNDEFINED)¶ Parametrized constructor.
Creates an empty variable value of desired type.
- Parameters
[in] var_type – Type of value to create. Default is VarType::UNDEFINED.
-
VarValue
(std::string &&str_value)¶ Parametrized constructor.
Creates a VarType::STRING variable from a
str_value
.- Parameters
[in] str_value – std::string to hold as value.
-
VarValue
(std::vector<std::string> &&list_value)¶ Parametrized constructor.
Creates a VarType::LIST variable from a
list_value
.- Parameters
[in] list_value – std::vector to hold as value.
-
VarValue
(std::unordered_map<std::string, std::string> &&dict_value)¶ Parametrized constructor.
Creates a VarType::DICT variable from a
dict_value
.- Parameters
[in] dict_value – std::unordered_map to hold as value.
-
~VarValue
() = default¶ Destructor.
-
template<class
T
>
inline T &Get
()¶ Get specific representation.
- Template Parameters
T – Type of the representation to get. Either:
std::string
orstd::vector<std::string>
orstd::unordered_map<std::string, std::string>
- Throws
std::bad_variant_access – if type mismatch.
- Returns
A reference of
T
to stored value.
-
template<class
T
>
inline const T &Get
() const¶ Get specific representation.
- Template Parameters
T – Type of the representation to get. Either:
std::string
orstd::vector<std::string>
orstd::unordered_map<std::string, std::string>
- Throws
std::bad_variant_access – if type mismatch.
- Returns
A const reference of
T
to stored value.
-
std::string
Print
() const¶ Produce printable value image.
Stored value printed as follows:
VarType::UNDEFINED -> undefined
VarType::STRING -> string
VarType::LIST -> [‘string’, ‘string’, …]
VarType::DICT -> {‘key’: ‘value’, ‘key’: ‘value’, …} Where ‘undefined’ is literal constant, and ‘string’, ‘key’, ‘value’ are contents of vector or unordered_map respectively.
- Returns
A string representing stored value.
-