Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Namespace Members | Class Members | File Members | Related Pages

IniFile Class Reference

Key/Value based .INI-File handling. More...

#include <IniFile.h>

List of all members.

Public Member Functions

 IniFile ()
 Construct an empty IniFile.

 IniFile (const char *filename)
 Construct an IniFile and load settings.

bool load (const char *filename)
 Load settings from an .ini file.

bool save (const char *filename) const
 Save setting to an .ini-File.

void removeKey (const char *section, const char *key)
 Remove a key from a section.

const char * getString (const char *section, const char *key, const char *def="") const
 Get value of key.

int getInt (const char *section, const char *key, int def=0) const
double getDouble (const char *section, const char *key, double def=0) const
bool getBool (const char *section, const char *key, bool def=false) const
void setString (const char *section, const char *key, const char *val)
 Set value of key.

void setInt (const char *section, const char *key, int val)
void setDouble (const char *section, const char *key, double val)
void setBool (const char *section, const char *key, bool val)

Private Types

typedef map< string, string,
lt_nocase
Keys
typedef map< string, Keys,
lt_nocase
Sections

Private Attributes

Sections sections


Detailed Description

Key/Value based .INI-File handling.

The values are stored in a double layered map. The first layer contains the section names, the second layer contains the actual key/value pairs. All names are case-insensitive, and are kept in sorted order. Insertion, lookup and removal of keys should take logarithmic time.

Author:
Thomas Kindler, thomas.kindler@gmx.de

Definition at line 18 of file IniFile.h.


Member Typedef Documentation

typedef map<string, string, lt_nocase> IniFile::Keys [private]
 

Definition at line 27 of file IniFile.h.

typedef map<string, Keys, lt_nocase> IniFile::Sections [private]
 

Definition at line 28 of file IniFile.h.


Constructor & Destructor Documentation

IniFile::IniFile  ) 
 

Construct an empty IniFile.

Definition at line 22 of file IniFile.cpp.

IniFile::IniFile const char *  filename  ) 
 

Construct an IniFile and load settings.

Parameters:
filename name of .ini file to load

Definition at line 32 of file IniFile.cpp.

References load().

Here is the call graph for this function:


Member Function Documentation

bool IniFile::load const char *  filename  ) 
 

Load settings from an .ini file.

Lines can be arbitrarily long and may use \-escaping and quoted whitespace. Comments must start with an ';'.

Note:
The contents of the file are added to the current list of settings. You can safely load multiple .ini-files into one IniFile instance.
Parameters:
filename name of .ini file to load
Returns:
true if successful, false otherwise

Definition at line 67 of file IniFile.cpp.

References InFile::exists(), InFile::getEof(), InStream< InFile, InBinary >::read(), and sections.

Referenced by IniFile().

Here is the call graph for this function:

bool IniFile::save const char *  filename  )  const
 

Save setting to an .ini-File.

Note:
Sections and keys are saved in undefined order, formatting and comments are not preserved.
Parameters:
filename name of .ini file to save into

Definition at line 218 of file IniFile.cpp.

References esc(), OutFile::exists(), and sections.

Here is the call graph for this function:

void IniFile::removeKey const char *  section,
const char *  key
 

Remove a key from a section.

Note:
section and key names are case-insensitive.
Parameters:
section section of key
key name of key to remove

Definition at line 45 of file IniFile.cpp.

References sections.

const char * IniFile::getString const char *  section,
const char *  key,
const char *  def = ""
const
 

Get value of key.

Note:
section and key names are case-insensitive.
Parameters:
section section of key
key name of key to retrieve
def default value
Returns:
value of key, or def if key doesn't exist

Definition at line 263 of file IniFile.cpp.

References sections.

Referenced by getBool(), getDouble(), and getInt().

int IniFile::getInt const char *  section,
const char *  key,
int  def = 0
const
 

Definition at line 275 of file IniFile.cpp.

References getString().

Here is the call graph for this function:

double IniFile::getDouble const char *  section,
const char *  key,
double  def = 0
const
 

Definition at line 282 of file IniFile.cpp.

References getString().

Here is the call graph for this function:

bool IniFile::getBool const char *  section,
const char *  key,
bool  def = false
const
 

Definition at line 289 of file IniFile.cpp.

References getString().

Here is the call graph for this function:

void IniFile::setString const char *  section,
const char *  key,
const char *  val
 

Set value of key.

Note:
section and key names are case-insensitive.
Parameters:
section section of key
key name of key to set
val value to set

Definition at line 247 of file IniFile.cpp.

References sections.

Referenced by setBool(), setDouble(), and setInt().

void IniFile::setInt const char *  section,
const char *  key,
int  val
 

Definition at line 303 of file IniFile.cpp.

References setString().

Here is the call graph for this function:

void IniFile::setDouble const char *  section,
const char *  key,
double  val
 

Definition at line 310 of file IniFile.cpp.

References setString().

Here is the call graph for this function:

void IniFile::setBool const char *  section,
const char *  key,
bool  val
 

Definition at line 317 of file IniFile.cpp.

References setString().

Here is the call graph for this function:


Member Data Documentation

Sections IniFile::sections [private]
 

Definition at line 30 of file IniFile.h.

Referenced by getString(), load(), removeKey(), save(), and setString().


The documentation for this class was generated from the following files:
Generated on Thu Sep 23 20:08:42 2004 for GT2004 by doxygen 1.3.6