Add ScriptStoryPageElementList to get the contents of a page
[openttd/fttd.git] / src / ini_type.h
blob05133c77f01ddfc754d539722a60a291c4d9344c
1 /* $Id$ */
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 */
10 /** @file ini_type.h Types related to reading/writing '*.ini' files. */
12 #ifndef INI_TYPE_H
13 #define INI_TYPE_H
15 #include "fileio_type.h"
17 /** Types of groups */
18 enum IniGroupType {
19 IGT_VARIABLES = 0, ///< Values of the form "landscape = hilly".
20 IGT_LIST = 1, ///< A list of values, separated by \n and terminated by the next group block.
21 IGT_SEQUENCE = 2, ///< A list of uninterpreted lines, terminated by the next group block.
24 /** A single "line" in an ini file. */
25 struct IniItem {
26 IniItem *next; ///< The next item in this group
27 char *name; ///< The name of this item
28 char *value; ///< The value of this item
29 char *comment; ///< The comment associated with this item
31 IniItem(struct IniGroup *parent, const char *name, size_t len = 0);
32 ~IniItem();
34 void SetValue(const char *value);
37 /** A group within an ini file. */
38 struct IniGroup {
39 IniGroup *next; ///< the next group within this file
40 IniGroupType type; ///< type of group
41 IniItem *item; ///< the first item in the group
42 IniItem **last_item; ///< the last item in the group
43 char *name; ///< name of group
44 char *comment; ///< comment for group
46 IniGroup(struct IniLoadFile *parent, const char *name, size_t len = 0);
47 ~IniGroup();
49 IniItem *GetItem(const char *name, bool create);
50 void Clear();
53 /** Ini file that only supports loading. */
54 struct IniLoadFile {
55 IniGroup *group; ///< the first group in the ini
56 IniGroup **last_group; ///< the last group in the ini
57 char *comment; ///< last comment in file
58 const char * const *list_group_names; ///< NULL terminated list with group names that are lists
59 const char * const *seq_group_names; ///< NULL terminated list with group names that are sequences.
61 IniLoadFile(const char * const *list_group_names = NULL, const char * const *seq_group_names = NULL);
62 virtual ~IniLoadFile();
64 IniGroup *GetGroup(const char *name, size_t len = 0, bool create_new = true);
65 void RemoveGroup(const char *name);
67 void LoadFromDisk(const char *filename, Subdirectory subdir);
69 /**
70 * Open the INI file.
71 * @param filename Name of the INI file.
72 * @param subdir The subdir to load the file from.
73 * @param size [out] Size of the opened file.
74 * @return File handle of the opened file, or \c NULL.
76 virtual FILE *OpenFile(const char *filename, Subdirectory subdir, size_t *size) = 0;
78 /**
79 * Report an error about the file contents.
80 * @param pre Prefix text of the \a buffer part.
81 * @param buffer Part of the file with the error.
82 * @param post Suffix text of the \a buffer part.
84 virtual void ReportFileError(const char * const pre, const char * const buffer, const char * const post) = 0;
87 /** Ini file that supports both loading and saving. */
88 struct IniFile : IniLoadFile {
89 IniFile(const char * const *list_group_names = NULL);
91 bool SaveToDisk(const char *filename);
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);
97 #endif /* INI_TYPE_H */