MCS  0.3.3-alpha7
mcs::Conf Class Reference

Read and write configuration files. More...

#include <mcs.hh>

Public Member Functions

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

Private Member Functions

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

Private Attributes

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

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 4843 of file mcs.hh.

Constructor & Destructor Documentation

◆ Conf() [1/2]

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.

◆ Conf() [2/2]

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

Constructor, parse a configuration file.

Parameters
filenamePath to the configuration file.

Definition at line 28 of file Conf.cc.

◆ ~Conf()

mcs::Conf::~Conf ( )

Destructor.

Definition at line 36 of file Conf.cc.

Member Function Documentation

◆ index()

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

Search the index at which section and key are found.

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

Definition at line 104 of file Conf.cc.

◆ ival() [1/2]

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
sectionSection to search for;
keyKey to search for.
Returns
The value requested as an integer if found.
Exceptions
ERRORMSG_ENTRY_UNAVAILABLE.

Definition at line 142 of file Conf.cc.

◆ ival() [2/2]

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
sectionSection to search for;
keyKey to search for;
defvalDefault value.
Returns
The value requested as an integer string if found, the default value otherwise.

Definition at line 173 of file Conf.cc.

◆ lval() [1/2]

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
sectionSection to search for;
keyKey to search for.
Returns
The value requested as an integer if found.
Exceptions
ERRORMSG_ENTRY_UNAVAILABLE.

Definition at line 149 of file Conf.cc.

◆ lval() [2/2]

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
sectionSection to search for;
keyKey to search for;
defvalDefault value.
Returns
The value requested as an integer string if found, the default value otherwise.

Definition at line 182 of file Conf.cc.

◆ operator=()

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.

◆ save()

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
filenamePath to the configuration file.
Exceptions
ERRORMSG_CANT_OPEN_FILE.

Definition at line 227 of file Conf.cc.

◆ search()

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

Search for the specified section/key value.

Parameters
sectionSection to search for;
keyKey to search for.
throwexcIf THROW will throw an exception instead of returning an empty string.
Returns
True if the value has been found, false otherwise.
Exceptions
ERRORMSG_ENTRY_UNAVAILABLE.

Definition at line 122 of file Conf.cc.

◆ setval() [1/4]

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
sectionSection you wish to write to;
keyKey you wish to write to;
valNew value for the section/key pair;
commentOptional comment to the value.

Definition at line 191 of file Conf.cc.

◆ setval() [2/4]

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
sectionSection you wish to write to;
keyKey you wish to write to;
valNew value for the section/key pair;
commentOptional comment to the value.

Definition at line 221 of file Conf.cc.

◆ setval() [3/4]

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
sectionSection you wish to write to;
keyKey you wish to write to;
valNew value for the section/key pair;
commentOptional comment to the value.

Definition at line 215 of file Conf.cc.

◆ setval() [4/4]

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
sectionSection you wish to write to;
keyKey you wish to write to;
valNew value for the section/key pair;
commentOptional comment to the value.

Definition at line 209 of file Conf.cc.

◆ sval() [1/2]

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
sectionSection to search for;
keyKey to search for.
Returns
The value requested as a string if found.
Exceptions
ERRORMSG_ENTRY_UNAVAILABLE.

Definition at line 135 of file Conf.cc.

◆ sval() [2/2]

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
sectionSection to search for;
keyKey to search for;
defvalDefault value.
Returns
The value requested as a string if found, the default value otherwise.

Definition at line 164 of file Conf.cc.

◆ val()

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
sectionSection to search for;
keyKey to search for.
Returns
The value requested inside a Data object if found.
Exceptions
ERRORMSG_ENTRY_UNAVAILABLE.

Definition at line 156 of file Conf.cc.

Member Data Documentation

◆ comments

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

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

Definition at line 4859 of file mcs.hh.

◆ filename

string mcs::Conf::filename
private

Path to the configuration file.

Definition at line 4847 of file mcs.hh.

◆ keys

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

Internal vector containing keys names.

Definition at line 4853 of file mcs.hh.

◆ sections

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

Internal vector containing section names.

Definition at line 4850 of file mcs.hh.

◆ values

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

Internal vector containing values names.

Definition at line 4856 of file mcs.hh.


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

mcslogo

MCS (My Customizable Server) ver. 0.3.3-alpha7
Documentation generated on Mon May 28 07:39:41 UTC 2018