Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/core2/src/orxonox/core/ConfigFileManager.h @ 989

Last change on this file since 989 was 989, checked in by landauf, 16 years ago

sync with notebook, nothing special here

File size: 3.3 KB
Line 
1/*
2 *   ORXONOX - the hottest 3D action shooter ever to exist
3 *
4 *
5 *   License notice:
6 *
7 *   This program is free software; you can redistribute it and/or
8 *   modify it under the terms of the GNU General Public License
9 *   as published by the Free Software Foundation; either version 2
10 *   of the License, or (at your option) any later version.
11 *
12 *   This program is distributed in the hope that it will be useful,
13 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
14 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 *   GNU General Public License for more details.
16 *
17 *   You should have received a copy of the GNU General Public License
18 *   along with this program; if not, write to the Free Software
19 *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
20 *
21 *   Author:
22 *      Fabian 'x3n' Landau
23 *   Co-authors:
24 *      ...
25 *
26 */
27
28#ifndef _ConfigFileManager_H__
29#define _ConfigFileManager_H__
30
31#include <list>
32
33#include "CorePrereqs.h"
34
35namespace orxonox
36{
37    class ConfigFileEntry
38    {
39        public:
40            ConfigFileEntry(const std::string& name, const std::string& value = "");
41
42            void setValue(const std::string& value);
43            const std::string& getValue() const;
44            const std::string& getName() const;
45
46        private:
47            std::string name_;
48            std::string value_;
49    };
50
51    class ConfigFileSection
52    {
53        public:
54            void addEntry(const std::string& name);
55            ConfigFileEntry* getEntry(const std::string& name) const;
56
57            void setValue(const std::string& name, const std::string& value);
58            const std::string& getValue(const std::string& name) const;
59
60        private:
61            std::string name_;
62            std::list<ConfigFileEntry> entries_;
63    };
64
65    class ConfigFile
66    {
67        public:
68            enum Type
69            {
70                Settings,
71                Keybindings
72            };
73
74        public:
75            void load();
76            void save();
77
78            void addSection(const std::string& name);
79            ConfigFileSection* getSection(const std::string& name) const;
80
81            void setValue(const std::string& section, const std::string& name, const std::string& value);
82            const std::string& getValue(const std::string& section, const std::string& name) const;
83
84        private:
85            std::string name_;
86            Type type_;
87            std::list<ConfigFileSection> sections_;
88    };
89
90    class ConfigFileManager
91    {
92        public:
93            static ConfigFileManater* getInstance();
94
95            void load(const std::string& filename);
96            void save(const std::string& filename) const;
97
98            void setFile(const std::string& filename);
99            ConfigFile& getFile(const std::string& filename) const;
100
101            void setValue(const std::string& filename, const std::string& section, const std::string& name, const std::string& value);
102            const std::string& getValue(const std::string& filename, const std::string& section, const std::string& name) const;
103
104        private:
105            std::list<ConfigFile> configFiles_;
106    };
107}
108
109#endif /* _ConfigFileManager_H__ */
Note: See TracBrowser for help on using the repository browser.