#ifndef SETTINGS_H #define SETTINGS_H #include #include #include #include "ConfigManager.h" #include "FilePath.h" class SettingsMigration; class Settings { public: Settings(const Settings& other); Settings& operator=(const Settings& other); virtual ~Settings(); bool load(const FilePath& filePath, bool readOnly = false); void save(); void save(const FilePath& filePath); void clear(); virtual const FilePath& getFilePath() const; size_t getVersion() const; void setVersion(size_t version); static FilePath expandPath(const FilePath& path); static std::vector expandPaths(const std::vector& paths); protected: Settings(); void setFilePath(const FilePath& filePath); template T getValue(const std::string& key, T defaultValue) const; template std::vector getValues(const std::string& key, std::vector defaultValues) const; std::vector getPathValues(const std::string& key) const; template bool setValue(const std::string& key, T value); template bool setValues(const std::string& key, std::vector values); bool setPathValues(const std::string& key, const std::vector& paths); bool isValueDefined(const std::string& key) const; void removeValues(const std::string& key); void enableWarnings() const; void disableWarnings() const; std::shared_ptr m_config; private: FilePath m_filePath; bool m_readOnly = false; friend SettingsMigration; }; template T Settings::getValue(const std::string& key, T defaultValue) const { if (m_config) { T value; if (m_config->getValue(key, value)) { return value; } } return defaultValue; } template std::vector Settings::getValues(const std::string& key, std::vector defaultValues) const { if(m_config) { std::vector values; if(m_config->getValues(key, values)) { return values; } } return defaultValues; } template bool Settings::setValue(const std::string& key, T value) { if (m_config) { m_config->setValue(key, value); return true; } return false; } template bool Settings::setValues(const std::string& key, std::vector values) { if (m_config) { m_config->setValues(key, values); return true; } return false; } #endif // SETTINGS_H