24#ifndef CONFIG_READER_INCLUDED
25#define CONFIG_READER_INCLUDED
32#include <rapidjson/document.h>
67 bool get_element(
const std::string &element_name, T &element_value,
70 if (parent !=
nullptr) {
71 if (!parent->IsObject())
return true;
90 if (!
valid_ || !
data_.HasMember(element_name))
return true;
91 element_value = &
data_[element_name];
108 if (!
valid_ || parent ==
nullptr || !parent->IsObject())
return true;
109 auto parent_object = parent->GetObject();
110 if (!parent_object.HasMember(element_name))
return true;
111 element_value = &parent_object[element_name];
156 template <
typename P,
typename T>
160 if (!parent.HasMember(element_name))
return true;
161 const rapidjson::Value &element = parent[element_name];
163 if (!element.Is<T>())
return true;
164 element_value = element.Get<T>();
Definition: config_reader.h:38
bool get_element(const std::string &element_name, T &element_value, const Config_object &parent=nullptr)
Get an element value from parent element or top level of JSON document.
Definition: config_reader.h:67
bool get_element(const std::string &element_name, Config_object &element_value)
Get an object element from top level of JSON document.
Definition: config_reader.h:88
rapidjson::Document data_
Configuration data in JSON.
Definition: config_reader.h:133
bool get_element(const Config_object &parent, const std::string &element_name, Config_object &element_value)
Get an object element value from parent element of JSON document.
Definition: config_reader.h:106
Config_reader(std::string config_file_path)
Constructor.
Definition: config_reader.cc:33
bool is_valid(std::string &err) const
Check if the object is valid, in particular if there was no parse error.
Definition: config_reader.h:124
bool valid_
Validity of configuration data.
Definition: config_reader.h:135
std::string err_
When not valid: cause of invalidity of configuration data.
Definition: config_reader.h:137
std::string config_file_path_
Configuration file path.
Definition: config_reader.h:131
bool get_element_inner(const P &parent, const std::string &element_name, T &element_value)
Get an element value.
Definition: config_reader.h:157
#define P
Definition: dtoa.cc:620
Define rapidjson::SizeType to be std::uint64_t.
static Value err()
Create a Value object that represents an error condition.
Definition: json_binary.cc:908
Definition: config_reader.cc:31
const rapidjson::Value * Config_object
Definition: config_reader.h:36