src/ini_type.h
author translators
Thu, 18 Dec 2008 18:47:39 +0000
changeset 10437 6d64230b9fb9
parent 10008 fca6f9cf02ac
permissions -rw-r--r--
(svn r14691) -Update: WebTranslator2 update to 2008-12-18 18:47:25
arabic_egypt - 132 fixed, 1 changed by khaloofah (133)
czech - 10 fixed, 25 changed by Hadez (35)
esperanto - 15 fixed by Athaba (15)
greek - 7 fixed by ouranogrammi (7)
indonesian - 88 changed by fanioz (88)
latvian - 117 fixed, 16 changed by peerer (83), marismols (50)
lithuanian - 15 fixed by Zogg (15)
malay - 38 fixed by tombakemas (5), Syed (33)
serbian - 39 fixed, 1 changed by Jenraux (40)
thai - 105 fixed by vetbook (105)
9996
fceaf224b2f0 (svn r14153) -Codechange: split ini file reading/saving from settings.cpp.
rubidium
parents:
diff changeset
     1
/* $Id$ */
fceaf224b2f0 (svn r14153) -Codechange: split ini file reading/saving from settings.cpp.
rubidium
parents:
diff changeset
     2
fceaf224b2f0 (svn r14153) -Codechange: split ini file reading/saving from settings.cpp.
rubidium
parents:
diff changeset
     3
/** @file ini_type.h Types related to reading/writing '*.ini' files. */
fceaf224b2f0 (svn r14153) -Codechange: split ini file reading/saving from settings.cpp.
rubidium
parents:
diff changeset
     4
fceaf224b2f0 (svn r14153) -Codechange: split ini file reading/saving from settings.cpp.
rubidium
parents:
diff changeset
     5
#ifndef INI_TYPE_H
fceaf224b2f0 (svn r14153) -Codechange: split ini file reading/saving from settings.cpp.
rubidium
parents:
diff changeset
     6
#define INI_TYPE_H
fceaf224b2f0 (svn r14153) -Codechange: split ini file reading/saving from settings.cpp.
rubidium
parents:
diff changeset
     7
fceaf224b2f0 (svn r14153) -Codechange: split ini file reading/saving from settings.cpp.
rubidium
parents:
diff changeset
     8
/** Types of groups */
fceaf224b2f0 (svn r14153) -Codechange: split ini file reading/saving from settings.cpp.
rubidium
parents:
diff changeset
     9
enum IniGroupType {
fceaf224b2f0 (svn r14153) -Codechange: split ini file reading/saving from settings.cpp.
rubidium
parents:
diff changeset
    10
	IGT_VARIABLES = 0, ///< values of the form "landscape = hilly"
fceaf224b2f0 (svn r14153) -Codechange: split ini file reading/saving from settings.cpp.
rubidium
parents:
diff changeset
    11
	IGT_LIST      = 1, ///< a list of values, seperated by \n and terminated by the next group block
fceaf224b2f0 (svn r14153) -Codechange: split ini file reading/saving from settings.cpp.
rubidium
parents:
diff changeset
    12
};
fceaf224b2f0 (svn r14153) -Codechange: split ini file reading/saving from settings.cpp.
rubidium
parents:
diff changeset
    13
fceaf224b2f0 (svn r14153) -Codechange: split ini file reading/saving from settings.cpp.
rubidium
parents:
diff changeset
    14
/** A single "line" in an ini file. */
fceaf224b2f0 (svn r14153) -Codechange: split ini file reading/saving from settings.cpp.
rubidium
parents:
diff changeset
    15
struct IniItem {
fceaf224b2f0 (svn r14153) -Codechange: split ini file reading/saving from settings.cpp.
rubidium
parents:
diff changeset
    16
	IniItem *next; ///< The next item in this group
fceaf224b2f0 (svn r14153) -Codechange: split ini file reading/saving from settings.cpp.
rubidium
parents:
diff changeset
    17
	char *name;    ///< The name of this item
fceaf224b2f0 (svn r14153) -Codechange: split ini file reading/saving from settings.cpp.
rubidium
parents:
diff changeset
    18
	char *value;   ///< The value of this item
fceaf224b2f0 (svn r14153) -Codechange: split ini file reading/saving from settings.cpp.
rubidium
parents:
diff changeset
    19
	char *comment; ///< The comment associated with this item
fceaf224b2f0 (svn r14153) -Codechange: split ini file reading/saving from settings.cpp.
rubidium
parents:
diff changeset
    20
10005
4b4ce4a46744 (svn r14164) -Codechange: simplify and unify the addition of ini items with value when not loading an ini file.
rubidium
parents: 9999
diff changeset
    21
	/**
4b4ce4a46744 (svn r14164) -Codechange: simplify and unify the addition of ini items with value when not loading an ini file.
rubidium
parents: 9999
diff changeset
    22
	 * Construct a new in-memory item of an Ini file.
4b4ce4a46744 (svn r14164) -Codechange: simplify and unify the addition of ini items with value when not loading an ini file.
rubidium
parents: 9999
diff changeset
    23
	 * @param parent the group we belong to
4b4ce4a46744 (svn r14164) -Codechange: simplify and unify the addition of ini items with value when not loading an ini file.
rubidium
parents: 9999
diff changeset
    24
	 * @param name   the name of the item
4b4ce4a46744 (svn r14164) -Codechange: simplify and unify the addition of ini items with value when not loading an ini file.
rubidium
parents: 9999
diff changeset
    25
	 * @param len    the length of the name of the item
4b4ce4a46744 (svn r14164) -Codechange: simplify and unify the addition of ini items with value when not loading an ini file.
rubidium
parents: 9999
diff changeset
    26
	 */
9996
fceaf224b2f0 (svn r14153) -Codechange: split ini file reading/saving from settings.cpp.
rubidium
parents:
diff changeset
    27
	IniItem(struct IniGroup *parent, const char *name, size_t len = 0);
10005
4b4ce4a46744 (svn r14164) -Codechange: simplify and unify the addition of ini items with value when not loading an ini file.
rubidium
parents: 9999
diff changeset
    28
4b4ce4a46744 (svn r14164) -Codechange: simplify and unify the addition of ini items with value when not loading an ini file.
rubidium
parents: 9999
diff changeset
    29
	/** Free everything we loaded. */
9996
fceaf224b2f0 (svn r14153) -Codechange: split ini file reading/saving from settings.cpp.
rubidium
parents:
diff changeset
    30
	~IniItem();
10005
4b4ce4a46744 (svn r14164) -Codechange: simplify and unify the addition of ini items with value when not loading an ini file.
rubidium
parents: 9999
diff changeset
    31
4b4ce4a46744 (svn r14164) -Codechange: simplify and unify the addition of ini items with value when not loading an ini file.
rubidium
parents: 9999
diff changeset
    32
	/**
4b4ce4a46744 (svn r14164) -Codechange: simplify and unify the addition of ini items with value when not loading an ini file.
rubidium
parents: 9999
diff changeset
    33
	 * Replace the current value with another value.
4b4ce4a46744 (svn r14164) -Codechange: simplify and unify the addition of ini items with value when not loading an ini file.
rubidium
parents: 9999
diff changeset
    34
	 * @param value the value to replace with.
4b4ce4a46744 (svn r14164) -Codechange: simplify and unify the addition of ini items with value when not loading an ini file.
rubidium
parents: 9999
diff changeset
    35
	 */
4b4ce4a46744 (svn r14164) -Codechange: simplify and unify the addition of ini items with value when not loading an ini file.
rubidium
parents: 9999
diff changeset
    36
	void SetValue(const char *value);
9996
fceaf224b2f0 (svn r14153) -Codechange: split ini file reading/saving from settings.cpp.
rubidium
parents:
diff changeset
    37
};
fceaf224b2f0 (svn r14153) -Codechange: split ini file reading/saving from settings.cpp.
rubidium
parents:
diff changeset
    38
fceaf224b2f0 (svn r14153) -Codechange: split ini file reading/saving from settings.cpp.
rubidium
parents:
diff changeset
    39
/** A group within an ini file. */
fceaf224b2f0 (svn r14153) -Codechange: split ini file reading/saving from settings.cpp.
rubidium
parents:
diff changeset
    40
struct IniGroup {
fceaf224b2f0 (svn r14153) -Codechange: split ini file reading/saving from settings.cpp.
rubidium
parents:
diff changeset
    41
	IniGroup *next;      ///< the next group within this file
fceaf224b2f0 (svn r14153) -Codechange: split ini file reading/saving from settings.cpp.
rubidium
parents:
diff changeset
    42
	IniGroupType type;   ///< type of group
fceaf224b2f0 (svn r14153) -Codechange: split ini file reading/saving from settings.cpp.
rubidium
parents:
diff changeset
    43
	IniItem *item;       ///< the first item in the group
fceaf224b2f0 (svn r14153) -Codechange: split ini file reading/saving from settings.cpp.
rubidium
parents:
diff changeset
    44
	IniItem **last_item; ///< the last item in the group
fceaf224b2f0 (svn r14153) -Codechange: split ini file reading/saving from settings.cpp.
rubidium
parents:
diff changeset
    45
	char *name;          ///< name of group
fceaf224b2f0 (svn r14153) -Codechange: split ini file reading/saving from settings.cpp.
rubidium
parents:
diff changeset
    46
	char *comment;       ///< comment for group
fceaf224b2f0 (svn r14153) -Codechange: split ini file reading/saving from settings.cpp.
rubidium
parents:
diff changeset
    47
fceaf224b2f0 (svn r14153) -Codechange: split ini file reading/saving from settings.cpp.
rubidium
parents:
diff changeset
    48
	/**
fceaf224b2f0 (svn r14153) -Codechange: split ini file reading/saving from settings.cpp.
rubidium
parents:
diff changeset
    49
	 * Construct a new in-memory group of an Ini file.
fceaf224b2f0 (svn r14153) -Codechange: split ini file reading/saving from settings.cpp.
rubidium
parents:
diff changeset
    50
	 * @param parent the file we belong to
fceaf224b2f0 (svn r14153) -Codechange: split ini file reading/saving from settings.cpp.
rubidium
parents:
diff changeset
    51
	 * @param name   the name of the group
fceaf224b2f0 (svn r14153) -Codechange: split ini file reading/saving from settings.cpp.
rubidium
parents:
diff changeset
    52
	 * @param len    the length of the name of the group
fceaf224b2f0 (svn r14153) -Codechange: split ini file reading/saving from settings.cpp.
rubidium
parents:
diff changeset
    53
	 */
fceaf224b2f0 (svn r14153) -Codechange: split ini file reading/saving from settings.cpp.
rubidium
parents:
diff changeset
    54
	IniGroup(struct IniFile *parent, const char *name, size_t len = 0);
fceaf224b2f0 (svn r14153) -Codechange: split ini file reading/saving from settings.cpp.
rubidium
parents:
diff changeset
    55
fceaf224b2f0 (svn r14153) -Codechange: split ini file reading/saving from settings.cpp.
rubidium
parents:
diff changeset
    56
	/** Free everything we loaded. */
fceaf224b2f0 (svn r14153) -Codechange: split ini file reading/saving from settings.cpp.
rubidium
parents:
diff changeset
    57
	~IniGroup();
fceaf224b2f0 (svn r14153) -Codechange: split ini file reading/saving from settings.cpp.
rubidium
parents:
diff changeset
    58
fceaf224b2f0 (svn r14153) -Codechange: split ini file reading/saving from settings.cpp.
rubidium
parents:
diff changeset
    59
	/**
fceaf224b2f0 (svn r14153) -Codechange: split ini file reading/saving from settings.cpp.
rubidium
parents:
diff changeset
    60
	 * Get the item with the given name, and if it doesn't exist
fceaf224b2f0 (svn r14153) -Codechange: split ini file reading/saving from settings.cpp.
rubidium
parents:
diff changeset
    61
	 * and create is true it creates a new item.
fceaf224b2f0 (svn r14153) -Codechange: split ini file reading/saving from settings.cpp.
rubidium
parents:
diff changeset
    62
	 * @param name   name of the item to find.
fceaf224b2f0 (svn r14153) -Codechange: split ini file reading/saving from settings.cpp.
rubidium
parents:
diff changeset
    63
	 * @param create whether to create an item when not found or not.
fceaf224b2f0 (svn r14153) -Codechange: split ini file reading/saving from settings.cpp.
rubidium
parents:
diff changeset
    64
	 * @return the requested item or NULL if not found.
fceaf224b2f0 (svn r14153) -Codechange: split ini file reading/saving from settings.cpp.
rubidium
parents:
diff changeset
    65
	 */
fceaf224b2f0 (svn r14153) -Codechange: split ini file reading/saving from settings.cpp.
rubidium
parents:
diff changeset
    66
	IniItem *GetItem(const char *name, bool create);
fceaf224b2f0 (svn r14153) -Codechange: split ini file reading/saving from settings.cpp.
rubidium
parents:
diff changeset
    67
};
fceaf224b2f0 (svn r14153) -Codechange: split ini file reading/saving from settings.cpp.
rubidium
parents:
diff changeset
    68
fceaf224b2f0 (svn r14153) -Codechange: split ini file reading/saving from settings.cpp.
rubidium
parents:
diff changeset
    69
/** The complete ini file. */
fceaf224b2f0 (svn r14153) -Codechange: split ini file reading/saving from settings.cpp.
rubidium
parents:
diff changeset
    70
struct IniFile {
fceaf224b2f0 (svn r14153) -Codechange: split ini file reading/saving from settings.cpp.
rubidium
parents:
diff changeset
    71
	IniGroup *group;               ///< the first group in the ini
fceaf224b2f0 (svn r14153) -Codechange: split ini file reading/saving from settings.cpp.
rubidium
parents:
diff changeset
    72
	IniGroup **last_group;         ///< the last group in the ini
fceaf224b2f0 (svn r14153) -Codechange: split ini file reading/saving from settings.cpp.
rubidium
parents:
diff changeset
    73
	char *comment;                 ///< last comment in file
fceaf224b2f0 (svn r14153) -Codechange: split ini file reading/saving from settings.cpp.
rubidium
parents:
diff changeset
    74
	const char **list_group_names; ///< NULL terminated list with group names that are lists
fceaf224b2f0 (svn r14153) -Codechange: split ini file reading/saving from settings.cpp.
rubidium
parents:
diff changeset
    75
fceaf224b2f0 (svn r14153) -Codechange: split ini file reading/saving from settings.cpp.
rubidium
parents:
diff changeset
    76
	/**
fceaf224b2f0 (svn r14153) -Codechange: split ini file reading/saving from settings.cpp.
rubidium
parents:
diff changeset
    77
	 * Construct a new in-memory Ini file representation.
fceaf224b2f0 (svn r14153) -Codechange: split ini file reading/saving from settings.cpp.
rubidium
parents:
diff changeset
    78
	 * @param list_group_names A NULL terminated list with groups that should be
fceaf224b2f0 (svn r14153) -Codechange: split ini file reading/saving from settings.cpp.
rubidium
parents:
diff changeset
    79
	 *                         loaded as lists instead of variables.
fceaf224b2f0 (svn r14153) -Codechange: split ini file reading/saving from settings.cpp.
rubidium
parents:
diff changeset
    80
	 */
fceaf224b2f0 (svn r14153) -Codechange: split ini file reading/saving from settings.cpp.
rubidium
parents:
diff changeset
    81
	IniFile(const char **list_group_names = NULL);
fceaf224b2f0 (svn r14153) -Codechange: split ini file reading/saving from settings.cpp.
rubidium
parents:
diff changeset
    82
fceaf224b2f0 (svn r14153) -Codechange: split ini file reading/saving from settings.cpp.
rubidium
parents:
diff changeset
    83
	/** Free everything we loaded. */
fceaf224b2f0 (svn r14153) -Codechange: split ini file reading/saving from settings.cpp.
rubidium
parents:
diff changeset
    84
	~IniFile();
fceaf224b2f0 (svn r14153) -Codechange: split ini file reading/saving from settings.cpp.
rubidium
parents:
diff changeset
    85
fceaf224b2f0 (svn r14153) -Codechange: split ini file reading/saving from settings.cpp.
rubidium
parents:
diff changeset
    86
	/**
fceaf224b2f0 (svn r14153) -Codechange: split ini file reading/saving from settings.cpp.
rubidium
parents:
diff changeset
    87
	 * Get the group with the given name, and if it doesn't exist
fceaf224b2f0 (svn r14153) -Codechange: split ini file reading/saving from settings.cpp.
rubidium
parents:
diff changeset
    88
	 * create a new group.
fceaf224b2f0 (svn r14153) -Codechange: split ini file reading/saving from settings.cpp.
rubidium
parents:
diff changeset
    89
	 * @param name name of the group to find.
fceaf224b2f0 (svn r14153) -Codechange: split ini file reading/saving from settings.cpp.
rubidium
parents:
diff changeset
    90
	 * @param len  the maximum length of said name.
fceaf224b2f0 (svn r14153) -Codechange: split ini file reading/saving from settings.cpp.
rubidium
parents:
diff changeset
    91
	 * @return the requested group.
fceaf224b2f0 (svn r14153) -Codechange: split ini file reading/saving from settings.cpp.
rubidium
parents:
diff changeset
    92
	 */
fceaf224b2f0 (svn r14153) -Codechange: split ini file reading/saving from settings.cpp.
rubidium
parents:
diff changeset
    93
	IniGroup *GetGroup(const char *name, size_t len = 0);
fceaf224b2f0 (svn r14153) -Codechange: split ini file reading/saving from settings.cpp.
rubidium
parents:
diff changeset
    94
fceaf224b2f0 (svn r14153) -Codechange: split ini file reading/saving from settings.cpp.
rubidium
parents:
diff changeset
    95
	/**
fceaf224b2f0 (svn r14153) -Codechange: split ini file reading/saving from settings.cpp.
rubidium
parents:
diff changeset
    96
	 * Remove the group with the given name.
fceaf224b2f0 (svn r14153) -Codechange: split ini file reading/saving from settings.cpp.
rubidium
parents:
diff changeset
    97
	 * @param name name of the group to remove.
fceaf224b2f0 (svn r14153) -Codechange: split ini file reading/saving from settings.cpp.
rubidium
parents:
diff changeset
    98
	 */
fceaf224b2f0 (svn r14153) -Codechange: split ini file reading/saving from settings.cpp.
rubidium
parents:
diff changeset
    99
	void RemoveGroup(const char *name);
fceaf224b2f0 (svn r14153) -Codechange: split ini file reading/saving from settings.cpp.
rubidium
parents:
diff changeset
   100
fceaf224b2f0 (svn r14153) -Codechange: split ini file reading/saving from settings.cpp.
rubidium
parents:
diff changeset
   101
	/**
fceaf224b2f0 (svn r14153) -Codechange: split ini file reading/saving from settings.cpp.
rubidium
parents:
diff changeset
   102
	 * Load the Ini file's data from the disk.
fceaf224b2f0 (svn r14153) -Codechange: split ini file reading/saving from settings.cpp.
rubidium
parents:
diff changeset
   103
	 * @param filename the file to load.
fceaf224b2f0 (svn r14153) -Codechange: split ini file reading/saving from settings.cpp.
rubidium
parents:
diff changeset
   104
	 * @pre nothing has been loaded yet.
fceaf224b2f0 (svn r14153) -Codechange: split ini file reading/saving from settings.cpp.
rubidium
parents:
diff changeset
   105
	 */
fceaf224b2f0 (svn r14153) -Codechange: split ini file reading/saving from settings.cpp.
rubidium
parents:
diff changeset
   106
	void LoadFromDisk(const char *filename);
fceaf224b2f0 (svn r14153) -Codechange: split ini file reading/saving from settings.cpp.
rubidium
parents:
diff changeset
   107
fceaf224b2f0 (svn r14153) -Codechange: split ini file reading/saving from settings.cpp.
rubidium
parents:
diff changeset
   108
	/**
fceaf224b2f0 (svn r14153) -Codechange: split ini file reading/saving from settings.cpp.
rubidium
parents:
diff changeset
   109
	 * Save the Ini file's data to the disk.
fceaf224b2f0 (svn r14153) -Codechange: split ini file reading/saving from settings.cpp.
rubidium
parents:
diff changeset
   110
	 * @param filename the file to save to.
fceaf224b2f0 (svn r14153) -Codechange: split ini file reading/saving from settings.cpp.
rubidium
parents:
diff changeset
   111
	 * @return true if saving succeeded.
fceaf224b2f0 (svn r14153) -Codechange: split ini file reading/saving from settings.cpp.
rubidium
parents:
diff changeset
   112
	 */
fceaf224b2f0 (svn r14153) -Codechange: split ini file reading/saving from settings.cpp.
rubidium
parents:
diff changeset
   113
	bool SaveToDisk(const char *filename);
fceaf224b2f0 (svn r14153) -Codechange: split ini file reading/saving from settings.cpp.
rubidium
parents:
diff changeset
   114
};
fceaf224b2f0 (svn r14153) -Codechange: split ini file reading/saving from settings.cpp.
rubidium
parents:
diff changeset
   115
9999
d88ba8e0fd38 (svn r14156) -Fix (r14153): missing/wrong comments
smatz
parents: 9996
diff changeset
   116
#endif /* INI_TYPE_H */