#pragma once #include "ddkit/base/Config.hpp" #include "ddkit/base/IConfigWrite.hpp" #include #include namespace ddkit { namespace base { /// @brief ConfigRw (ReadWrite) is constructed with a normal Config (read, from a file) and enables overwrite of keys as well. /// additionally it may be checked, which keys are allowed class ConfigRw : public IConfig, public IConfigWrite { public: ConfigRw(); ConfigRw(Config& config); ConfigRw(const ConfigRw&); void operator=(const ConfigRw&); // IConfig bool hasKey(const std::string& key) const override; std::string getStringValue(const std::string& key) const override; int getIntValue(const std::string& key) const override; int64_t getInt64Value(const std::string& key) const override; bool getBoolValue(const std::string& key) const override; // IConfigWrite void setStringValue(const std::string& key, const std::string& value) override; void setIntValue(const std::string& key, int value) override; void setInt64Value(const std::string& key, int64_t value) override; void setBoolValue(const std::string& key, bool value) override; // activate checks. i.e. foo.bar -> section foo and key bar void registerKnownConfigKey( const std::string& section, const std::string& key); void checkConfig() const; // check in file (only for corresponding top-level) private: // the 'real' BaseConfig (ConfigFile from ConfigLoader) Config m_config; // the overwritten key-values std::vector m_keys; std::map m_key2stringValue; std::map m_key2intValue; std::map m_key2int64Value; std::map m_key2boolValue; // keys allowed std::map> m_knownKeysMap; void checkKey(const std::string& key) const; void checkConfig(const std::string& prefix) const; // check in file }; } // namespace base } // namespace ddkit