Commit 7478c1eb authored by Dominik Charousset's avatar Dominik Charousset

Add config_value_map convenience alias

parent 1f24d6d7
...@@ -158,6 +158,10 @@ private: ...@@ -158,6 +158,10 @@ private:
variant_type data_; variant_type data_;
}; };
/// Organizes config values into categories.
/// @relates config_value
using config_value_map = std::map<std::string, config_value::dictionary>;
/// @relates config_value /// @relates config_value
template <class T> template <class T>
struct config_value_access; struct config_value_access;
...@@ -453,8 +457,7 @@ std::string get_or(const config_value::dictionary& xs, const std::string& name, ...@@ -453,8 +457,7 @@ std::string get_or(const config_value::dictionary& xs, const std::string& name,
/// Tries to retrieve the value associated to `name` from `xs`. /// Tries to retrieve the value associated to `name` from `xs`.
/// @relates config_value /// @relates config_value
template <class T> template <class T>
optional<T> get_if(const std::map<std::string, config_value::dictionary>* xs, optional<T> get_if(const config_value_map* xs, const std::string& name) {
const std::string& name) {
// Get the category. // Get the category.
auto pos = name.find('.'); auto pos = name.find('.');
if (pos == std::string::npos) { if (pos == std::string::npos) {
...@@ -472,8 +475,7 @@ optional<T> get_if(const std::map<std::string, config_value::dictionary>* xs, ...@@ -472,8 +475,7 @@ optional<T> get_if(const std::map<std::string, config_value::dictionary>* xs,
/// Retrieves the value associated to `name` from `xs`. /// Retrieves the value associated to `name` from `xs`.
/// @relates config_value /// @relates config_value
template <class T> template <class T>
T get(const std::map<std::string, config_value::dictionary>& xs, T get(const config_value_map& xs, const std::string& name) {
const std::string& name) {
auto result = get_if<T>(&xs, name); auto result = get_if<T>(&xs, name);
if (result) if (result)
return std::move(*result); return std::move(*result);
...@@ -484,8 +486,8 @@ T get(const std::map<std::string, config_value::dictionary>& xs, ...@@ -484,8 +486,8 @@ T get(const std::map<std::string, config_value::dictionary>& xs,
/// `default_value`. /// `default_value`.
/// @relates config_value /// @relates config_value
template <class T, class E = detail::enable_if_t<!std::is_pointer<T>::value>> template <class T, class E = detail::enable_if_t<!std::is_pointer<T>::value>>
T get_or(const std::map<std::string, config_value::dictionary>& xs, T get_or(const config_value_map& xs, const std::string& name,
const std::string& name, const T& default_value) { const T& default_value) {
auto result = get_if<T>(&xs, name); auto result = get_if<T>(&xs, name);
if (result) if (result)
return std::move(*result); return std::move(*result);
...@@ -495,8 +497,8 @@ T get_or(const std::map<std::string, config_value::dictionary>& xs, ...@@ -495,8 +497,8 @@ T get_or(const std::map<std::string, config_value::dictionary>& xs,
/// Retrieves the value associated to `name` from `xs` or returns /// Retrieves the value associated to `name` from `xs` or returns
/// `default_value`. /// `default_value`.
/// @relates config_value /// @relates config_value
std::string get_or(const std::map<std::string, config_value::dictionary>& xs, std::string get_or(const config_value_map& xs, const std::string& name,
const std::string& name, const char* default_value); const char* default_value);
/// Tries to retrieve the value associated to `name` from `cfg`. /// Tries to retrieve the value associated to `name` from `cfg`.
/// @relates config_value /// @relates config_value
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment