19 template <
typename Iterator>
41 if (
auto p = getConfigParameterOptional<T>(param))
46 error(
"Key <" + param +
"> has not been found");
51 T
const& default_value)
const
53 if (
auto p = getConfigParameterOptional<T>(param))
63 std::string
const& param)
const
72 std::string
const& param, T* )
const
76 return p->getValue<T>();
84 std::string
const& param, std::vector<T>* )
const
88 std::istringstream sstr{p->getValue<std::string>()};
89 std::vector<T> result;
93 result.push_back(value);
99 "' not convertible to a vector of the desired type."
100 " Could not convert token no. " +
101 std::to_string(result.size() + 1) +
".");
105 return std::make_optional(result);
111 template <
typename T>
113 std::string
const& param)
const
118 auto p =
tree_->equal_range(param);
123 template <
typename T>
128 if (
auto p =
tree_->get_child_optional(param))
132 return p->get_value<T>();
134 catch (boost::property_tree::ptree_bad_data
const&)
137 "' not convertible to the desired type.");
142 error(
"Key <" + param +
"> has not been found");
146 template <
typename T>
148 T
const& value)
const
150 if (getConfigParameter<T>(param) != value)
152 error(
"The value of key <" + param +
"> is not the expected one.");
156 template <
typename Ch>
158 Ch
const* value)
const
160 if (getConfigParameter<std::string>(param) != value)
162 error(
"The value of key <" + param +
"> is not the expected one.");
166 template <
typename T>
171 error(
"The data of this subtree has already been read.");
176 if (
auto v =
tree_->get_value_optional<T>())
181 "' is not convertible to the desired type.");
184 template <
typename T>
187 if (
auto a = getConfigAttributeOptional<T>(attr))
192 error(
"Did not find XML attribute with name '" + attr +
"'.");
195 template <
typename T>
197 T
const& default_value)
const
199 if (
auto a = getConfigAttributeOptional<T>(attr))
204 return default_value;
207 template <
typename T>
209 std::string
const& attr)
const
212 auto& ct = markVisited<T>(attr,
Attr::ATTR,
true);
214 if (
auto attrs =
tree_->get_child_optional(
"<xmlattr>"))
216 if (
auto a = attrs->get_child_optional(attr))
219 if (
auto v = a->get_value_optional<T>())
221 return std::make_optional(*v);
223 error(
"Value for XML attribute '" + attr +
"' `" +
225 "' not convertible to the desired type.");
232 template <
typename T>
235 bool const peek_only)
const
237 auto const type = std::type_index(
typeid(T));
244 auto& v = p.first->second;
254 error(
"There already was an attempt to obtain key <" + key +
255 "> with type '" + v.type.name() +
"' (now: '" + type.name() +
260 return p.first->second;
T peekConfigParameter(std::string const ¶m) const
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.
std::map< KeyType, CountType > visited_params_
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
std::optional< ConfigTree > getConfigSubtreeOptional(std::string const &root) const
std::optional< T > getConfigParameterOptional(std::string const ¶m) 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.
std::optional< T > getConfigParameterOptionalImpl(std::string const ¶m, T *) const
Default implementation of reading a value of type T.
Range< ValueIterator< T > > getConfigParameterList(std::string const ¶m) const
std::optional< T > getConfigAttributeOptional(std::string const &attr) const
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)