OpenTTD
ini_type.h
Go to the documentation of this file.
1 /*
2  * This file is part of OpenTTD.
3  * 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.
4  * 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.
5  * 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/>.
6  */
7 
10 #ifndef INI_TYPE_H
11 #define INI_TYPE_H
12 
13 #include "fileio_type.h"
14 
18  IGT_LIST = 1,
20 };
21 
23 struct IniItem {
25  char *name;
26  char *value;
27  char *comment;
28 
29  IniItem(struct IniGroup *parent, const char *name, const char *last = nullptr);
30  ~IniItem();
31 
32  void SetValue(const char *value);
33 };
34 
36 struct IniGroup {
41  char *name;
42  char *comment;
43 
44  IniGroup(struct IniLoadFile *parent, const char *name, const char *last = nullptr);
45  ~IniGroup();
46 
47  IniItem *GetItem(const char *name, bool create);
48  void Clear();
49 };
50 
52 struct IniLoadFile {
55  char *comment;
56  const char * const *list_group_names;
57  const char * const *seq_group_names;
58 
59  IniLoadFile(const char * const *list_group_names = nullptr, const char * const *seq_group_names = nullptr);
60  virtual ~IniLoadFile();
61 
62  IniGroup *GetGroup(const char *name, size_t len = 0, bool create_new = true);
63  void RemoveGroup(const char *name);
64 
65  void LoadFromDisk(const char *filename, Subdirectory subdir);
66 
74  virtual FILE *OpenFile(const char *filename, Subdirectory subdir, size_t *size) = 0;
75 
82  virtual void ReportFileError(const char * const pre, const char * const buffer, const char * const post) = 0;
83 };
84 
86 struct IniFile : IniLoadFile {
87  IniFile(const char * const *list_group_names = nullptr);
88 
89  bool SaveToDisk(const char *filename);
90 
91  virtual FILE *OpenFile(const char *filename, Subdirectory subdir, size_t *size);
92  virtual void ReportFileError(const char * const pre, const char * const buffer, const char * const post);
93 };
94 
95 #endif /* INI_TYPE_H */
A group within an ini file.
Definition: ini_type.h:36
Subdirectory
The different kinds of subdirectories OpenTTD uses.
Definition: fileio_type.h:108
char * comment
comment for group
Definition: ini_type.h:42
IniItem ** last_item
the last item in the group
Definition: ini_type.h:40
IniGroupType
Types of groups.
Definition: ini_type.h:16
IniItem * item
the first item in the group
Definition: ini_type.h:39
IniItem * next
The next item in this group.
Definition: ini_type.h:24
char * comment
last comment in file
Definition: ini_type.h:55
A single "line" in an ini file.
Definition: ini_type.h:23
Types for Standard In/Out file operations.
IniGroup * group
the first group in the ini
Definition: ini_type.h:53
IniGroupType type
type of group
Definition: ini_type.h:38
void SetValue(const char *value)
Replace the current value with another value.
Definition: ini_load.cpp:47
char * value
The value of this item.
Definition: ini_type.h:26
Values of the form "landscape = hilly".
Definition: ini_type.h:17
IniGroup ** last_group
the last group in the ini
Definition: ini_type.h:54
A list of uninterpreted lines, terminated by the next group block.
Definition: ini_type.h:19
Ini file that supports both loading and saving.
Definition: ini_type.h:86
char * name
The name of this item.
Definition: ini_type.h:25
IniItem(struct IniGroup *parent, const char *name, const char *last=nullptr)
Construct a new in-memory item of an Ini file.
Definition: ini_load.cpp:24
IniGroup * next
the next group within this file
Definition: ini_type.h:37
~IniItem()
Free everything we loaded.
Definition: ini_load.cpp:34
A list of values, separated by and terminated by the next group block.
Definition: ini_type.h:18
char * name
name of group
Definition: ini_type.h:41
Ini file that only supports loading.
Definition: ini_type.h:52
char * comment
The comment associated with this item.
Definition: ini_type.h:27
const char *const * list_group_names
nullptr terminated list with group names that are lists
Definition: ini_type.h:56
const char *const * seq_group_names
nullptr terminated list with group names that are sequences.
Definition: ini_type.h:57