diff options
Diffstat (limited to 'src/common/Configuration')
-rw-r--r-- | src/common/Configuration/BuiltInConfig.h | 2 | ||||
-rw-r--r-- | src/common/Configuration/Config.cpp | 50 | ||||
-rw-r--r-- | src/common/Configuration/Config.h | 16 |
3 files changed, 36 insertions, 32 deletions
diff --git a/src/common/Configuration/BuiltInConfig.h b/src/common/Configuration/BuiltInConfig.h index cc21555f4bf..a818407fb74 100644 --- a/src/common/Configuration/BuiltInConfig.h +++ b/src/common/Configuration/BuiltInConfig.h @@ -18,8 +18,8 @@ #ifndef BUILT_IN_CONFIG_H #define BUILT_IN_CONFIG_H -#include <string> #include "Define.h" +#include <string> /// Provides helper functions to access built-in values /// which can be overwritten in config diff --git a/src/common/Configuration/Config.cpp b/src/common/Configuration/Config.cpp index be05916e805..d4e56716501 100644 --- a/src/common/Configuration/Config.cpp +++ b/src/common/Configuration/Config.cpp @@ -16,14 +16,23 @@ * with this program. If not, see <http://www.gnu.org/licenses/>. */ -#include <algorithm> -#include <mutex> -#include <boost/property_tree/ptree.hpp> -#include <boost/property_tree/ini_parser.hpp> #include "Config.h" #include "Log.h" +#include "Util.h" +#include <boost/property_tree/ini_parser.hpp> +#include <algorithm> +#include <memory> +#include <mutex> -using namespace boost::property_tree; +namespace bpt = boost::property_tree; + +namespace +{ + std::string _filename; + std::vector<std::string> _args; + bpt::ptree _config; + std::mutex _configLock; +} bool ConfigMgr::LoadInitial(std::string const& file, std::vector<std::string> args, std::string& error) @@ -35,8 +44,8 @@ bool ConfigMgr::LoadInitial(std::string const& file, std::vector<std::string> ar try { - ptree fullTree; - ini_parser::read_ini(file, fullTree); + bpt::ptree fullTree; + bpt::ini_parser::read_ini(file, fullTree); if (fullTree.empty()) { @@ -47,7 +56,7 @@ bool ConfigMgr::LoadInitial(std::string const& file, std::vector<std::string> ar // Since we're using only one section per config file, we skip the section and have direct property access _config = fullTree.begin()->second; } - catch (ini_parser::ini_parser_error const& e) + catch (bpt::ini_parser::ini_parser_error const& e) { if (e.line() == 0) error = e.message() + " (" + e.filename() + ")"; @@ -75,14 +84,14 @@ T ConfigMgr::GetValueDefault(std::string const& name, T def) const { try { - return _config.get<T>(ptree::path_type(name, '/')); + return _config.get<T>(bpt::ptree::path_type(name, '/')); } - catch (boost::property_tree::ptree_bad_path) + catch (bpt::ptree_bad_path) { TC_LOG_WARN("server.loading", "Missing name %s in config file %s, add \"%s = %s\" to this file", name.c_str(), _filename.c_str(), name.c_str(), std::to_string(def).c_str()); } - catch (boost::property_tree::ptree_bad_data) + catch (bpt::ptree_bad_data) { TC_LOG_ERROR("server.loading", "Bad value defined for name %s in config file %s, going to use %s instead", name.c_str(), _filename.c_str(), std::to_string(def).c_str()); @@ -96,14 +105,14 @@ std::string ConfigMgr::GetValueDefault<std::string>(std::string const& name, std { try { - return _config.get<std::string>(ptree::path_type(name, '/')); + return _config.get<std::string>(bpt::ptree::path_type(name, '/')); } - catch (boost::property_tree::ptree_bad_path) + catch (bpt::ptree_bad_path) { TC_LOG_WARN("server.loading", "Missing name %s in config file %s, add \"%s = %s\" to this file", name.c_str(), _filename.c_str(), name.c_str(), def.c_str()); } - catch (boost::property_tree::ptree_bad_data) + catch (bpt::ptree_bad_data) { TC_LOG_ERROR("server.loading", "Bad value defined for name %s in config file %s, going to use %s instead", name.c_str(), _filename.c_str(), def.c_str()); @@ -123,7 +132,7 @@ bool ConfigMgr::GetBoolDefault(std::string const& name, bool def) const { std::string val = GetValueDefault(name, std::string(def ? "1" : "0")); val.erase(std::remove(val.begin(), val.end(), '"'), val.end()); - return (val == "1" || val == "true" || val == "TRUE" || val == "yes" || val == "YES"); + return StringToBool(val); } int ConfigMgr::GetIntDefault(std::string const& name, int def) const @@ -142,13 +151,18 @@ std::string const& ConfigMgr::GetFilename() return _filename; } -std::list<std::string> ConfigMgr::GetKeysByString(std::string const& name) +std::vector<std::string> const& ConfigMgr::GetArguments() const +{ + return _args; +} + +std::vector<std::string> ConfigMgr::GetKeysByString(std::string const& name) { std::lock_guard<std::mutex> lock(_configLock); - std::list<std::string> keys; + std::vector<std::string> keys; - for (const ptree::value_type& child : _config) + for (bpt::ptree::value_type const& child : _config) if (child.first.compare(0, name.length(), name) == 0) keys.push_back(child.first); diff --git a/src/common/Configuration/Config.h b/src/common/Configuration/Config.h index 1e0f558b007..df82a4e6668 100644 --- a/src/common/Configuration/Config.h +++ b/src/common/Configuration/Config.h @@ -20,12 +20,8 @@ #define CONFIG_H #include "Define.h" - #include <string> -#include <list> #include <vector> -#include <mutex> -#include <boost/property_tree/ptree.hpp> class TC_COMMON_API ConfigMgr { @@ -36,8 +32,7 @@ class TC_COMMON_API ConfigMgr public: /// Method used only for loading main configuration files (authserver.conf and worldserver.conf) - bool LoadInitial(std::string const& file, std::vector<std::string> args, - std::string& error); + bool LoadInitial(std::string const& file, std::vector<std::string> args, std::string& error); static ConfigMgr* instance(); @@ -49,15 +44,10 @@ public: float GetFloatDefault(std::string const& name, float def) const; std::string const& GetFilename(); - std::vector<std::string> const& GetArguments() const { return _args; } - std::list<std::string> GetKeysByString(std::string const& name); + std::vector<std::string> const& GetArguments() const; + std::vector<std::string> GetKeysByString(std::string const& name); private: - std::string _filename; - std::vector<std::string> _args; - boost::property_tree::ptree _config; - std::mutex _configLock; - template<class T> T GetValueDefault(std::string const& name, T def) const; }; |