Marine Library
1.0
C++ library for Linux Networking Development
|
Parse config file and get attributes. More...
#include <configuration.hh>
Public Member Functions | |||||||||||||||||||||||
std::string | getConfName () const | ||||||||||||||||||||||
Get config file name. More... | |||||||||||||||||||||||
void | clear () | ||||||||||||||||||||||
Clear all attributes loaded. More... | |||||||||||||||||||||||
bool | load (const std::string &file_name, int format=kFormatSpace) | ||||||||||||||||||||||
Parse and load content of a config file. More... | |||||||||||||||||||||||
std::string | getString (const std::string &key, const std::string &strdefault="") const | ||||||||||||||||||||||
Get string value of an attribute. More... | |||||||||||||||||||||||
std::string | getFilepath (const std::string &key, const std::string &strdefault="") const | ||||||||||||||||||||||
Get file name value of an attribute. More... | |||||||||||||||||||||||
std::string | toString () const | ||||||||||||||||||||||
Get a readable description of this object. More... | |||||||||||||||||||||||
getInt | |||||||||||||||||||||||
These functions try to translate the value to an integer.
For example,
| |||||||||||||||||||||||
int | getInt (const std::string &key, int ndefault=0, int min=std::numeric_limits< int >::min(), int max=std::numeric_limits< int >::max()) const | ||||||||||||||||||||||
template<typename Int > | |||||||||||||||||||||||
Int | getInt (const std::string &key, Int ndefault=0, Int min=std::numeric_limits< Int >::min(), Int max=std::numeric_limits< Int >::max()) const | ||||||||||||||||||||||
Static Public Attributes | |
static const int | kFormatEqual = 0 |
static const int | kFormatSpace = 1 |
static const int | kFormatColon = 2 |
Parse config file and get attributes.
A config file is a text file consisting of attributes. An attribute consists of a name and its value.
There is only one attribute per line. Empty lines are allowed. Any content after #
will be treated as comments, until the end of the line.
Attribute name and value consist of any readable characters. Leading and trailing spaces will be trimmed. But spaces inside of a name or value are considered part of it.
CConfiguration supports 3 formats of config files:
kFormatEqual
NAME = VALUE
, which means =
cannot be part of an attribute name or value. kFormatSpace
NAME VALUE
, which means SPACE
cannot be part of an attribute name or value. kFormatColon
NAME : VALUE
, which means
: cannot be part of an attribute name or value.
|
inline |
Clear all attributes loaded.
This function won't change the content of config file.
|
inline |
Get config file name.
|
inline |
Get file name value of an attribute.
This function considers the value to be a file name relative to the current working directory, and tries to expand it to a full pathname.
If the value is empty or a full pathname already, no expansion will take place.
key | Attribute name |
strdefault | Default value if key is not found, before expansion |
|
inline |
Get string value of an attribute.
key | Attribute name |
strdefault | Default value if key is not found |
|
inline |
Parse and load content of a config file.
file_name | Config file name |
format | Config file format, could be kFormatEqual , kFormatSpace or kFormatColon |
true
if succeeded; otherwise false
|
inline |
Get a readable description of this object.