Main Page   Namespace List   Class Hierarchy   Compound List   File List   Namespace Members   Compound Members   File Members  

ZE::ZConfigFile Class Reference

#include <ZE_ZConfigFile.h>

List of all members.


Detailed Description

ZConfigFile class for INI-style configuration files for games or applications. ZConfigFile can have comments using the semicolon (;) or octothorpe (#) characters. Sections are delimited by [section-name], and variables must start with a letter and should be in the format variable = data.


Public Member Functions

 ZConfigFile ()
 Default constructor.

 ZConfigFile (std::string filename)
 Constructor which takes filename.

virtual ~ZConfigFile ()
 Destructor, flushes file.

void Process (std::string filename)
 Parse a file.

float GetFloat (std::string section, std::string var, float defVal) const
 Get value in floating point format from file.

int GetInt (std::string section, std::string var, int defVal) const
 Get value in integer format from file.

bool GetBool (std::string section, std::string var, bool defVal) const
 Get value in boolean format from file.

std::string GetString (std::string section, std::string var, std::string defVal) const
 Get value in std::string format from file.

void SetFloat (std::string section, std::string var, float val)
 Set value in floating point format in file.

void SetInt (std::string section, std::string var, int val)
 Set value in integer format in file.

void SetBool (std::string section, std::string var, bool val)
 Set value in boolean format in file.

void SetString (std::string section, std::string var, std::string val)
 Set value in std::string format in file.

void Flush ()
 Write all values to file.

void Close ()
 Close the file.


Protected Member Functions

std::string CleanString (std::string str) const
 Reformat a std::string in a form more suitable to parsing.

bool Exists (std::string sec) const
 Check if a section exists.

bool Exists (std::string sec, std::string var) const
 Check if a variable exists.

void SetVariable (std::string sec, std::string var, std::string val)
 Internal function to set variables.

std::string GetVariable (std::string sec, std::string var, std::string defVal) const
 Internal function to get value of a variable.


Protected Attributes

std::list< ZCF_SectionrFileLayout
 List of sections of internal type.

std::string rFilename
 Filename of file currently open.


Constructor & Destructor Documentation

ZE::ZConfigFile::ZConfigFile  ) 
 

A no-op default constructor.

ZE::ZConfigFile::ZConfigFile std::string  filename  ) 
 

Constructor takes filename, and calls process on it.

Parameters:
filename File to load as ZConfigFile.

ZE::ZConfigFile::~ZConfigFile  )  [virtual]
 

Flushes the file, ensures a flush if the file is left open.


Member Function Documentation

std::string ZE::ZConfigFile::CleanString std::string  str  )  const [protected]
 

Removes whitespace from a std::string and makes all characters lowercase.

Parameters:
str The std::string to get a clean version of.
Returns:
Cleaned std::string.

bool ZE::ZConfigFile::Exists std::string  sec  )  const [protected]
 

Find out if a section currently exists.

Parameters:
sec Section to check for.
Returns:
bool, true if section exists in file.

bool ZE::ZConfigFile::Exists std::string  sec,
std::string  var
const [protected]
 

Find out if a variable currently exists.

Parameters:
sec Section to check in.
var Variable to check for.
Returns:
bool, true if section exists in file.

void ZE::ZConfigFile::SetVariable std::string  sec,
std::string  var,
std::string  val
[protected]
 

Set variable to value, called internally only.

Parameters:
sec Section for variable.
var Variable to set.
val Value to set variable to.

std::string ZE::ZConfigFile::GetVariable std::string  sec,
std::string  var,
std::string  defVal
const [protected]
 

Get value of variable, called internally only.

Parameters:
sec Section for variable.
var Variable to get.
defVal Value to return if variable doesnt exist.
Returns:
Value of variable.

void ZE::ZConfigFile::Process std::string  filename  ) 
 

Parses the file, reading the contents into the fileLayout map.

Parameters:
filename File to parse and attach this ZDataFile to.

float ZE::ZConfigFile::GetFloat std::string  section,
std::string  var,
float  defVal
const
 

Get the current value of a variable in the file, or defVal if not found in file.

Since:
0.8.3
Parameters:
section Name of section to seek variable under.
var Name of variable to seek value for.
defVal Value to return if var does not exist within section.
Returns:
Contents of the variable in floating point format.

int ZE::ZConfigFile::GetInt std::string  section,
std::string  var,
int  defVal
const
 

Get the current value of a variable in the file, or defVal if not found in file.

Parameters:
section Name of section to seek variable under.
var Name of variable to seek value for.
defVal Value to return if var does not exist within section.
Returns:
Contents of the variable in integer format.

bool ZE::ZConfigFile::GetBool std::string  section,
std::string  var,
bool  defVal
const
 

Get the current value of a variable in the file, or defVal if not found in file. (Valid values are "0","1","true" and "false")

Parameters:
section Name of section to seek variable under.
var Name of variable to seek value for.
defVal Value to return if var does not exist within section.
Returns:
Contents of the variable in boolean format.

std::string ZE::ZConfigFile::GetString std::string  section,
std::string  var,
std::string  defVal
const
 

Get the current value of a variable in the file, or defVal if not found in file.

Parameters:
section Name of section to seek variable under.
var Name of variable to seek value for.
defVal Value to return if var does not exist within section.
Returns:
Contents of the variable in std::string format.

void ZE::ZConfigFile::SetFloat std::string  section,
std::string  var,
float  val
 

Set the new value of a variable in the file to val, creating the section and variable if not already found in file.

Since:
0.8.3
Parameters:
section Name of section to edit variable under.
var Name of variable to set value for.
val Floating point value to set variable to in file.

void ZE::ZConfigFile::SetInt std::string  section,
std::string  var,
int  val
 

Set the new value of a variable in the file to val, creating the section and variable if not already found in file.

Parameters:
section Name of section to edit variable under.
var Name of variable to set value for.
val Integer value to set variable to in file.

void ZE::ZConfigFile::SetBool std::string  section,
std::string  var,
bool  val
 

Set the new value of a variable in the file to val, creating the section and variable if not already found in file.

Parameters:
section Name of section to edit variable under.
var Name of variable to set value for.
val Boolean value to set variable to in file.

void ZE::ZConfigFile::SetString std::string  section,
std::string  var,
std::string  val
 

Set the new value of a variable in the file to val, creating the section and variable if not already found in file.

Parameters:
section Name of section to edit variable under.
var Name of variable to set value for.
val String value to set variable to in file.

void ZE::ZConfigFile::Flush  ) 
 

Writes all values and sections to file.

void ZE::ZConfigFile::Close  ) 
 

Flush the file and clear the filename.


The documentation for this class was generated from the following files:
Generated on Sun Oct 5 19:34:46 2003 for ZEngine by doxygen1.3