#include <userver/utils/default_dict.hpp>
Dictionary that for missing keys falls back to a default value stored by key utils::kDefaultDictDefaultName.
Usually used by dynamic configs for providing a fallback or default value along with the specific values. For example:
Definition at line 42 of file default_dict.hpp.
Public Types | |
using | DictType = utils::impl::TransparentMap<std::string, ValueType> |
using | const_iterator = typename DictType::const_iterator |
using | iterator = const_iterator |
using | value_type = typename DictType::value_type |
using | key_type = std::string |
using | mapped_type = ValueType |
using | init_list = std::initializer_list<std::pair<std::string_view, ValueType>> |
Public Member Functions | |
DefaultDict (init_list contents) | |
DefaultDict (DictType dict) | |
DefaultDict (std::string name, init_list contents) | |
DefaultDict (std::string name, DictType dict) | |
bool | HasDefaultValue () const noexcept |
bool | HasValue (std::string_view key) const noexcept |
Returns true if *this has key , otherwise returns false. | |
const ValueType & | GetDefaultValue () const |
const ValueType & | operator[] (std::string_view key) const |
template<typename StringType > | |
const ValueType & | operator[] (const std::optional< StringType > &key) const |
Returns key ? Get(*key) : GetDefaultValue() | |
const ValueType & | Get (std::string_view key) const |
template<typename StringType > | |
const ValueType & | Get (const std::optional< StringType > &key) const |
Returns key ? Get(*key) : GetDefaultValue() | |
std::optional< ValueType > | GetOptional (std::string_view key) const |
void | SetDefault (ValueType value) |
template<typename StringType > | |
void | Set (StringType &&key, ValueType value) |
auto | begin () const noexcept |
auto | end () const noexcept |
const std::string & | GetName () const noexcept |
bool | operator== (const DefaultDict &r) const noexcept |
bool | operator!= (const DefaultDict &r) const noexcept |
using utils::DefaultDict< ValueType >::const_iterator = typename DictType::const_iterator |
Definition at line 45 of file default_dict.hpp.
using utils::DefaultDict< ValueType >::DictType = utils::impl::TransparentMap<std::string, ValueType> |
Definition at line 44 of file default_dict.hpp.
using utils::DefaultDict< ValueType >::init_list = std::initializer_list<std::pair<std::string_view, ValueType>> |
Definition at line 50 of file default_dict.hpp.
using utils::DefaultDict< ValueType >::iterator = const_iterator |
Definition at line 46 of file default_dict.hpp.
using utils::DefaultDict< ValueType >::key_type = std::string |
Definition at line 48 of file default_dict.hpp.
using utils::DefaultDict< ValueType >::mapped_type = ValueType |
Definition at line 49 of file default_dict.hpp.
using utils::DefaultDict< ValueType >::value_type = typename DictType::value_type |
Definition at line 47 of file default_dict.hpp.
|
inline |
Definition at line 54 of file default_dict.hpp.
|
inline |
Definition at line 56 of file default_dict.hpp.
|
inline |
Definition at line 58 of file default_dict.hpp.
|
inline |
Definition at line 61 of file default_dict.hpp.
|
inlinenoexcept |
Definition at line 139 of file default_dict.hpp.
|
inlinenoexcept |
Definition at line 141 of file default_dict.hpp.
|
inline |
Returns key ? Get(*key) : GetDefaultValue()
Definition at line 107 of file default_dict.hpp.
|
inline |
Definition at line 103 of file default_dict.hpp.
|
inline |
Returns value by utils::kDefaultDictDefaultName key, throws a std::runtime_error exception.
Definition at line 74 of file default_dict.hpp.
|
inlinenoexcept |
Definition at line 143 of file default_dict.hpp.
|
inline |
Returns value by key
if it is in *this, otherwise returns value by utils::kDefaultDictDefaultName if it is in *this, otherwise returns an empty optional.
Definition at line 114 of file default_dict.hpp.
|
inlinenoexcept |
Returns true if *this has a utils::kDefaultDictDefaultName key, otherwise returns false.
Definition at line 65 of file default_dict.hpp.
|
inlinenoexcept |
Returns true if *this has key
, otherwise returns false.
Definition at line 68 of file default_dict.hpp.
|
inlinenoexcept |
Definition at line 147 of file default_dict.hpp.
|
inlinenoexcept |
Definition at line 145 of file default_dict.hpp.
|
inline |
Returns key ? Get(*key) : GetDefaultValue()
Definition at line 98 of file default_dict.hpp.
|
inline |
Returns value by key
if it is in *this, otherwise returns value by utils::kDefaultDictDefaultName if it is in *this, otherwise throws a std::runtime_error exception.
Definition at line 85 of file default_dict.hpp.
|
inline |
Sets a mapping. key == utils::kDefaultDictDefaultName is allowed.
The function is primarily there for testing purposes - DefaultDict is normally obtained by parsing the config.
Definition at line 135 of file default_dict.hpp.
|
inline |
Sets the default value.
The function is primarily there for testing purposes - DefaultDict is normally obtained by parsing the config.
Definition at line 128 of file default_dict.hpp.