79 QFile inputFile( _filename );
85 if ( inputFile.exists() && inputFile.open(QIODevice::ReadOnly | QIODevice::Text) ) {
95 }
else if( _create ) {
99 QFile outputFile(_filename);
101 if ( outputFile.open( QIODevice::Text |
102 QIODevice::WriteOnly |
103 QIODevice::Truncate ) ) {
111 std::cerr <<
"Unable to create File : " << std::endl;
117 std::cerr <<
"Unable to open File : " << std::endl;
139 QString line, section;
140 bool inSection =
false;
143 while( !_inputStream.atEnd() ) {
146 QByteArray lineBuffer = _inputStream.readLine();
147 line = QString(lineBuffer);
148 line = line.trimmed();
150 if( line.isEmpty() || line[ 0 ] ==
'#' )
154 if( line[ 0 ] ==
'[' && line[ line.length()-1 ] ==
']' ) {
157 section = line.mid( 1, line.length() - 2 );
160 }
else if( inSection ) {
165 pos = line.indexOf(
'=' );
169 key = line.mid( 0, pos );
171 value = line.mid( pos + 1, line.length() - 1 );
172 value = value.trimmed();
174 if( key.isEmpty() || value.isEmpty() )
199 if ( ! outputFile.open( QIODevice::WriteOnly ) )
202 QTextStream out(&outputFile);
205 SectionMap::const_iterator sIter, sEnd;
206 EntryMap::const_iterator eIter, eEnd;
209 for( sIter =
m_iniData.begin(); sIter != sEnd; ++sIter ) {
211 out <<
"[" << sIter->first <<
"]\n";
213 eEnd = sIter->second.end();
214 for( eIter = sIter->second.begin(); eIter != eEnd; ++eIter ) {
215 out << eIter->first <<
"=";
216 out << eIter->second;
244 static SectionMap::const_iterator mapIter;
247 && mapIter->second.find( _key ) != mapIter->second.end() );
264 const QString & _key,
265 const QString & _value )
275 const QString & _key,
276 const double & _value)
278 m_iniData[ _section ][ _key ] = QString::number( _value );
286 const QString & _key,
287 const float & _value)
289 m_iniData[ _section ][ _key ] = QString::number( _value );
297 const QString & _key ,
300 m_iniData[ _section ][ _key ] = QString::number( _value );
308 const QString & _key ,
309 const unsigned int & _value)
311 m_iniData[ _section ][ _key ] = QString::number( _value );
319 const QString & _key ,
322 m_iniData[ _section ][ _key ] = (_value ?
"true" :
"false");
330 const QString & _key,
331 const std::vector<float> & _value)
334 std::vector<float>::const_iterator viter;
335 for(viter = _value.begin();viter!=_value.end();++viter)
336 list += QString::number( *viter ) +
";";
345 const QString & _key,
346 const std::vector<double> & _value)
349 std::vector<double>::const_iterator viter;
350 for(viter = _value.begin();viter!=_value.end();++viter)
351 list += QString::number( *viter ) +
";";
360 const QString & _key,
361 const std::vector<bool> & _value)
364 std::vector<bool>::const_iterator viter;
365 for(viter = _value.begin();viter!=_value.end();++viter){
378 const QString & _key,
379 const std::vector<int> & _value)
382 std::vector<int>::const_iterator viter;
383 for(viter = _value.begin();viter!=_value.end();++viter)
384 list += QString::number( *viter ) +
";";
391 const QString & _key,
392 const std::vector<QString> & _value)
395 std::vector<QString>::const_iterator viter;
396 for(viter = _value.begin();viter!=_value.end();++viter) {
397 list += *viter +
";";
405 const QString & _key,
406 const QStringList & _value)
408 QString list = _value.join(
";");
417 SectionMap::iterator sIter;
418 EntryMap::iterator eIter;
423 if( (eIter = sIter->second.find( _key )) != sIter->second.end() )
424 sIter->second.erase( eIter );
440 const QString & _section,
441 const QString & _key )
const
443 SectionMap::const_iterator sIter;
444 EntryMap::const_iterator eIter;
451 if( (eIter = sIter->second.find( _key )) == sIter->second.end() )
454 _val = eIter->second;
463 const QString & _section,
464 const QString & _key )
const
466 SectionMap::const_iterator sIter;
467 EntryMap::const_iterator eIter;
474 if( (eIter = sIter->second.find( _key )) == sIter->second.end() )
478 _val = eIter->second.toDouble(&ok);
487 const QString & _section,
488 const QString & _key )
const
490 SectionMap::const_iterator sIter;
491 EntryMap::const_iterator eIter;
498 if( (eIter = sIter->second.find( _key )) == sIter->second.end() )
502 _val = eIter->second.toFloat(&ok);
511 const QString & _section,
512 const QString & _key )
const
514 SectionMap::const_iterator sIter;
515 EntryMap::const_iterator eIter;
522 if( (eIter = sIter->second.find( _key )) == sIter->second.end() )
526 _val = eIter->second.toInt(&ok);
534 const QString & _section,
535 const QString & _key )
const
537 SectionMap::const_iterator sIter;
538 EntryMap::const_iterator eIter;
545 if( (eIter = sIter->second.find( _key )) == sIter->second.end() )
549 _val = eIter->second.toUInt(&ok);
558 const QString & _section,
559 const QString & _key)
const
561 SectionMap::const_iterator sIter;
562 EntryMap::const_iterator eIter;
569 if( (eIter = sIter->second.find( _key )) == sIter->second.end() )
572 if( eIter->second ==
"true" || eIter->second ==
"false" ) {
573 _val = (eIter->second ==
"true");
585 const QString & _section,
586 const QString & _key )
const
588 SectionMap::const_iterator sIter;
589 EntryMap::const_iterator eIter;
598 if( (eIter = sIter->second.find( _key )) == sIter->second.end() )
601 QStringList list = eIter->second.split(
';');
604 for (
int i = 0 ; i < list.size(); ++i) {
605 if ( list[i].isEmpty() )
608 _val.push_back(list[i].toFloat(&tmpOk));
620 const QString & _section,
621 const QString & _key )
const
623 SectionMap::const_iterator sIter;
624 EntryMap::const_iterator eIter;
633 if( (eIter = sIter->second.find( _key )) == sIter->second.end() )
636 QStringList list = eIter->second.split(
';');
639 for (
int i = 0 ; i < list.size(); ++i) {
640 if ( list[i].isEmpty() )
643 _val.push_back(list[i].toDouble(&tmpOk));
655 const QString & _section,
656 const QString & _key )
const
658 SectionMap::const_iterator sIter;
659 EntryMap::const_iterator eIter;
668 if( (eIter = sIter->second.find( _key )) == sIter->second.end() )
671 QStringList list = eIter->second.split(
';');
674 for (
int i = 0 ; i < list.size(); ++i) {
675 if ( list[i].isEmpty() )
677 if (list[i] ==
"true")
678 _val.push_back(
true);
680 _val.push_back(
false);
691 const QString & _section,
692 const QString & _key )
const
694 SectionMap::const_iterator sIter;
695 EntryMap::const_iterator eIter;
704 if( (eIter = sIter->second.find( _key )) == sIter->second.end() )
707 QStringList list = eIter->second.split(
';');
710 for (
int i = 0 ; i < list.size(); ++i) {
711 if ( list[i].isEmpty() )
714 _val.push_back(list[i].toInt(&tmpOk));
726 const QString & _section,
727 const QString & _key )
const
729 SectionMap::const_iterator sIter;
730 EntryMap::const_iterator eIter;
739 if( (eIter = sIter->second.find( _key )) == sIter->second.end() )
742 QStringList list = eIter->second.split(
';');
745 for (
int i = 0 ; i < list.size(); ++i) {
746 if ( list[i].isEmpty() )
748 _val.push_back(list[i]);
759 const QString & _section,
760 const QString & _key )
const
762 SectionMap::const_iterator sIter;
763 EntryMap::const_iterator eIter;
772 if( (eIter = sIter->second.find( _key )) == sIter->second.end() )
775 _val = eIter->second.split(
';');
778 if ( _val.isEmpty() )
void disconnect()
Remove connection of this object to a file.
std::map< QString, QString > EntryMap
Type for map of contained entries.
bool connect(const QString &name, const bool create)
Connect INIFile object with given filename.
void delete_section(const QString &_sectionname)
Deletion of an entire section.
bool get_entry(QString &_val, const QString &_section, const QString &_key) const
Access to a string entry.
void add_entry(const QString &_section, const QString &_key, const QString &_value)
Addition / modification of a string entry.
bool is_connected() const
Check if object is connected to file.
bool parseFile(QFile &_inputStream)
Read content of an INI file.
void add_section(const QString &_sectionname)
Addition of a section.
QString m_filename
Name of current INI file.
bool mf_isConnected
Flag: this object is connected to an INI file.
bool writeFile(void)
Write data to file we are currently connected to.
void delete_entry(const QString &_section, const QString &_key)
Deletion of an entry.
bool section_exists(const QString &_section) const
Check if given section exists in the current INI file.
SectionMap m_iniData
Stored data of an INI file.
bool entry_exists(const QString &_section, const QString &_key) const
Check if given entry esists in the current INI file.
INIFile()
Default constructor.