20 template<
typename Iterator>
43 if (
auto p = getConfigParameterOptional<T>(param))
48 error(
"Key <" + param +
"> has not been found");
56 if (
auto p = getConfigParameterOptional<T>(param))
66 std::string
const& param)
const
75 std::string
const& param, T* )
const
79 return p->getValue<T>();
87 std::string
const& param, std::vector<T>* )
const
91 std::istringstream sstr{p->getValue<std::string>()};
92 std::vector<T> result;
96 result.push_back(value);
101 error(
"Value for key <" + param +
"> `" +
103 "' not convertible to a vector of the desired type."
104 " Could not convert token no. " +
105 std::to_string(result.size() + 1) +
".");
109 return boost::make_optional(result);
123 auto p =
_tree->equal_range(param);
136 if (
auto p =
_tree->get_child_optional(param))
140 return p->get_value<T>();
142 catch (boost::property_tree::ptree_bad_data
const&)
145 "' not convertible to the desired type.");
150 error(
"Key <" + param +
"> has not been found");
159 if (getConfigParameter<T>(param) != value) {
160 error(
"The value of key <" + param +
"> is not the expected one.");
164 template<
typename Ch>
169 if (getConfigParameter<std::string>(param) != value) {
170 error(
"The value of key <" + param +
"> is not the expected one.");
180 error(
"The data of this subtree has already been read.");
185 if (
auto v =
_tree->get_value_optional<T>()) {
189 "' is not convertible to the desired type.");
197 if (
auto a = getConfigAttributeOptional<T>(attr))
202 error(
"Did not find XML attribute with name '" + attr +
"'.");
205 template <
typename T>
207 T
const& default_value)
const
209 if (
auto a = getConfigAttributeOptional<T>(attr))
214 return default_value;
223 auto& ct = markVisited<T>(attr,
Attr::ATTR,
true);
225 if (
auto attrs =
_tree->get_child_optional(
"<xmlattr>")) {
226 if (
auto a = attrs->get_child_optional(attr)) {
228 if (
auto v = a->get_value_optional<T>()) {
231 error(
"Value for XML attribute '" + attr +
"' `" +
233 "' not convertible to the desired type.");
244 bool const peek_only)
const
246 auto const type = std::type_index(
typeid(T));
252 auto& v = p.first->second;
253 if (v.type == type) {
259 error(
"There already was an attempt to obtain key <" + key +
260 "> with type '" + v.type.name() +
"' (now: '" + type.name() +
265 return p.first->second;
T peekConfigParameter(std::string const ¶m) const
std::map< KeyType, CountType > _visited_params
void checkConfigParameter(std::string const ¶m, T const &value) const
void checkUniqueAttr(std::string const &attr) const
Asserts that the attribute attr has not been read yet.
boost::optional< T > getConfigParameterOptional(std::string const ¶m) const
static std::string shortString(std::string const &s)
returns a short string at suitable for error/warning messages
void error(std::string const &message) const
boost::optional< T > getConfigAttributeOptional(std::string const &attr) const
void checkUnique(std::string const &key) const
Asserts that the key has not been read yet.
T getConfigParameter(std::string const ¶m) const
T getConfigAttribute(std::string const &attr) const
Attr
Used to indicate if dealing with XML tags or XML attributes.
CountType & markVisited(std::string const &key, Attr const is_attr, bool peek_only) const
boost::property_tree::ptree const * _tree
The wrapped tree.
boost::optional< ConfigTree > getConfigSubtreeOptional(std::string const &root) const
Range< ValueIterator< T > > getConfigParameterList(std::string const ¶m) const
bool _have_read_data
Indicates if the plain data contained in this tree has already been read.
boost::optional< T > getConfigParameterOptionalImpl(std::string const ¶m, T *) const
Default implementation of reading a value of type T.
void checkKeyname(std::string const &key) const
Checks if key complies with the rules [a-z0-9_].
Wraps a pair of iterators for use as a range in range-based for-loops.
Range(Iterator begin, Iterator end)