Otclient  14/8/2020
config.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2010-2020 OTClient <https://github.com/edubart/otclient>
3  *
4  * Permission is hereby granted, free of charge, to any person obtaining a copy
5  * of this software and associated documentation files (the "Software"), to deal
6  * in the Software without restriction, including without limitation the rights
7  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8  * copies of the Software, and to permit persons to whom the Software is
9  * furnished to do so, subject to the following conditions:
10  *
11  * The above copyright notice and this permission notice shall be included in
12  * all copies or substantial portions of the Software.
13  *
14  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20  * THE SOFTWARE.
21  */
22 
23 #ifndef CONFIG_H
24 #define CONFIG_H
25 
26 #include "declarations.h"
27 
30 
31 // @bindclass
32 class Config : public LuaObject
33 {
34 public:
35  Config();
36 
37  bool load(const std::string& file);
38  bool unload();
39  bool save();
40  void clear();
41 
42  void setValue(const std::string& key, const std::string& value);
43  void setList(const std::string& key, const std::vector<std::string>& list);
44  std::string getValue(const std::string& key);
45  std::vector<std::string> getList(const std::string& key);
46 
47  void setNode(const std::string& key, const OTMLNodePtr& node);
48  void mergeNode(const std::string& key, const OTMLNodePtr& node);
49  OTMLNodePtr getNode(const std::string& key);
50 
51  bool exists(const std::string& key);
52  void remove(const std::string& key);
53 
54  std::string getFileName();
55  bool isLoaded();
56 
57  // @dontbind
58  ConfigPtr asConfig() { return static_self_cast<Config>(); }
59 
60 private:
61  std::string m_fileName;
62  OTMLDocumentPtr m_confsDoc;
63 };
64 
65 #endif
Config::isLoaded
bool isLoaded()
Definition: config.cpp:150
Config::Config
Config()
Definition: config.cpp:29
Config::load
bool load(const std::string &file)
Definition: config.cpp:35
Config::save
bool save()
Definition: config.cpp:63
Config::setList
void setList(const std::string &key, const std::vector< std::string > &list)
Definition: config.cpp:86
Config::setNode
void setNode(const std::string &key, const OTMLNodePtr &node)
Definition: config.cpp:131
Config::asConfig
ConfigPtr asConfig()
Definition: config.h:58
declarations.h
luaobject.h
Config
Definition: config.h:32
Config::getList
std::vector< std::string > getList(const std::string &key)
Definition: config.cpp:113
Config::clear
void clear()
Definition: config.cpp:70
declarations.h
Config::mergeNode
void mergeNode(const std::string &key, const OTMLNodePtr &node)
Definition: config.cpp:137
Config::getNode
OTMLNodePtr getNode(const std::string &key)
Definition: config.cpp:145
Config::getFileName
std::string getFileName()
Definition: config.cpp:155
Config::exists
bool exists(const std::string &key)
Definition: config.cpp:99
stdext::shared_object_ptr< OTMLNode >
Config::unload
bool unload()
Definition: config.cpp:53
Config::setValue
void setValue(const std::string &key, const std::string &value)
Definition: config.cpp:75
Config::remove
void remove(const std::string &key)
Definition: config.cpp:124
Config::getValue
std::string getValue(const std::string &key)
Definition: config.cpp:104
LuaObject
LuaObject, all script-able classes have it as base.
Definition: luaobject.h:30