diff --git a/BaseLib/ConfigTreeNew.cpp b/BaseLib/ConfigTreeNew.cpp index 0631983b76bee01fa79a78fd9ea6b7de87665539..57b16ed0a0090cec2ece05a1a31d7c73e10ce7cd 100644 --- a/BaseLib/ConfigTreeNew.cpp +++ b/BaseLib/ConfigTreeNew.cpp @@ -246,4 +246,20 @@ ConfigTreeNew::checkAndInvalidate() _tree = nullptr; } + +void checkAndInvalidate(ConfigTreeNew &conf) +{ + conf.checkAndInvalidate(); +} + +void checkAndInvalidate(ConfigTreeNew* const conf) +{ + if (conf) conf->checkAndInvalidate(); +} + +void checkAndInvalidate(std::unique_ptr<ConfigTreeNew> const& conf) +{ + if (conf) conf->checkAndInvalidate(); +} + } diff --git a/BaseLib/ConfigTreeNew.h b/BaseLib/ConfigTreeNew.h index 6129c55539cd96cf6733e9ed04f678f78bb41a50..eeec5c00630057f5038cf2e7c9b71fe6645fb69d 100644 --- a/BaseLib/ConfigTreeNew.h +++ b/BaseLib/ConfigTreeNew.h @@ -15,10 +15,27 @@ #include <map> #include <functional> +#include <memory> namespace BaseLib { +class ConfigTreeNew; + +/*! Check if \c conf has been read entirely and invalidate it. + * + * This method can savely be called on \c nullptr's. + * + * \see ConfigTreeNew::checkAndInvalidate() + */ +void checkAndInvalidate(ConfigTreeNew* const conf); + +//! \overload +void checkAndInvalidate(std::unique_ptr<ConfigTreeNew> const& conf); + +//! \overload +void checkAndInvalidate(ConfigTreeNew& conf); + template<typename Iterator> class Range; /*! @@ -305,13 +322,6 @@ public: */ 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 //! have been read. ~ConfigTreeNew(); @@ -372,6 +382,13 @@ private: //! and the number of times it exists in the ConfigTree void markVisitedDecrement(std::string const& key) 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(); + //! returns a short string at suitable for error/warning messages static std::string shortString(std::string const& s); @@ -401,6 +418,10 @@ private: //! Set of allowed characters in a key name. static const std::string key_chars; + + friend void checkAndInvalidate(ConfigTreeNew* const conf); + friend void checkAndInvalidate(ConfigTreeNew& conf); + friend void checkAndInvalidate(std::unique_ptr<ConfigTreeNew> const& conf); }; }