/* * Copyright (C) 2016+ AzerothCore , released under GNU GPL v2 license, you may redistribute it and/or modify it under version 2 of the License, or (at your option), any later version. * Copyright (C) 2021+ WarheadCore */ #ifndef CONFIG_H #define CONFIG_H #include "Define.h" #include #include #include class ConfigMgr { ConfigMgr() = default; ConfigMgr(ConfigMgr const&) = delete; ConfigMgr& operator=(ConfigMgr const&) = delete; ~ConfigMgr() = default; public: bool LoadAppConfigs(); bool LoadModulesConfigs(); void Configure(std::string const& initFileName, std::vector args, std::string const& modulesConfigList = ""); static ConfigMgr* instance(); bool Reload(); std::string const& GetFilename(); std::string const GetConfigPath(); std::vector const& GetArguments() const; std::vector GetKeysByString(std::string const& name); template T GetOption(std::string const& name, T const& def, bool showLogs = true) const; /* * Deprecated geters. This geters will be deleted */ // @deprecated DO NOT USE - use GetOption instead. std::string GetStringDefault(std::string const& name, const std::string& def, bool showLogs = true); // @deprecated DO NOT USE - use GetOption instead. bool GetBoolDefault(std::string const& name, bool def, bool showLogs = true); // @deprecated DO NOT USE - use GetOption instead. int GetIntDefault(std::string const& name, int def, bool showLogs = true); // @deprecated DO NOT USE - use GetOption instead. float GetFloatDefault(std::string const& name, float def, bool showLogs = true); /* * End deprecated geters */ bool isDryRun() { return dryRun; } void setDryRun(bool mode) { dryRun = mode; } private: /// Method used only for loading main configuration files (authserver.conf and worldserver.conf) bool LoadInitial(std::string const& file); bool LoadAdditionalFile(std::string file); template T GetValueDefault(std::string const& name, T const& def, bool showLogs = true) const; bool dryRun = false; }; class ConfigException : public std::length_error { public: explicit ConfigException(std::string const& message) : std::length_error(message) { } }; #define sConfigMgr ConfigMgr::instance() #endif