TrinityCore
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
Config.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2008-2016 TrinityCore <http://www.trinitycore.org/>
3  * Copyright (C) 2005-2009 MaNGOS <http://getmangos.com/>
4  *
5  * This program is free software; you can redistribute it and/or modify it
6  * under the terms of the GNU General Public License as published by the
7  * Free Software Foundation; either version 2 of the License, or (at your
8  * option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful, but WITHOUT
11  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12  * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
13  * more details.
14  *
15  * You should have received a copy of the GNU General Public License along
16  * with this program. If not, see <http://www.gnu.org/licenses/>.
17  */
18 
19 #ifndef CONFIG_H
20 #define CONFIG_H
21 
22 #include "Define.h"
23 
24 #include <string>
25 #include <list>
26 #include <mutex>
27 #include <boost/property_tree/ptree.hpp>
28 
30 {
31  ConfigMgr() = default;
32  ConfigMgr(ConfigMgr const&) = delete;
33  ConfigMgr& operator=(ConfigMgr const&) = delete;
34  ~ConfigMgr() = default;
35 
36 public:
38  bool LoadInitial(std::string const& file, std::string& error);
39 
40  static ConfigMgr* instance();
41 
42  bool Reload(std::string& error);
43 
44  std::string GetStringDefault(std::string const& name, const std::string& def) const;
45  bool GetBoolDefault(std::string const& name, bool def) const;
46  int GetIntDefault(std::string const& name, int def) const;
47  float GetFloatDefault(std::string const& name, float def) const;
48 
49  std::string const& GetFilename();
50  std::list<std::string> GetKeysByString(std::string const& name);
51 
52 private:
53  std::string _filename;
54  boost::property_tree::ptree _config;
55  std::mutex _configLock;
56 
57  template<class T>
58  T GetValueDefault(std::string const& name, T def) const;
59 };
60 
61 #define sConfigMgr ConfigMgr::instance()
62 
63 #endif
Definition: Config.h:29
std::mutex _configLock
Definition: Config.h:55
std::string _filename
Definition: Config.h:53
Vector2int16 & operator=(const Any &a)
#define TC_COMMON_API
Definition: Define.h:116
boost::property_tree::ptree _config
Definition: Config.h:54