Developer Documentation
INIFile Class Reference

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, EntryMapSectionMap
 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...
 

Detailed Description

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:

  • Open an existing or create a new INI file with a call to connect()
  • Check for the existence of entries (entry_exists()), access stored values (get_entry()) or add new entries (add_entry()). Note that the function add_section() is obsolete and only kept for backward compatibility. A new section is now implicitly generated by specifying it in a call to add_entry().
  • disconnect() from the INI file. Only now are all entries and sections written to the file.

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.

Member Typedef Documentation

◆ EntryMap

typedef std::map< QString, QString > INIFile::EntryMap
private

Type for map of contained entries.

Definition at line 353 of file INIFile.hh.

◆ SectionMap

typedef std::map< QString, EntryMap > INIFile::SectionMap
private

Type for map of contained sections.

Definition at line 357 of file INIFile.hh.

Constructor & Destructor Documentation

◆ INIFile()

INIFile::INIFile ( )

Default constructor.

Definition at line 54 of file INIFile.cc.

◆ ~INIFile()

INIFile::~INIFile ( )

Destructor.

Definition at line 62 of file INIFile.cc.

Member Function Documentation

◆ add_entry() [1/13]

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.

◆ add_entry() [2/13]

void INIFile::add_entry ( const QString &  _section,
const QString &  _key,
const char *  _value 
)
inline

Addition / modification of a string entry, given as char array.

Definition at line 156 of file INIFile.hh.

◆ add_entry() [3/13]

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.

◆ add_entry() [4/13]

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.

◆ add_entry() [5/13]

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.

◆ add_entry() [6/13]

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.

◆ add_entry() [7/13]

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.

◆ add_entry() [8/13]

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.

◆ add_entry() [9/13]

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.

◆ add_entry() [10/13]

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.

◆ add_entry() [11/13]

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.

◆ add_entry() [12/13]

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.

◆ add_entry() [13/13]

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.

◆ add_entryVec() [1/2]

template<typename VectorT >
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.

◆ add_entryVec() [2/2]

template<typename VectorT >
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.

◆ add_section()

void INIFile::add_section ( const QString &  _sectionname)

Addition of a section.

Definition at line 247 of file INIFile.cc.

◆ connect()

bool INIFile::connect ( const QString &  name,
const bool  create 
)

Connect INIFile object with given filename.

Definition at line 70 of file INIFile.cc.

◆ delete_entry()

void INIFile::delete_entry ( const QString &  _section,
const QString &  _key 
)

Deletion of an entry.

Definition at line 409 of file INIFile.cc.

◆ delete_section()

void INIFile::delete_section ( const QString &  _sectionname)

Deletion of an entire section.

Definition at line 424 of file INIFile.cc.

◆ disconnect()

void INIFile::disconnect ( )

Remove connection of this object to a file.

Definition at line 122 of file INIFile.cc.

◆ entry_exists()

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.

◆ entry_in_section()

bool INIFile::entry_in_section ( const QString &  _section,
const QString &  _key 
) const
inline

Same as entry_exists() (for backward compatibility)

Definition at line 135 of file INIFile.hh.

◆ get_entry() [1/12]

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.

◆ get_entry() [2/12]

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.

◆ get_entry() [3/12]

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.

◆ get_entry() [4/12]

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.

◆ get_entry() [5/12]

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.

◆ get_entry() [6/12]

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.

◆ get_entry() [7/12]

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.

◆ get_entry() [8/12]

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.

◆ get_entry() [9/12]

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.

◆ get_entry() [10/12]

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.

◆ get_entry() [11/12]

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.

◆ get_entry() [12/12]

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.

◆ get_entryVecd() [1/2]

template<typename VectorT >
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.

◆ get_entryVecd() [2/2]

template<typename VectorT >
bool INIFile::get_entryVecd ( VectorT &  _val,
const QString &  _section,
const QString &  _key 
) const

Get a Vec_n_d (double)

Get a Vec_n_d.

Definition at line 126 of file INIFileT_impl.hh.

◆ get_entryVecf() [1/2]

template<typename VectorT >
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.

◆ get_entryVecf() [2/2]

template<typename VectorT >
bool INIFile::get_entryVecf ( VectorT &  _val,
const QString &  _section,
const QString &  _key 
) const

Get a Vec_n_i (int)

Get a Vec_n_f.

Definition at line 168 of file INIFileT_impl.hh.

◆ get_entryVeci() [1/2]

template<typename VectorT >
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.

◆ get_entryVeci() [2/2]

template<typename VectorT >
bool INIFile::get_entryVeci ( VectorT &  _val,
const QString &  _section,
const QString &  _key 
) const

Get a Vec_n_i (int)

Get a Vec_n_i.

Definition at line 84 of file INIFileT_impl.hh.

◆ is_connected()

bool INIFile::is_connected ( ) const
inline

Check if object is connected to file.

Definition at line 117 of file INIFile.hh.

◆ name()

const QString & INIFile::name ( ) const
inline

Access to name of connected file.

Definition at line 120 of file INIFile.hh.

◆ parseFile()

bool INIFile::parseFile ( QFile &  _inputStream)
private

Read content of an INI file.

Definition at line 131 of file INIFile.cc.

◆ section_exists()

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.

◆ writeFile()

bool INIFile::writeFile ( void  )
private

Write data to file we are currently connected to.

Definition at line 185 of file INIFile.cc.

Member Data Documentation

◆ m_filename

QString INIFile::m_filename
private

Name of current INI file.

Definition at line 370 of file INIFile.hh.

◆ m_iniData

SectionMap INIFile::m_iniData
private

Stored data of an INI file.

Definition at line 377 of file INIFile.hh.

◆ mf_isConnected

bool INIFile::mf_isConnected
private

Flag: this object is connected to an INI file.

Definition at line 373 of file INIFile.hh.


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