This class allows loading and storing values and vectors of different types from ".ini" files easily.
The contents of the file will be modified by "write" operations in memory, and will be saved back to the file at the destructor, and only if at least one write operation has been applied.
Definition at line 47 of file CConfigFile.h.
#include <mrpt/utils/CConfigFile.h>
Public Member Functions | |
CConfigFile (const std::string &fileName) | |
Constructor that opens a configuration file. | |
CConfigFile () | |
Constructor, does not open any file. | |
void | setFileName (const std::string &fil_path) |
Associate this object with the given file, so future read/write operations will be applied to that file (it's synchronized at destruction). | |
void | writeNow () |
Dumps the changes to the physical configuration file now, not waiting until destruction. | |
std::string | getAssociatedFile () const |
Returns the file currently open by this object. | |
virtual | ~CConfigFile () |
Destructor. | |
virtual void | getAllSections (vector_string §ions) const |
Returns a list with all the section names. | |
virtual void | getAllKeys (const std::string section, vector_string &keys) const |
Returs a list with all the keys into a section. | |
Protected Member Functions | |
void | writeString (const std::string §ion, const std::string &name, const std::string &str) |
A virtual method to write a generic string. | |
std::string | readString (const std::string §ion, const std::string &name, const std::string &defaultStr, bool failIfNotFound=false) const |
A virtual method to read a generic string. | |
Private Attributes | |
std::string | m_file |
The name of the file. | |
void_ptr_noncopy | m_ini |
The interface to the file: | |
bool | m_modified |
If modified since load. |
mrpt::utils::CConfigFile::CConfigFile | ( | const std::string & | fileName | ) |
Constructor that opens a configuration file.
mrpt::utils::CConfigFile::CConfigFile | ( | ) |
Constructor, does not open any file.
You should call "setFileName" before reading or writting or otherwise nothing will be read and write operations will be eventually lost. However, it's perfectly right to use this object without an associated file, in which case it will behave as an "in-memory" file.
virtual mrpt::utils::CConfigFile::~CConfigFile | ( | ) | [virtual] |
Destructor.
virtual void mrpt::utils::CConfigFile::getAllKeys | ( | const std::string | section, |
vector_string & | keys | ||
) | const [virtual] |
Returs a list with all the keys into a section.
Implements mrpt::utils::CConfigFileBase.
virtual void mrpt::utils::CConfigFile::getAllSections | ( | vector_string & | sections | ) | const [virtual] |
Returns a list with all the section names.
Implements mrpt::utils::CConfigFileBase.
std::string mrpt::utils::CConfigFile::getAssociatedFile | ( | ) | const [inline] |
Returns the file currently open by this object.
Definition at line 94 of file CConfigFile.h.
std::string mrpt::utils::CConfigFile::readString | ( | const std::string & | section, |
const std::string & | name, | ||
const std::string & | defaultStr, | ||
bool | failIfNotFound = false |
||
) | const [protected, virtual] |
A virtual method to read a generic string.
std::exception | If the key name is not found and "failIfNotFound" is true. Otherwise the "defaultValue" is returned. |
Implements mrpt::utils::CConfigFileBase.
void mrpt::utils::CConfigFile::setFileName | ( | const std::string & | fil_path | ) |
Associate this object with the given file, so future read/write operations will be applied to that file (it's synchronized at destruction).
void mrpt::utils::CConfigFile::writeNow | ( | ) |
Dumps the changes to the physical configuration file now, not waiting until destruction.
void mrpt::utils::CConfigFile::writeString | ( | const std::string & | section, |
const std::string & | name, | ||
const std::string & | str | ||
) | [protected, virtual] |
A virtual method to write a generic string.
Implements mrpt::utils::CConfigFileBase.
std::string mrpt::utils::CConfigFile::m_file [private] |
The name of the file.
Definition at line 52 of file CConfigFile.h.
The interface to the file:
Definition at line 56 of file CConfigFile.h.
bool mrpt::utils::CConfigFile::m_modified [private] |
If modified since load.
Definition at line 60 of file CConfigFile.h.
Page generated by Doxygen 1.7.3 for MRPT 0.9.4 SVN:exported at Tue Jan 25 21:56:31 UTC 2011 |