OpenMoHAA 0.82.0
Loading...
Searching...
No Matches
configurator.h
1/*
2===========================================================================
3Copyright (C) 2015 the OpenMoHAA team
4
5This file is part of OpenMoHAA source code.
6
7OpenMoHAA source code is free software; you can redistribute it
8and/or modify it under the terms of the GNU General Public License as
9published by the Free Software Foundation; either version 2 of the License,
10or (at your option) any later version.
11
12OpenMoHAA source code is distributed in the hope that it will be
13useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
14MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15GNU General Public License for more details.
16
17You should have received a copy of the GNU General Public License
18along with OpenMoHAA source code; if not, write to the Free Software
19Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20===========================================================================
21*/
22
23// configurator.h: Config class for INI files.
24
25#ifndef __CONFIGURATOR_H__
26#define __CONFIGURATOR_H__
27
28#include <listener.h>
29
30#define MAX_CONFIGURATOR_ARRAY_SIZE 2048
31
32typedef struct configValue_s {
33 bool m_bNeedWrite;
34 str value;
35} configValue_t;
36
37typedef struct configKey_s {
38 bool m_bNeedWrite;
39 str name;
41 bool m_bArray;
42} configKey_t;
43
44typedef struct configSection_s {
45 bool m_bNeedWrite;
46 str name;
48} configSection_t;
49
50enum { LINE_EMPTY, LINE_COMMENT, LINE_SECTION, LINE_VALUE, LINE_ERROR };
51
52class Configurator : public Class
53{
54private:
55 str m_filename;
56 bool m_bNoWrite;
57 bool m_bNeedWrite;
58
60 Container<configSection_t*> m_reverseSections;
61
62private:
63 size_t GetLine(char* dest, const char* data, size_t size);
64 str GetValue(const char* section, const char* key, str defaultValue,
65 int index = -1);
66 configKey_t* GetKey(const char* section, const char* key, int index = -1);
67
68 int CutLine(char* data);
69 bool SetupLine(char* line, int& lineno, size_t& len, size_t& last);
70 bool FindData(int type, const char* section, const char* key,
71 size_t* offset, const char* data, size_t size);
72 void ParseData(const char* data, size_t size);
73 void WriteData(char** data, size_t* size);
74 void WriteData2(char** data, size_t* size);
75 int ParseLine(char* line, char* section, char* key, char* value);
76
77 configSection_t* CreateSection(const char* section);
78 configSection_t* FindSection(const char* section);
79 int GetKeyArray(char* key);
80 int GetKeyArray(str& key);
81 configKey_t* CreateKey(configSection_t* section, const char* key,
82 unsigned int* index);
83 configKey_t* FindKey(configSection_t* section, const char* key);
84 void RemoveSection(configSection_t* section);
85 void RemoveKey(configSection_t* section, configKey_t* key);
86
87public:
88 CLASS_PROTOTYPE(Configurator);
89
90 Configurator(const char* filename);
91 Configurator();
92 ~Configurator();
93
94 void Parse(const char* filename);
95 void Close();
96 void SetWrite(bool bWrite);
97
98 str GetString(const char* section, const char* key, str defaultValue,
99 int index = -1);
100 int GetInteger(const char* section, const char* key, int defaultValue,
101 int index = -1);
102 float GetFloat(const char* section, const char* key, float defaultValue,
103 int index = -1);
104 void SetString(const char* section, const char* key, str value,
105 int index = -1);
106 void SetInteger(const char* section, const char* key, int value,
107 int index = -1);
108 void SetFloat(const char* section, const char* key, float value,
109 int index = -1);
110};
111
112void test_config(void);
113
114#endif /* __CONFIGURATOR_H__ */
Definition container.h:85
Definition con_set.h:119
Definition str.h:77
Definition configurator.h:37
Definition configurator.h:44
Definition configurator.h:32