IniFile Class Reference

#include <IniFile.h>

List of all members.

Public Member Functions

 IniFile ()
 IniFile (const char *filename)
bool load (const char *filename)
bool save (const char *filename) const
void removeKey (const char *section, const char *key)
const char * getString (const char *section, const char *key, const char *def="") const
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)
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

Classes

struct  lt_nocase


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 29 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 39 of file IniFile.cpp.

References load().


Member Function Documentation

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

Definition at line 296 of file IniFile.cpp.

References getString(), and stricmp().

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

Definition at line 289 of file IniFile.cpp.

References getString().

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

Definition at line 282 of file IniFile.cpp.

References getString().

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 270 of file IniFile.cpp.

References sections.

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

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 74 of file IniFile.cpp.

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

Referenced by IniFile().

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 52 of file IniFile.cpp.

References sections.

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 225 of file IniFile.cpp.

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

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

Definition at line 328 of file IniFile.cpp.

References setString().

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

Definition at line 319 of file IniFile.cpp.

References buffer, and setString().

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

Definition at line 310 of file IniFile.cpp.

References buffer, and setString().

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 254 of file IniFile.cpp.

References sections.

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


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 Dec 7 01:38:35 2006 for DT2005.panorama by  doxygen 1.4.7