OpenMoHAA 0.82.1
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 {
51 LINE_EMPTY,
52 LINE_COMMENT,
53 LINE_SECTION,
54 LINE_VALUE,
55 LINE_ERROR
56};
57
58class Configurator : public Class
59{
60private:
61 str m_filename;
62 bool m_bNoWrite;
63 bool m_bNeedWrite;
64
66 Container<configSection_t *> m_reverseSections;
67
68private:
69 size_t GetLine(char *dest, const char *data, size_t size);
70 str GetValue(const char *section, const char *key, str defaultValue, int index = -1);
71 configKey_t *GetKey(const char *section, const char *key, int index = -1);
72
73 int CutLine(char *data);
74 bool SetupLine(char *line, int& lineno, size_t& len, size_t& last);
75 bool FindData(int type, const char *section, const char *key, size_t *offset, const char *data, size_t size);
76 void ParseData(const char *data, size_t size);
77 void WriteData(char **data, size_t *size);
78 void WriteData2(char **data, size_t *size);
79 int ParseLine(char *line, char *section, char *key, char *value);
80
81 configSection_t *CreateSection(const char *section);
82 configSection_t *FindSection(const char *section);
83 int GetKeyArray(char *key);
84 int GetKeyArray(str& key);
85 configKey_t *CreateKey(configSection_t *section, const char *key, unsigned int *index);
86 configKey_t *FindKey(configSection_t *section, const char *key);
87 void RemoveSection(configSection_t *section);
88 void RemoveKey(configSection_t *section, configKey_t *key);
89
90public:
91 CLASS_PROTOTYPE(Configurator);
92
93 Configurator(const char *filename);
94 Configurator();
95 ~Configurator();
96
97 void Parse(const char *filename);
98 void Close();
99 void SetWrite(bool bWrite);
100
101 str GetString(const char *section, const char *key, str defaultValue, int index = -1);
102 int GetInteger(const char *section, const char *key, int defaultValue, int index = -1);
103 float GetFloat(const char *section, const char *key, float defaultValue, int index = -1);
104 void SetString(const char *section, const char *key, str value, int index = -1);
105 void SetInteger(const char *section, const char *key, int value, int index = -1);
106 void SetFloat(const char *section, const char *key, float value, int index = -1);
107};
108
109void test_config(void);
110
111#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