Classes | Public Types | Public Member Functions | Static Public Member Functions

base::Config Class Reference

Configuration class. More...

#include <libppbase/base/Config.h>

List of all members.

Classes

class  Item
 A Configuration Item. More...

Public Types

enum  configFlags { flagNone = 0x00, flagKeep = 0x01, flagNeedNotExist = 0x02 }
 

Config flags.

More...

Public Member Functions

std::map< String, Item >::iterator begin ()
 Gets an iterator to the first configuration variable.
std::map< String, Item >
::const_iterator 
begin () const
 Gets an iterator to the first configuration variable.
void clear ()
 Deletes the entire configuration.
void clear (const String &var)
 Clears an array configuration variable.
std::map< String, Item >::iterator end ()
 Gets an iterator that points after the last configuration variable.
std::map< String, Item >
::const_iterator 
end () const
 Gets an iterator that points after the last configuration variable.
void erase (const String &var)
 Erases a configuration variable.
bool exists (const String &var) const
 Check if a configuration variable exists.
const std::vector< String > & getAll (const String &var) const
 Gets all items for an array variable.
bool getBool (const String &var, size_t pos=0) const
 Returns a configuration variable as a boolean.
bool getBool (const String &var, bool defval, size_t pos=0) const
 Returns a configuration variable as a boolean, returning a default value if it does not exist.
size_t getCount (const String &var) const
 Returns the number of array items of a configuration variable.
const StringgetFileName () const
 Gets the file name of the last read configuration file.
int getInt (const String &var, size_t pos=0) const
 Returns a configuration variable as an integer.
int getInt (const String &var, int defval, size_t pos=0) const
 Returns a configuration variable as an integer, returning a default value if it does not exist.
const StringgetString (const String &var, size_t pos=0) const
 Returns a configuration variable as string.
const StringgetString (const String &var, const String &defval, size_t pos=0) const
 Returns a configuration variable as string, returning a default value if it does not exist.
std::vector< StringgetVectorOfStrings (const String &var, char delim= ',', size_t pos=0) const
 Returns a configuration variable as a vector of strings.
void read (const String &fname, configFlags flags=flagNone)
 Reads a configuration file and stores all variables.
void readUser (const String &company, const String &product, const String &id, configFlags flags=flagNone)
 Reads a configuration file from the user area and stores all variables.
void setAll (const String &var, const std::vector< String > &val)
 Sets all items for an array variable.
void setBool (const String &var, bool val, size_t pos=0)
 Sets a configuration variable.
void setInt (const String &var, int val, size_t pos=0)
 Sets a configuration variable.
void setString (const String &var, const String &val, size_t pos=0)
 Sets a configuration variable.
void write () const
 Writes a configuration to the same file it was read from.
void write (const String &fname) const
 Writes a configuration file.
void writeUser (const String &company, const String &product, const String &id) const
 Writes a configuration file to the user area.

Static Public Member Functions

static bool fileExists (const String &fname)
 Checks if a configuration file exists.
static bool fileExistsUser (const String &company, const String &product, const String &id)
 Checks if a configuration file exists.
static String mkFileName (const String &fname)
 Gets the filename of a configuration file.
static String mkFileNameUser (const String &company, const String &product, const String &id)
 Gets the filename of a configuration file in the user area.

Detailed Description

Configuration class.

Author:
Christoph Schwarz
Version:
$Id: Config.h 21 2010-09-05 04:18:17Z cschwarz1 $

Member Enumeration Documentation

Config flags.

Enumerator:
flagNone 

no flags set

flagKeep 

keep existing configuration variables

flagNeedNotExist 

file does not need to exist, i.e. ignore non-existing file


Member Function Documentation

std::map<String, Item>::iterator base::Config::begin (  ) 

Gets an iterator to the first configuration variable.

Returns:
begin iterator
std::map<String, Item>::const_iterator base::Config::begin (  )  const

Gets an iterator to the first configuration variable.

Returns:
begin iterator
std::map<String, Item>::iterator base::Config::end (  ) 

Gets an iterator that points after the last configuration variable.

Returns:
end iterator
std::map<String, Item>::const_iterator base::Config::end (  )  const

Gets an iterator that points after the last configuration variable.

Returns:
end iterator
bool base::Config::exists ( const String var  )  const

Check if a configuration variable exists.

Parameters:
var the name of the configuration variable
Returns:
true if it exists, false if not
bool base::Config::getBool ( const String var,
size_t  pos = 0 
) const

Returns a configuration variable as a boolean.

Parameters:
var the name of the configuration variable
pos the array position
Returns:
the value of the configuration variable
bool base::Config::getBool ( const String var,
bool  defval,
size_t  pos = 0 
) const

Returns a configuration variable as a boolean, returning a default value if it does not exist.

Parameters:
var the name of the configuration variable
defval the defval value to return if the configuration variable does not exist
pos the array position
Returns:
the value of the configuration variable
size_t base::Config::getCount ( const String var  )  const

Returns the number of array items of a configuration variable.

Parameters:
var the name of the configuration variable
Returns:
the number of array items
const String& base::Config::getFileName (  )  const

Gets the file name of the last read configuration file.

Returns:
empty string if no file has been read
int base::Config::getInt ( const String var,
size_t  pos = 0 
) const

Returns a configuration variable as an integer.

Parameters:
var the name of the configuration variable
pos the array position
Returns:
the value of the configuration variable
int base::Config::getInt ( const String var,
int  defval,
size_t  pos = 0 
) const

Returns a configuration variable as an integer, returning a default value if it does not exist.

Parameters:
var the name of the configuration variable
defval the defval value to return if the configuration variable does not exist
pos the array position
Returns:
the value of the configuration variable
const String& base::Config::getString ( const String var,
size_t  pos = 0 
) const

Returns a configuration variable as string.

Parameters:
var the name of the configuration variable
pos the array position
Returns:
the value of the configuration variable
const String& base::Config::getString ( const String var,
const String defval,
size_t  pos = 0 
) const

Returns a configuration variable as string, returning a default value if it does not exist.

Parameters:
var the name of the configuration variable
defval the defval value to return if the configuration variable does not exist
pos the array position
Returns:
the value of the configuration variable
std::vector<String> base::Config::getVectorOfStrings ( const String var,
char  delim = ',',
size_t  pos = 0 
) const

Returns a configuration variable as a vector of strings.

Parameters:
var the name of the configuration variable
delim the delimiter that separates the elements
pos the array position
Returns:
the value of the configuration variable
static String base::Config::mkFileNameUser ( const String company,
const String product,
const String id 
) [static]

Gets the filename of a configuration file in the user area.

The file name is created depending on the platform:

  • UNIX: $HOME/.<lower(company)>/<lower(product)>/<lower(id)>.rc
  • Windows: $APPDATA/<company>/<product>/<id>.ini
    Parameters:
    company company name
    product product name
    id identifier from which the file name is built
void base::Config::read ( const String fname,
configFlags  flags = flagNone 
)

Reads a configuration file and stores all variables.

Parameters:
fname the file name, absolute or relative to the global base directory
flags keep/override settings
void base::Config::readUser ( const String company,
const String product,
const String id,
configFlags  flags = flagNone 
)

Reads a configuration file from the user area and stores all variables.

Parameters:
company company name
product product name
id identifier from which the file name is built
flags keep/override settings
void base::Config::write ( const String fname  )  const

Writes a configuration file.

Parameters:
fname the file name, absolute or relative to the global base directory
void base::Config::writeUser ( const String company,
const String product,
const String id 
) const

Writes a configuration file to the user area.

Parameters:
company company name
product product name
id identifier from which the file name is built

The documentation for this class was generated from the following file: