mcs::Conf Class Reference

#include <mcs.hh>

List of all members.


Detailed Description

Read and write configuration files.

This class can be used to read and write configuration files like those known as INI files in the Windows world.

Supported files can have sections (using the "[]" characters) and comments (from the "#" character to the new line).

Once the file have been parsed (by the constructor) values can be retrieved as STRING Data objects, as well as string or integers.

Definition at line 4858 of file mcs.hh.


Public Member Functions

 Conf (string filename="")
 Constructor, parse a configuration file.
 Conf (const Conf &)
 Declared to avoid using of default copy constructor.
int ival (string section, string key, int defval)
 Search for the specified section/key value and return it as an integer.
int ival (string section, string key)
 Search for the specified section/key value and return it as an integer.
long long int lval (string section, string key, int defval)
 Search for the specified section/key value and return it as a long integer.
long long int lval (string section, string key)
 Search for the specified section/key value and return it as a long integer.
void open (string filename)
Confoperator= (const Conf &)
 Declared to avoid using of default assignment operator.
void save (string filename="")
 Save all the values in a configuration file.
bool search (string section, string key, enum ThrowExceptions throwexc=DONT_THROW)
 Search for the specified section/key value.
void setval (string section, string key, Data *val, string comment="")
 Set a new value for the specified section/key pair.
void setval (string section, string key, int val, string comment="")
 Set a new value for the specified section/key pair.
void setval (string section, string key, long long int val, string comment="")
 Set a new value for the specified section/key pair.
void setval (string section, string key, string val, string comment="")
 Set a new value for the specified section/key pair.
string sval (string section, string key, string defval)
 Search for the specified section/key value and return it as a string.
string sval (string section, string key)
 Search for the specified section/key value and return it as a string.
Dataval (string section="", string key="")
 Return a Data object containing the last value found.
 ~Conf ()
 Destructor.

Private Member Functions

int index (string section, string key)
 Search the index at which section and key are found.

Private Attributes

vector< string > comments
 Internal vector containing comments, this is used in the save() method.
string filename
 Path to the configuration file.
vector< string > keys
 Internal vector containing keys names.
Data lastval
vector< string > sections
 Internal vector containing section names.
vector< string > values
 Internal vector containing values names.

Constructor & Destructor Documentation

mcs::Conf::Conf ( const Conf  ) 

Declared to avoid using of default copy constructor.

Warning:
This constructor is declared but not implemented. If you try to use it you will get a compilation error.

mcs::Conf::Conf ( string  filename = ""  ) 

Constructor, parse a configuration file.

Parameters:
filename Path to the configuration file.

Definition at line 28 of file Conf.cc.

mcs::Conf::~Conf (  ) 

Destructor.

Definition at line 36 of file Conf.cc.


Member Function Documentation

int mcs::Conf::index ( string  section,
string  key 
) [private]

Search the index at which section and key are found.

Parameters:
section Section to search for;
key Key to search for.
Returns:
Index of the section/key pair, or -1 if not found.

Definition at line 104 of file Conf.cc.

int mcs::Conf::ival ( string  section,
string  key,
int  defval 
)

Search for the specified section/key value and return it as an integer.

Return the containing the requested value as an integer if found, the default value passed in the last parameter otherwise.

Parameters:
section Section to search for;
key Key to search for;
defval Default value.
Returns:
The value requested as an integer string if found, the default value otherwise.

Definition at line 173 of file Conf.cc.

int mcs::Conf::ival ( string  section,
string  key 
)

Search for the specified section/key value and return it as an integer.

If the value is not found an exception will be thrown.

Parameters:
section Section to search for;
key Key to search for.
Returns:
The value requested as an integer if found.
Exceptions:
ERROR MSG_ENTRY_UNAVAILABLE.

Definition at line 142 of file Conf.cc.

long long int mcs::Conf::lval ( string  section,
string  key,
int  defval 
)

Search for the specified section/key value and return it as a long integer.

Return the containing the requested value as an integer if found, the default value passed in the last parameter otherwise.

Parameters:
section Section to search for;
key Key to search for;
defval Default value.
Returns:
The value requested as an integer string if found, the default value otherwise.

Definition at line 182 of file Conf.cc.

long long int mcs::Conf::lval ( string  section,
string  key 
)

Search for the specified section/key value and return it as a long integer.

If the value is not found an exception will be thrown.

Parameters:
section Section to search for;
key Key to search for.
Returns:
The value requested as an integer if found.
Exceptions:
ERROR MSG_ENTRY_UNAVAILABLE.

Definition at line 149 of file Conf.cc.

Conf& mcs::Conf::operator= ( const Conf  ) 

Declared to avoid using of default assignment operator.

Warning:
This operator is declared but not implemented. If you try to use it you will get a compilation error.

void mcs::Conf::save ( string  filename = ""  ) 

Save all the values in a configuration file.

If no parameter is given the path of the last configuration file opened will be used.

Parameters:
filename Path to the configuration file.
Exceptions:
ERROR MSG_CANT_OPEN_FILE.

Definition at line 227 of file Conf.cc.

bool mcs::Conf::search ( string  section,
string  key,
enum ThrowExceptions  throwexc = DONT_THROW 
)

Search for the specified section/key value.

Parameters:
section Section to search for;
key Key to search for.
throwexc If THROW will throw an exception instead of returning an empty string.
Returns:
True if the value has been found, false otherwise.
Exceptions:
ERROR MSG_ENTRY_UNAVAILABLE.

Definition at line 122 of file Conf.cc.

void mcs::Conf::setval ( string  section,
string  key,
Data val,
string  comment = "" 
)

Set a new value for the specified section/key pair.

If the section/key pair was already present its value will be substituted with the new one, otherwise it will be created.

The changes you made to the values won't be written to the configuration file until you call the save() method.

Parameters:
section Section you wish to write to;
key Key you wish to write to;
val New value for the section/key pair;
comment Optional comment to the value.

Definition at line 209 of file Conf.cc.

void mcs::Conf::setval ( string  section,
string  key,
int  val,
string  comment = "" 
)

Set a new value for the specified section/key pair.

If the section/key pair was already present its value will be substituted with the new one, otherwise it will be created.

The changes you made to the values won't be written to the configuration file until you call the save() method.

Parameters:
section Section you wish to write to;
key Key you wish to write to;
val New value for the section/key pair;
comment Optional comment to the value.

Definition at line 215 of file Conf.cc.

void mcs::Conf::setval ( string  section,
string  key,
long long int  val,
string  comment = "" 
)

Set a new value for the specified section/key pair.

If the section/key pair was already present its value will be substituted with the new one, otherwise it will be created.

The changes you made to the values won't be written to the configuration file until you call the save() method.

Parameters:
section Section you wish to write to;
key Key you wish to write to;
val New value for the section/key pair;
comment Optional comment to the value.

Definition at line 221 of file Conf.cc.

void mcs::Conf::setval ( string  section,
string  key,
string  val,
string  comment = "" 
)

Set a new value for the specified section/key pair.

If the section/key pair was already present its value will be substituted with the new one, otherwise it will be created.

The changes you made to the values won't be written to the configuration file until you call the save() method.

Parameters:
section Section you wish to write to;
key Key you wish to write to;
val New value for the section/key pair;
comment Optional comment to the value.

Definition at line 191 of file Conf.cc.

string mcs::Conf::sval ( string  section,
string  key,
string  defval 
)

Search for the specified section/key value and return it as a string.

Return a string containing the requested value if found, the default value passed in the last parameter otherwise.

Parameters:
section Section to search for;
key Key to search for;
defval Default value.
Returns:
The value requested as a string if found, the default value otherwise.

Definition at line 164 of file Conf.cc.

string mcs::Conf::sval ( string  section,
string  key 
)

Search for the specified section/key value and return it as a string.

If the value is not found an exception will be thrown.

Parameters:
section Section to search for;
key Key to search for.
Returns:
The value requested as a string if found.
Exceptions:
ERROR MSG_ENTRY_UNAVAILABLE.

Definition at line 135 of file Conf.cc.

Data & mcs::Conf::val ( string  section = "",
string  key = "" 
)

Return a Data object containing the last value found.

Search for the specified section/key value and return it in a Data object.

If the value is not found an exception will be thrown. If both parameters are empty string the retunred Data object contain the last requested value.

Parameters:
section Section to search for;
key Key to search for.
Returns:
The value requested inside a Data object if found.
Exceptions:
ERROR MSG_ENTRY_UNAVAILABLE.

Definition at line 156 of file Conf.cc.


Member Data Documentation

vector<string> mcs::Conf::comments [private]

Internal vector containing comments, this is used in the save() method.

Definition at line 4874 of file mcs.hh.

string mcs::Conf::filename [private]

Path to the configuration file.

Definition at line 4862 of file mcs.hh.

vector<string> mcs::Conf::keys [private]

Internal vector containing keys names.

Definition at line 4868 of file mcs.hh.

vector<string> mcs::Conf::sections [private]

Internal vector containing section names.

Definition at line 4865 of file mcs.hh.

vector<string> mcs::Conf::values [private]

Internal vector containing values names.

Definition at line 4871 of file mcs.hh.


The documentation for this class was generated from the following files:
mcslogo

MCS (My Customizable Server) ver. 0.3.3-alpha3
Documentation generated on Thu Mar 22 13:22:23 UTC 2012