Colobot
config_file.h
Go to the documentation of this file.
1 /*
2  * This file is part of the Colobot: Gold Edition source code
3  * Copyright (C) 2001-2016, Daniel Roux, EPSITEC SA & TerranovaTeam
4  * http://epsitec.ch; http://colobot.info; http://github.com/colobot
5  *
6  * This program is free software: you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation, either version 3 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
14  * See the GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program. If not, see http://gnu.org/licenses
18  */
19 
25 #pragma once
26 
27 #include "common/singleton.h"
28 
29 #include <boost/property_tree/ptree.hpp>
30 
31 #include <string>
32 
33 
40 class CConfigFile : public CSingleton<CConfigFile>
41 {
42 public:
43  CConfigFile();
44  virtual ~CConfigFile();
45 
47  void SetUseCurrentDirectory(bool useCurrentDirectory);
48 
52  bool Init();
53 
57  bool Save();
58 
62  bool SetStringProperty(std::string section, std::string key, std::string value);
63 
67  bool GetStringProperty(std::string section, std::string key, std::string& value);
68 
72  bool SetIntProperty(std::string section, std::string key, int value);
73 
77  bool SetBoolProperty(std::string section, std::string key, bool value);
78 
83  bool GetIntProperty(std::string section, std::string key, int &value);
84 
89  bool SetFloatProperty(std::string section, std::string key, float value);
90 
95  bool GetFloatProperty(std::string section, std::string key, float &value);
96 
101  bool GetBoolProperty(std::string section, std::string key, bool &value);
102 
103 private:
104  boost::property_tree::ptree m_propertyTree;
105  bool m_needsSave;
106  bool m_useCurrentDirectory;
107  bool m_loaded;
108 };
109 
112 {
113  return CConfigFile::GetInstance();
114 }
CSingleton base class for singletons.
bool GetIntProperty(std::string section, std::string key, int &value)
Definition: config_file.cpp:188
void SetUseCurrentDirectory(bool useCurrentDirectory)
Definition: config_file.cpp:59
bool SetBoolProperty(std::string section, std::string key, bool value)
Definition: config_file.cpp:203
Definition: singleton.h:30
bool GetBoolProperty(std::string section, std::string key, bool &value)
Definition: config_file.cpp:208
bool SetIntProperty(std::string section, std::string key, int value)
Definition: config_file.cpp:173
Class for loading config file.
Definition: config_file.h:40
bool GetStringProperty(std::string section, std::string key, std::string &value)
Definition: config_file.cpp:158
bool GetFloatProperty(std::string section, std::string key, float &value)
Definition: config_file.cpp:247
bool Init()
Definition: config_file.cpp:64
bool SetStringProperty(std::string section, std::string key, std::string value)
Definition: config_file.cpp:143
bool Save()
Definition: config_file.cpp:102
bool SetFloatProperty(std::string section, std::string key, float value)
Definition: config_file.cpp:232
CConfigFile & GetConfigFile()
Global function to get config file instance.
Definition: config_file.h:111