13 #include <boost/property_tree/ptree.hpp>
22 extern template class boost::property_tree::basic_ptree<
23 std::string, std::string, std::less<>>;
43 template <
typename Iterator>
111 :
public std::iterator<std::input_iterator_tag, ConfigTree>
114 using Iterator = boost::property_tree::ptree::const_assoc_iterator;
175 if (st.hasChildren())
178 "> has child elements.");
190 template <
typename ValueType>
192 :
public std::iterator<std::input_iterator_tag, ValueType>
195 using Iterator = boost::property_tree::ptree::const_assoc_iterator;
220 .getValue<ValueType>();
241 using PTree = boost::property_tree::ptree;
250 using Callback = std::function<void(
const std::string& filename,
251 const std::string& path,
252 const std::string& message)>;
270 std::string filename,
310 template <
typename T>
322 template <
typename T>
324 T
const& default_value)
const;
335 template <
typename T>
345 template <
typename T>
347 std::string
const& param)
const;
379 std::string
const& root)
const;
389 std::string
const& param)
const;
397 template <
typename T>
406 template <
typename T>
420 template <
typename T>
430 template <
typename T>
455 template <
typename T>
463 template <
typename T>
467 template <
typename Ch>
489 std::string
const& root)
const;
540 static void onerror(std::string
const& filename, std::string
const& path,
541 std::string
const& message);
545 static void onwarning(std::string
const& filename, std::string
const& path,
546 std::string
const& message);
553 template <
typename T>
558 template <
typename T>
560 std::string
const& param, std::vector<T>* )
const;
577 std::string
const& root);
583 [[noreturn]]
void error(std::string
const& message)
const;
587 void warning(std::string
const& message)
const;
593 std::string
joinPaths(std::string
const& p1, std::string
const& p2)
const;
608 template <
typename T>
610 bool peek_only)
const;
620 bool const peek_only)
const;
638 static std::string
shortString(std::string
const& s);
641 boost::property_tree::ptree
const*
tree_;
bool operator!=(SubtreeIterator const &other) const
boost::property_tree::ptree::const_assoc_iterator Iterator
std::string const tagname_
ConfigTree const & parent_
SubtreeIterator & operator++()
SubtreeIterator(Iterator const &it, std::string const &root, ConfigTree const &parent)
bool operator==(SubtreeIterator const &other) const
boost::property_tree::ptree::const_assoc_iterator Iterator
ConfigTree const & parent_
bool operator==(ValueIterator< ValueType > const &other) const
ValueIterator< ValueType > & operator++()
ValueIterator(Iterator const &it, std::string const &root, ConfigTree const &parent)
std::string const tagname_
bool operator!=(ValueIterator< ValueType > const &other) const
T peekConfigParameter(std::string const ¶m) const
void markVisitedDecrement(Attr const is_attr, std::string const &key) const
void ignoreConfigParameter(std::string const ¶m) const
static void onerror(std::string const &filename, std::string const &path, std::string const &message)
void checkAndInvalidate()
static void assertNoSwallowedErrors()
Asserts that there have not been any errors reported in the destructor.
Callback onwarning_
Custom warning callback.
void checkConfigParameter(std::string const ¶m, T const &value) const
static const char pathseparator
Character separating two path components.
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
ConfigTree(PTree const &tree, std::string filename, Callback error_cb, Callback warning_cb)
void error(std::string const &message) const
std::optional< ConfigTree > getConfigSubtreeOptional(std::string const &root) const
ConfigTree(PTree &&, std::string const &, Callback const &, Callback const &)=delete
std::optional< T > getConfigParameterOptional(std::string const ¶m) const
void ignoreConfigAttribute(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.
Range< SubtreeIterator > getConfigSubtreeList(std::string const &root) const
static const std::string key_chars_start
Set of allowed characters as the first letter of a key name.
std::function< void(const std::string &filename, const std::string &path, const std::string &message)> Callback
ConfigTree getConfigSubtree(std::string const &root) const
std::pair< Attr, std::string > KeyType
A pair (is attribute, tag/attribute name).
std::string path_
A path printed in error/warning messages.
CountType & markVisited(std::string const &key, Attr const is_attr, bool peek_only) const
void ignoreConfigParameterAll(std::string const ¶m) const
boost::property_tree::ptree const * tree_
The wrapped tree.
Callback onerror_
Custom error callback.
std::string const & getProjectFileName() const
Used to get the project file name.
std::string joinPaths(std::string const &p1, std::string const &p2) const
Used to generate the path of a subtree.
std::optional< T > getConfigParameterOptionalImpl(std::string const ¶m, T *) const
Default implementation of reading a value of type T.
ConfigTree(ConfigTree const &)=delete
copying is not compatible with the semantics of this class
Range< ValueIterator< T > > getConfigParameterList(std::string const ¶m) const
ConfigTree & operator=(ConfigTree const &)=delete
copying is not compatible with the semantics of this class
std::optional< T > getConfigAttributeOptional(std::string const &attr) const
void warning(std::string const &message) const
bool hasChildren() const
Checks if this tree has any children.
boost::property_tree::ptree PTree
The tree being wrapped by this class.
std::string filename_
The path of the file from which this tree has been read.
void checkKeyname(std::string const &key) const
Checks if key complies with the rules [a-z0-9_].
static void onwarning(std::string const &filename, std::string const &path, std::string const &message)
static const std::string key_chars
Set of allowed characters in a key name.
Wraps a pair of iterators for use as a range in range-based for-loops.
void checkAndInvalidate(ConfigTree &conf)
This is an overloaded member function, provided for convenience. It differs from the above function o...