#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 43 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 |
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 46 of file default_dict.hpp.
using utils::DefaultDict< ValueType >::DictType = utils::impl::TransparentMap<std::string, ValueType> |
Definition at line 45 of file default_dict.hpp.
using utils::DefaultDict< ValueType >::init_list |
Definition at line 51 of file default_dict.hpp.
using utils::DefaultDict< ValueType >::iterator = const_iterator |
Definition at line 47 of file default_dict.hpp.
using utils::DefaultDict< ValueType >::key_type = std::string |
Definition at line 49 of file default_dict.hpp.
using utils::DefaultDict< ValueType >::mapped_type = ValueType |
Definition at line 50 of file default_dict.hpp.
using utils::DefaultDict< ValueType >::value_type = typename DictType::value_type |
Definition at line 48 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 60 of file default_dict.hpp.
|
inline |
Definition at line 63 of file default_dict.hpp.
|
inlinenoexcept |
Definition at line 148 of file default_dict.hpp.
|
inlinenoexcept |
Definition at line 150 of file default_dict.hpp.
|
inline |
Returns key ? Get(*key) : GetDefaultValue()
Definition at line 113 of file default_dict.hpp.
|
inline |
Definition at line 109 of file default_dict.hpp.
|
inline |
Returns value by utils::kDefaultDictDefaultName key, throws a std::runtime_error exception.
Definition at line 79 of file default_dict.hpp.
|
inlinenoexcept |
Definition at line 152 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 120 of file default_dict.hpp.
|
inlinenoexcept |
Returns true if *this has a utils::kDefaultDictDefaultName key, otherwise returns false.
Definition at line 68 of file default_dict.hpp.
|
inlinenoexcept |
Returns true if *this has key
, otherwise returns false.
Definition at line 73 of file default_dict.hpp.
|
inlinenoexcept |
Definition at line 158 of file default_dict.hpp.
|
inlinenoexcept |
Definition at line 154 of file default_dict.hpp.
|
inline |
Returns key ? Get(*key) : GetDefaultValue()
Definition at line 104 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 91 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 143 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 134 of file default_dict.hpp.