#include <mcllib/MCIniFile.h>
Inheritance diagram for MCIniFile:
Public Member Functions | |
bool | exists (const MCString §ionName, const MCString &key) |
Check to see if a key exists in a section of the ini file. | |
bool | exists (const MCString §ionName) |
Check to see if a section exists in the ini file. | |
MCString | expand (const MCString &str) |
Expand a string containing variable references. | |
MCString | get (const MCString §ionKey) |
Get a value from a section of the ini file. | |
MCString | get (const MCString §ionName, const MCString &key) |
Get a value from a section of the ini file. | |
bool | isOpen () const |
Check to see if the ini file is open. | |
MCIniFile (const MCString &fileName, bool readOnly=true) | |
Initialize the ini file from a file in the filesystem. | |
MCIniFile () | |
Default constructor. | |
void | open (const MCString &fileName, bool readOnly=true) |
Initialize the ini file from a file in the filesystem. | |
MCIniSection & | operator[] (const MCString §ionName) |
Get a section in the ini file. | |
void | sync (bool clear=false) |
Synchronize the contents of the ini file with filesystem. |
An ini file is a structured text file used to provide configuration information for an application. The format of the file is
[section] var1=value1 var2=value2 ...
The file may contain multiple sections where the open and close square brackets are literal text that must be included. A section will only be recognized if the open square bracket appears at the beginning of a line. All the text between the open and close square brackets is used as the name of the section (except any leading and trailing white space). If there is more than one section with the same name (ignoring case) all the contents from the like-named sections are merged together as if the ini file contained a single section with all contents in it. The closing square bracket may be optionally followed by trailing white space which is ignored.
Each section may contain multiple variable assignments. A variable assignment consists of a variable name followed by an equals sign followed optionally by a value. Only the value part may be empty. All the text up to the equals sign (except any leading and trailing white space) is used as the name of the variable. All the text after the equals sign (including any leading and trailing white space) is used as the value of the variable. A variable may be repeated multiple times, only the last value will be used. The preceding values are discarded.
The file can be commented using lines which begin with semi-colon (;) or hash (#). Comments and blank lines are ignored.
This class is intentionally not thread safe for performance reasons. To be thread safe, lock a mutex before accessing its member functions.
|
Default constructor. The open method can specify the ini file to use. |
|
Initialize the ini file from a file in the filesystem.
|
|
Check to see if a key exists in a section of the ini file. The check is case insensitive.
|
|
Check to see if a section exists in the ini file. The check is case insensitive.
|
|
Expand a string containing variable references. Takes a string which may contain variable references and looks up the variable references in the ini file, replacing them with the value found in the ini file. Variable references use the following syntax
${section.key} where section and key are passed to the get() method. Variable expansion using expand is recursive. This means that if the referenced strings contains variable references, these are in turn expanded. There is a limit on the level of nesting of variable references to detect infinite recursion. The limit is sufficiently large for all practical purposes.
|
|
Get a value from a section of the ini file. The check for section and key is case insensitive.
|
|
Get a value from a section of the ini file. The check for section and key is case insensitive.
|
|
Check to see if the ini file is open.
|
|
Initialize the ini file from a file in the filesystem.
|
|
Get a section in the ini file.
|
|
Synchronize the contents of the ini file with filesystem. If the ini file was open()-ed read-only then the modification time of the file in the filesystem is checked and (if it has changed) the file is re-read. If the ini file was open()-ed read-write then the contents of the ini file are written to the filesystem.
|