00001 /* $Id$ */ 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 00028 IniItem(struct IniGroup *parent, const char *name, size_t len = 0); 00029 ~IniItem(); 00030 00031 void SetValue(const char *value); 00032 }; 00033 00035 struct IniGroup { 00036 IniGroup *next; 00037 IniGroupType type; 00038 IniItem *item; 00039 IniItem **last_item; 00040 char *name; 00041 char *comment; 00042 00043 IniGroup(struct IniFile *parent, const char *name, size_t len = 0); 00044 ~IniGroup(); 00045 00046 IniItem *GetItem(const char *name, bool create); 00047 void Clear(); 00048 }; 00049 00051 struct IniFile { 00052 IniGroup *group; 00053 IniGroup **last_group; 00054 char *comment; 00055 const char * const *list_group_names; 00056 00057 IniFile(const char * const *list_group_names = NULL); 00058 ~IniFile(); 00059 00060 IniGroup *GetGroup(const char *name, size_t len = 0); 00061 void RemoveGroup(const char *name); 00062 00063 void LoadFromDisk(const char *filename); 00064 bool SaveToDisk(const char *filename); 00065 }; 00066 00067 #endif /* INI_TYPE_H */