OpenTTD: src/ini_type.h Source File

OpenTTD

- Main Page
- Related Pages
- Modules
- Namespaces
- Data Structures
- Files

- File List
- Globals

ini_type.h
Go to the documentation of this file.
1 /* $Id: ini_type.h 26499 2014-04-24 18:37:39Z rubidium $ */
2
3 /*
4 * This file is part of OpenTTD.
5 * OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
6 * OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
7 * See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>.
8 */
9
12 #ifndef INI_TYPE_H
13 #define INI_TYPE_H
14
15 #include "fileio_type.h"
16
18 enum IniGroupType {
19 IGT_VARIABLES = 0,
20 IGT_LIST = 1,
21 IGT_SEQUENCE = 2,
22 };
23
25 struct IniItem {
26 IniItem *next;
27 char *name;
28 char *value;
29 char *comment;
30
31 IniItem(struct IniGroup *parent, const char *name, const char *last = NULL);
32 ~IniItem();
33
34 void SetValue(const char *value);
35 };
36
38 struct IniGroup {
39 IniGroup *next;
40 IniGroupType type;
41 IniItem *item;
42 IniItem **last_item;
43 char *name;
44 char *comment;
45
46 IniGroup(struct IniLoadFile *parent, const char *name, const char *last = NULL);
47 ~IniGroup();
48
49 IniItem *GetItem(const char *name, bool create);
50 void Clear();
51 };
52
54 struct IniLoadFile {
55 IniGroup *group;
56 IniGroup **last_group;
57 char *comment;
58 const char * const *list_group_names;
59 const char * const *seq_group_names;
60
61 IniLoadFile(const char * const *list_group_names = NULL, const char * const *seq_group_names = NULL);
62 virtual ~IniLoadFile();
63
64 IniGroup *GetGroup(const char *name, size_t len = 0, bool create_new = true);
65 void RemoveGroup(const char *name);
66
67 void LoadFromDisk(const char *filename, Subdirectory subdir);
68
76 virtual FILE *OpenFile(const char *filename, Subdirectory subdir, size_t *size) = 0;
77
84 virtual void ReportFileError(const char * const pre, const char * const buffer, const char * const post) = 0;
85 };
86
88 struct IniFile : IniLoadFile {
89 IniFile(const char * const *list_group_names = NULL);
90
91 bool SaveToDisk(const char *filename);
92
93 virtual FILE *OpenFile(const char *filename, Subdirectory subdir, size_t *size);
94 virtual void ReportFileError(const char * const pre, const char * const buffer, const char * const post);
95 };
96
97 #endif /* INI_TYPE_H */