# ini_type.h

Go to the documentation of this file.

    00001 /* $Id: ini_type.h 17596 2009-09-20 23:11:01Z smatz $ */
    00002
    00003 /*
    00004  * This file is part of OpenTTD.
    00005  * 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.
    00006  * 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.
    00007  * 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/>.
    00008  */
    00009
    00012 #ifndef INI_TYPE_H
    00013 #define INI_TYPE_H
    00014
    00016 enum IniGroupType {
    00017   IGT_VARIABLES = 0,
    00018   IGT_LIST      = 1,
    00019 };
    00020
    00022 struct IniItem {
    00023   IniItem *next;
    00024   char *name;
    00025   char *value;
    00026   char *comment;
    00027
    00034   IniItem(struct IniGroup *parent, const char *name, size_t len = 0);
    00035
    00037   ~IniItem();
    00038
    00043   void SetValue(const char *value);
    00044 };
    00045
    00047 struct IniGroup {
    00048   IniGroup *next;
    00049   IniGroupType type;
    00050   IniItem *item;
    00051   IniItem **last_item;
    00052   char *name;
    00053   char *comment;
    00054
    00061   IniGroup(struct IniFile *parent, const char *name, size_t len = 0);
    00062
    00064   ~IniGroup();
    00065
    00073   IniItem *GetItem(const char *name, bool create);
    00074
    00078   void Clear();
    00079 };
    00080
    00082 struct IniFile {
    00083   IniGroup *group;
    00084   IniGroup **last_group;
    00085   char *comment;
    00086   const char * const *list_group_names;
    00087
    00093   IniFile(const char * const *list_group_names = NULL);
    00094
    00096   ~IniFile();
    00097
    00105   IniGroup *GetGroup(const char *name, size_t len = 0);
    00106
    00111   void RemoveGroup(const char *name);
    00112
    00118   void LoadFromDisk(const char *filename);
    00119
    00125   bool SaveToDisk(const char *filename);
    00126 };
    00127
    00128 #endif /* INI_TYPE_H */