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