CatapultServer
v0.5.0.1 (Elephant)
|
Go to the documentation of this file.
25 #include <unordered_map>
26 #include <unordered_set>
29 namespace catapult {
namespace utils {
60 template<
typename TValue>
64 template<
typename TValue>
68 using ValuesContainer = std::unordered_map<std::string, OrderedKeyValueMap<std::string>>;
87 count += section.second.size();
93 size_t size(
const char* section)
const {
94 auto sectionIter =
m_values.find(section);
95 return m_values.cend() == sectionIter ? 0 : sectionIter->second.size();
105 std::unordered_set<std::string>
sections;
116 auto pUnparsedValue =
lookup(key);
121 auto message =
"property could not be parsed";
132 if (!
tryGet(key, value)) {
133 auto message =
"property not found";
143 auto values = getAllOrdered<T>(section);
146 for (
const auto& value : values)
147 unorderedValues.emplace(value);
149 return unorderedValues;
157 auto sectionIter =
m_values.find(section);
161 for (
const auto& pair : sectionIter->second)
162 values.emplace_back(pair.first, get<T>(
ConfigurationKey(section, pair.first.c_str())));
173 const auto& sectionValues = sectionIter->second;
174 auto itemIter = std::find_if(sectionValues.cbegin(), sectionValues.cend(), [&name = key.
Name](
const auto& pair) {
175 return name == pair.first;
178 if (sectionValues.cend() == itemIter)
181 return &itemIter->second;
size_t size(const char *section) const
Returns the number of section properties in this bag.
Definition: ConfigurationBag.h:93
std::unordered_map< std::string, TValue > UnorderedKeyValueMap
A strongly typed unordered key to value map.
Definition: ConfigurationBag.h:65
const char * Section
Section containing the key.
Definition: ConfigurationBag.h:50
const std::string * lookup(const ConfigurationKey &key) const
Definition: ConfigurationBag.h:168
#define CATAPULT_THROW_AND_LOG_2(TYPE, MESSAGE, PARAM1, PARAM2)
Macro used to throw a catapult exception with two parameters.
Definition: exceptions.h:159
constexpr ConfigurationKey(const char *section, const char *name)
Creates a configuration key for a key with name in section.
Definition: ConfigurationBag.h:46
const char * Name
Key name.
Definition: ConfigurationBag.h:53
A simple bag of properties.
Definition: ConfigurationBag.h:57
std::unordered_set< std::string > sections() const
Gets the names of all sections in this bag.
Definition: ConfigurationBag.h:104
A configuration key.
Definition: ConfigurationBag.h:44
std::unordered_map< std::string, OrderedKeyValueMap< std::string > > ValuesContainer
Underlying container that a configuration bag is created around.
Definition: ConfigurationBag.h:68
ConfigurationBag(ValuesContainer &&values)
Creates a new configuration bag around values.
Definition: ConfigurationBag.h:72
std::vector< std::pair< std::string, TValue > > OrderedKeyValueMap
A strongly typed ordered key to value map.
Definition: ConfigurationBag.h:61
catapult_error< std::runtime_error > catapult_runtime_error
Definition: exceptions.h:87
T get(const ConfigurationKey &key) const
Gets the property identified by key from this bag.
Definition: ConfigurationBag.h:130
static ConfigurationBag FromPath(const std::string &path)
Loads a configuration bag from the specified path.
Definition: ConfigurationBag.cpp:45
static ConfigurationBag FromStream(std::istream &input)
Loads a configuration bag from the specified stream (input).
Definition: ConfigurationBag.cpp:29
Exception class that is thrown when a required configuration property is missing.
Definition: ConfigurationBag.h:32
#define VISIBLE_EXCEPTION_ATTRIBUTE
Definition: exceptions.h:35
Definition: AddressExtractionExtension.cpp:28
bool tryGet(const ConfigurationKey &key, T &value) const
Definition: ConfigurationBag.h:115
Base class for all catapult exceptions that derives from both std::exception and boost::exception.
Definition: exceptions.h:42
bool contains(const ConfigurationKey &key) const
Returns true if the property identified by key is contained in this bag.
Definition: ConfigurationBag.h:99
catapult_error< std::invalid_argument > catapult_invalid_argument
Definition: exceptions.h:88
bool TryParseValue(const std::string &str, LogLevel &parsedValue)
Tries to parse str into a log level (parsedValue).
Definition: ConfigurationValueParsers.cpp:60
OrderedKeyValueMap< T > getAllOrdered(const char *section) const
Gets all section properties from this bag preserving source order.
Definition: ConfigurationBag.h:154
size_t size() const
Returns the number of properties in this bag.
Definition: ConfigurationBag.h:84
ValuesContainer m_values
Definition: ConfigurationBag.h:185
UnorderedKeyValueMap< T > getAll(const char *section) const
Gets all section properties from this bag.
Definition: ConfigurationBag.h:142