Skip to content
Snippets Groups Projects
Commit 39960303 authored by Christoph Lehmann's avatar Christoph Lehmann
Browse files

[BL] make default behaviour strict

Also checks are made publicly callable
parent 345348b5
No related branches found
No related tags found
No related merge requests found
...@@ -54,14 +54,14 @@ ConfigTreeNew(ConfigTreeNew && other) ...@@ -54,14 +54,14 @@ ConfigTreeNew(ConfigTreeNew && other)
ConfigTreeNew::~ConfigTreeNew() ConfigTreeNew::~ConfigTreeNew()
{ {
checkFullyRead(); checkAndInvalidate();
} }
ConfigTreeNew& ConfigTreeNew&
ConfigTreeNew:: ConfigTreeNew::
operator=(ConfigTreeNew&& other) operator=(ConfigTreeNew&& other)
{ {
checkFullyRead(); checkAndInvalidate();
_tree = other._tree; _tree = other._tree;
other._tree = nullptr; other._tree = nullptr;
...@@ -221,7 +221,7 @@ markVisitedDecrement(std::string const& key) const ...@@ -221,7 +221,7 @@ markVisitedDecrement(std::string const& key) const
} }
void void
ConfigTreeNew::checkFullyRead() const ConfigTreeNew::checkAndInvalidate()
{ {
if (!_tree) return; if (!_tree) return;
...@@ -240,6 +240,10 @@ ConfigTreeNew::checkFullyRead() const ...@@ -240,6 +240,10 @@ ConfigTreeNew::checkFullyRead() const
+ " time(s) less than it was present in the configuration tree."); + " time(s) less than it was present in the configuration tree.");
} }
} }
// The following invalidates this instance, s.t. it can not be read from it anymore,
// but it also prevents double-checking.
_tree = nullptr;
} }
} }
...@@ -180,10 +180,13 @@ public: ...@@ -180,10 +180,13 @@ public:
* If a custom error callback is provided, this function should break out of * If a custom error callback is provided, this function should break out of
* the normal execution order, e.g., by throwing or by calling std::abort(), * the normal execution order, e.g., by throwing or by calling std::abort(),
* because otherwise this class will effectively treat errors as no-errors. * because otherwise this class will effectively treat errors as no-errors.
*
* Defaults are strict: By default, both callbacks are set to the same function,
* i.e., warnings will also result in program abortion!
*/ */
explicit ConfigTreeNew(PTree const& tree, explicit ConfigTreeNew(PTree const& tree,
Callback const& error_cb = onerror, Callback const& error_cb = onerror,
Callback const& warning_cb = onwarning); Callback const& warning_cb = onerror);
//! copying is not compatible with the semantics of this class //! copying is not compatible with the semantics of this class
ConfigTreeNew(ConfigTreeNew const&) = delete; ConfigTreeNew(ConfigTreeNew const&) = delete;
...@@ -302,6 +305,13 @@ public: ...@@ -302,6 +305,13 @@ public:
*/ */
void ignoreConfParamAll(std::string const& param) const; void ignoreConfParamAll(std::string const& param) const;
/*! Checks if the top level of this tree has been read entirely (and not too often).
*
* Caution: This method also invalidates the instance, i.e., afterwards it can not
* be read from the tree anymore!
*/
void checkAndInvalidate();
//! The destructor performs the check if all nodes at the current level of the tree //! The destructor performs the check if all nodes at the current level of the tree
//! have been read. //! have been read.
~ConfigTreeNew(); ~ConfigTreeNew();
...@@ -362,10 +372,6 @@ private: ...@@ -362,10 +372,6 @@ private:
//! and the number of times it exists in the ConfigTree //! and the number of times it exists in the ConfigTree
void markVisitedDecrement(std::string const& key) const; void markVisitedDecrement(std::string const& key) const;
//! Helper method that checks if the top level of this tree has
//! been red entirely (and not too often).
void checkFullyRead() const;
//! returns a short string at suitable for error/warning messages //! returns a short string at suitable for error/warning messages
static std::string shortString(std::string const& s); static std::string shortString(std::string const& s);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment