Developer Documentation
|
Class for the handling of simple configuration files. More...
#include <OpenFlipper/INIFile/INIFile.hh>
Public Member Functions | |
INIFile () | |
Default constructor. More... | |
~INIFile () | |
Destructor. More... | |
bool | connect (const QString &name, const bool create) |
Connect INIFile object with given filename. More... | |
void | disconnect () |
Remove connection of this object to a file. More... | |
bool | is_connected () const |
Check if object is connected to file. More... | |
const QString & | name () const |
Access to name of connected file. More... | |
Existence checking | |
bool | section_exists (const QString &_section) const |
Check if given section exists in the current INI file. More... | |
bool | entry_exists (const QString &_section, const QString &_key) const |
Check if given entry esists in the current INI file. More... | |
bool | entry_in_section (const QString &_section, const QString &_key) const |
Same as entry_exists() (for backward compatibility) More... | |
Addition of entities | |
void | add_section (const QString &_sectionname) |
Addition of a section. More... | |
void | add_entry (const QString &_section, const QString &_key, const QString &_value) |
Addition / modification of a string entry. More... | |
void | add_entry (const QString &_section, const QString &_key, const char *_value) |
Addition / modification of a string entry, given as char array. More... | |
void | add_entry (const QString &_section, const QString &_key, const double &_value) |
Addition / modification of a double entry. More... | |
void | add_entry (const QString &_section, const QString &_key, const float &_value) |
Addition / modification of a double entry. More... | |
void | add_entry (const QString &_section, const QString &_key, const int &_value) |
Addition / modification of an int entry. More... | |
void | add_entry (const QString &_section, const QString &_key, const unsigned int &_value) |
Addition / modification of an int entry. More... | |
void | add_entry (const QString &_section, const QString &_key, const bool &_value) |
Addition / modification of a boolean entry. More... | |
void | add_entry (const QString &_section, const QString &_key, const std::vector< float > &_value) |
Addition / modification of a float vector. More... | |
void | add_entry (const QString &_section, const QString &_key, const std::vector< double > &_value) |
Addition / modification of a double vector. More... | |
void | add_entry (const QString &_section, const QString &_key, const std::vector< bool > &_value) |
Addition / modification of a bool vector. More... | |
template<typename VectorT > | |
void | add_entryVec (const QString &_section, const QString &_key, const VectorT &_value) |
Addition of a Vec_n_something. More... | |
template<typename VectorT > | |
void | add_entryVec (const QString &_section, const QString &_key, const std::vector< VectorT > &_value) |
Addition of a vector of Vec_n_something. More... | |
void | add_entry (const QString &_section, const QString &_key, const std::vector< int > &_value) |
Addition / modification of an int vector. More... | |
void | add_entry (const QString &_section, const QString &_key, const std::vector< QString > &_value) |
Addition / modification of an int vector. More... | |
void | add_entry (const QString &_section, const QString &_key, const QStringList &_value) |
Addition / modification of an int vector. More... | |
Deletion of entities | |
void | delete_entry (const QString &_section, const QString &_key) |
Deletion of an entry. More... | |
void | delete_section (const QString &_sectionname) |
Deletion of an entire section. More... | |
Access to stored entries | |
typedef std::map< QString, QString > | EntryMap |
Type for map of contained entries. More... | |
typedef std::map< QString, EntryMap > | SectionMap |
Type for map of contained sections. More... | |
QString | m_filename |
Name of current INI file. More... | |
bool | mf_isConnected |
Flag: this object is connected to an INI file. More... | |
SectionMap | m_iniData |
Stored data of an INI file. More... | |
bool | get_entry (QString &_val, const QString &_section, const QString &_key) const |
Access to a string entry. More... | |
bool | get_entry (double &_val, const QString &_section, const QString &_key) const |
Access to a floating point entry, stored as double value. More... | |
bool | get_entry (float &_val, const QString &_section, const QString &_key) const |
Access to a floating point entry, stored as float value. More... | |
bool | get_entry (int &_val, const QString &_section, const QString &_key) const |
Access to an int entry. More... | |
bool | get_entry (unsigned int &_val, const QString &_section, const QString &_key) const |
Access to an unsigned int entry (which is actually stored as int!!!) More... | |
bool | get_entry (bool &_val, const QString &_section, const QString &_key) const |
Access to a boolean entry. More... | |
bool | get_entry (std::vector< float > &_val, const QString &_section, const QString &_key) const |
Access to a float vector. More... | |
bool | get_entry (std::vector< double > &_val, const QString &_section, const QString &_key) const |
Access to a double vector. More... | |
bool | get_entry (std::vector< bool > &_val, const QString &_section, const QString &_key) const |
Access to a bool vector. More... | |
bool | get_entry (std::vector< int > &_val, const QString &_section, const QString &_key) const |
Access to an int vector. More... | |
bool | get_entry (std::vector< QString > &_val, const QString &_section, const QString &_key) const |
Access to a string vector. More... | |
bool | get_entry (QStringList &_val, const QString &_section, const QString &_key) const |
Access to a stringList. More... | |
template<typename VectorT > | |
bool | get_entryVecd (VectorT &_val, const QString &_section, const QString &_key) const |
Get a Vec_n_d (double) More... | |
template<typename VectorT > | |
bool | get_entryVecf (VectorT &_val, const QString &_section, const QString &_key) const |
Get a Vec_n_i (int) More... | |
template<typename VectorT > | |
bool | get_entryVeci (VectorT &_val, const QString &_section, const QString &_key) const |
Get a Vec_n_i (int) More... | |
template<typename VectorT > | |
bool | get_entryVecd (std::vector< VectorT > &_val, const QString &_section, const QString &_key) const |
Get a Vec_n_d. More... | |
template<typename VectorT > | |
bool | get_entryVecf (std::vector< VectorT > &_val, const QString &_section, const QString &_key) const |
Get a Vec_n_f. More... | |
template<typename VectorT > | |
bool | get_entryVeci (std::vector< VectorT > &_val, const QString &_section, const QString &_key) const |
Get a Vec_n_i. More... | |
bool | parseFile (QFile &_inputStream) |
Read content of an INI file. More... | |
bool | writeFile (void) |
Write data to file we are currently connected to. More... | |
Class for the handling of simple configuration files.
The file format used by this class is similar to that of MS Windows INI files. It is possible to divide a file into sections which are denoted by brackets (e.g. [Section]
). All values are stored in the form <key> = <value>
and are assigned to a section. The INIFile class is able to store values of the types string, double, signed and unsigned int and bool.
The usual way to work with this class consists of the following steps:
To be able to use the INIFile class, an object is created. After that the object is connected to a given filename. This means that, if the file exists, it is opened and the content is parsed and stored in memory. The second (boolean) parameter to the connect() function indicates that the file should be created if it does not exists.
Now a new section named Main
is generated and several entries are added. Note that the INI file is not written to disc until the disconnect() function is called. All additions and modifications are only performed on the stored data in memory.
In the second part of this example the just created INI file is opened (connected) again and the created entries are read and printed to stdout
.
Definition at line 99 of file INIFile.hh.
|
private |
Type for map of contained entries.
Definition at line 353 of file INIFile.hh.
|
private |
Type for map of contained sections.
Definition at line 357 of file INIFile.hh.
INIFile::INIFile | ( | ) |
Default constructor.
Definition at line 54 of file INIFile.cc.
INIFile::~INIFile | ( | ) |
Destructor.
Definition at line 62 of file INIFile.cc.
void INIFile::add_entry | ( | const QString & | _section, |
const QString & | _key, | ||
const bool & | _value | ||
) |
Addition / modification of a boolean entry.
Definition at line 312 of file INIFile.cc.
|
inline |
Addition / modification of a string entry, given as char array.
Definition at line 156 of file INIFile.hh.
void INIFile::add_entry | ( | const QString & | _section, |
const QString & | _key, | ||
const double & | _value | ||
) |
Addition / modification of a double entry.
Definition at line 268 of file INIFile.cc.
void INIFile::add_entry | ( | const QString & | _section, |
const QString & | _key, | ||
const float & | _value | ||
) |
Addition / modification of a double entry.
Definition at line 279 of file INIFile.cc.
void INIFile::add_entry | ( | const QString & | _section, |
const QString & | _key, | ||
const int & | _value | ||
) |
Addition / modification of an int entry.
Definition at line 290 of file INIFile.cc.
void INIFile::add_entry | ( | const QString & | _section, |
const QString & | _key, | ||
const QString & | _value | ||
) |
Addition / modification of a string entry.
Definition at line 257 of file INIFile.cc.
void INIFile::add_entry | ( | const QString & | _section, |
const QString & | _key, | ||
const QStringList & | _value | ||
) |
Addition / modification of an int vector.
Definition at line 398 of file INIFile.cc.
void INIFile::add_entry | ( | const QString & | _section, |
const QString & | _key, | ||
const std::vector< bool > & | _value | ||
) |
Addition / modification of a bool vector.
Definition at line 353 of file INIFile.cc.
void INIFile::add_entry | ( | const QString & | _section, |
const QString & | _key, | ||
const std::vector< double > & | _value | ||
) |
Addition / modification of a double vector.
Definition at line 338 of file INIFile.cc.
void INIFile::add_entry | ( | const QString & | _section, |
const QString & | _key, | ||
const std::vector< float > & | _value | ||
) |
Addition / modification of a float vector.
Definition at line 323 of file INIFile.cc.
void INIFile::add_entry | ( | const QString & | _section, |
const QString & | _key, | ||
const std::vector< int > & | _value | ||
) |
Addition / modification of an int vector.
Definition at line 371 of file INIFile.cc.
void INIFile::add_entry | ( | const QString & | _section, |
const QString & | _key, | ||
const std::vector< QString > & | _value | ||
) |
Addition / modification of an int vector.
Definition at line 384 of file INIFile.cc.
void INIFile::add_entry | ( | const QString & | _section, |
const QString & | _key, | ||
const unsigned int & | _value | ||
) |
Addition / modification of an int entry.
Definition at line 301 of file INIFile.cc.
void INIFile::add_entryVec | ( | const QString & | _section, |
const QString & | _key, | ||
const std::vector< VectorT > & | _value | ||
) |
Addition of a vector of Vec_n_something.
Definition at line 402 of file INIFileT_impl.hh.
void INIFile::add_entryVec | ( | const QString & | _section, |
const QString & | _key, | ||
const VectorT & | _value | ||
) |
Addition of a Vec_n_something.
Addition of a vector of Vec_n_whatever.
Definition at line 212 of file INIFileT_impl.hh.
void INIFile::add_section | ( | const QString & | _sectionname | ) |
Addition of a section.
Definition at line 247 of file INIFile.cc.
bool INIFile::connect | ( | const QString & | name, |
const bool | create | ||
) |
Connect INIFile object with given filename.
Definition at line 70 of file INIFile.cc.
void INIFile::delete_entry | ( | const QString & | _section, |
const QString & | _key | ||
) |
Deletion of an entry.
Definition at line 409 of file INIFile.cc.
void INIFile::delete_section | ( | const QString & | _sectionname | ) |
Deletion of an entire section.
Definition at line 424 of file INIFile.cc.
void INIFile::disconnect | ( | ) |
Remove connection of this object to a file.
Definition at line 122 of file INIFile.cc.
bool INIFile::entry_exists | ( | const QString & | _section, |
const QString & | _key | ||
) | const |
Check if given entry esists in the current INI file.
Definition at line 236 of file INIFile.cc.
|
inline |
Same as entry_exists() (for backward compatibility)
Definition at line 135 of file INIFile.hh.
bool INIFile::get_entry | ( | bool & | _val, |
const QString & | _section, | ||
const QString & | _key | ||
) | const |
Access to a boolean entry.
Definition at line 551 of file INIFile.cc.
bool INIFile::get_entry | ( | double & | _val, |
const QString & | _section, | ||
const QString & | _key | ||
) | const |
Access to a floating point entry, stored as double value.
Definition at line 456 of file INIFile.cc.
bool INIFile::get_entry | ( | float & | _val, |
const QString & | _section, | ||
const QString & | _key | ||
) | const |
Access to a floating point entry, stored as float value.
Definition at line 480 of file INIFile.cc.
bool INIFile::get_entry | ( | int & | _val, |
const QString & | _section, | ||
const QString & | _key | ||
) | const |
Access to an int entry.
Definition at line 504 of file INIFile.cc.
bool INIFile::get_entry | ( | QString & | _val, |
const QString & | _section, | ||
const QString & | _key | ||
) | const |
Access to a string entry.
Definition at line 433 of file INIFile.cc.
bool INIFile::get_entry | ( | QStringList & | _val, |
const QString & | _section, | ||
const QString & | _key | ||
) | const |
Access to a stringList.
Definition at line 752 of file INIFile.cc.
bool INIFile::get_entry | ( | std::vector< bool > & | _val, |
const QString & | _section, | ||
const QString & | _key | ||
) | const |
Access to a bool vector.
Definition at line 648 of file INIFile.cc.
bool INIFile::get_entry | ( | std::vector< double > & | _val, |
const QString & | _section, | ||
const QString & | _key | ||
) | const |
Access to a double vector.
Definition at line 613 of file INIFile.cc.
bool INIFile::get_entry | ( | std::vector< float > & | _val, |
const QString & | _section, | ||
const QString & | _key | ||
) | const |
Access to a float vector.
Definition at line 578 of file INIFile.cc.
bool INIFile::get_entry | ( | std::vector< int > & | _val, |
const QString & | _section, | ||
const QString & | _key | ||
) | const |
Access to an int vector.
Definition at line 684 of file INIFile.cc.
bool INIFile::get_entry | ( | std::vector< QString > & | _val, |
const QString & | _section, | ||
const QString & | _key | ||
) | const |
Access to a string vector.
Definition at line 719 of file INIFile.cc.
bool INIFile::get_entry | ( | unsigned int & | _val, |
const QString & | _section, | ||
const QString & | _key | ||
) | const |
Access to an unsigned int entry (which is actually stored as int!!!)
Definition at line 527 of file INIFile.cc.
bool INIFile::get_entryVecd | ( | std::vector< VectorT > & | _val, |
const QString & | _section, | ||
const QString & | _key | ||
) | const |
Get a Vec_n_d.
Definition at line 233 of file INIFileT_impl.hh.
bool INIFile::get_entryVecd | ( | VectorT & | _val, |
const QString & | _section, | ||
const QString & | _key | ||
) | const |
bool INIFile::get_entryVecf | ( | std::vector< VectorT > & | _val, |
const QString & | _section, | ||
const QString & | _key | ||
) | const |
Get a Vec_n_f.
Definition at line 289 of file INIFileT_impl.hh.
bool INIFile::get_entryVecf | ( | VectorT & | _val, |
const QString & | _section, | ||
const QString & | _key | ||
) | const |
bool INIFile::get_entryVeci | ( | std::vector< VectorT > & | _val, |
const QString & | _section, | ||
const QString & | _key | ||
) | const |
Get a Vec_n_i.
Definition at line 345 of file INIFileT_impl.hh.
bool INIFile::get_entryVeci | ( | VectorT & | _val, |
const QString & | _section, | ||
const QString & | _key | ||
) | const |
|
inline |
Check if object is connected to file.
Definition at line 117 of file INIFile.hh.
|
inline |
Access to name of connected file.
Definition at line 120 of file INIFile.hh.
|
private |
Read content of an INI file.
Definition at line 131 of file INIFile.cc.
bool INIFile::section_exists | ( | const QString & | _section | ) | const |
Check if given section exists in the current INI file.
Definition at line 227 of file INIFile.cc.
|
private |
Write data to file we are currently connected to.
Definition at line 185 of file INIFile.cc.
|
private |
Name of current INI file.
Definition at line 370 of file INIFile.hh.
|
private |
Stored data of an INI file.
Definition at line 377 of file INIFile.hh.
|
private |
Flag: this object is connected to an INI file.
Definition at line 373 of file INIFile.hh.