OpenTTD

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 */
IniGroup
A group within an ini file.
Definition: ini_type.h:38
Subdirectory
Subdirectory
The different kinds of subdirectories OpenTTD uses.
Definition: fileio_type.h:110
IniGroup::comment
char * comment
comment for group
Definition: ini_type.h:44
IniGroup::last_item
IniItem ** last_item
the last item in the group
Definition: ini_type.h:42
IniGroupType
IniGroupType
Types of groups.
Definition: ini_type.h:18
IniGroup::item
IniItem * item
the first item in the group
Definition: ini_type.h:41
IniItem::next
IniItem * next
The next item in this group.
Definition: ini_type.h:26
IniLoadFile::comment
char * comment
last comment in file
Definition: ini_type.h:57
IniItem
A single "line" in an ini file.
Definition: ini_type.h:25
fileio_type.h
Types for Standard In/Out file operations.
IniLoadFile::group
IniGroup * group
the first group in the ini
Definition: ini_type.h:55
IniGroup::type
IniGroupType type
type of group
Definition: ini_type.h:40
IniItem::SetValue
void SetValue(const char *value)
Replace the current value with another value.
Definition: ini_load.cpp:49
IniItem::value
char * value
The value of this item.
Definition: ini_type.h:28
IGT_VARIABLES
Values of the form "landscape = hilly".
Definition: ini_type.h:19
IniLoadFile::last_group
IniGroup ** last_group
the last group in the ini
Definition: ini_type.h:56
IniItem::IniItem
IniItem(struct IniGroup *parent, const char *name, const char *last=NULL)
Construct a new in-memory item of an Ini file.
Definition: ini_load.cpp:26
IGT_SEQUENCE
A list of uninterpreted lines, terminated by the next group block.
Definition: ini_type.h:21
IniFile
Ini file that supports both loading and saving.
Definition: ini_type.h:88
IniItem::name
char * name
The name of this item.
Definition: ini_type.h:27
IniGroup::next
IniGroup * next
the next group within this file
Definition: ini_type.h:39
IniItem::~IniItem
~IniItem()
Free everything we loaded.
Definition: ini_load.cpp:36
IGT_LIST
A list of values, separated by and terminated by the next group block.
Definition: ini_type.h:20
IniGroup::name
char * name
name of group
Definition: ini_type.h:43
IniLoadFile
Ini file that only supports loading.
Definition: ini_type.h:54
IniItem::comment
char * comment
The comment associated with this item.
Definition: ini_type.h:29
IniLoadFile::list_group_names
const char *const * list_group_names
NULL terminated list with group names that are lists.
Definition: ini_type.h:58
IniLoadFile::seq_group_names
const char *const * seq_group_names
NULL terminated list with group names that are sequences.
Definition: ini_type.h:59