Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 7629 in orxonox.OLD for branches/qt_gui/src/lib


Ignore:
Timestamp:
May 16, 2006, 11:36:56 PM (19 years ago)
Author:
bensch
Message:

minor ini-parser-stuff

Location:
branches/qt_gui/src/lib
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • branches/qt_gui/src/lib/parser/ini_parser/ini_parser.cc

    r7626 r7629  
    401401 * @return true if everything is ok false on error
    402402 */
    403 bool IniParser::editVar(const std::string& entryName, const std::string& value, const std::string& sectionName)
     403bool IniParser::editVar(const std::string& entryName, const std::string& value, const std::string& sectionName, bool createMissing)
    404404{
    405405  std::list<IniSection>::iterator section;
     
    416416  if (section == this->sections.end())
    417417  {
    418     IniSection sec;
    419     sec.comment = "";
    420     sec.name = sectionName;
    421     section = this->sections.insert(this->sections.end(), sec);
    422   }
    423 
    424   if (section == this->sections.end())
    425   {
    426     PRINTF(2)("section '%s' not found for value '%s'\n", sectionName.c_str(), entryName.c_str());
    427     return false;
    428   }
    429   else
    430   {
    431     //try find item
    432     std::list<IniEntry>::iterator entry;
    433     for (entry = section->entries.begin(); entry!=section->entries.end(); entry++)
    434       if (entry->name == entryName )
     418    this->addSection(sectionName);
     419    for (section = this->sections.begin(); section != this->sections.end(); section++)
     420      if ((*section).name == sectionName)
    435421        break;
    436 
    437     //found it?
    438     if ( entry != section->entries.end() )
    439     {
    440       entry->value = value;
    441 
    442       return true;
    443     }
    444 
     422  }
     423
     424  //try find item
     425  std::list<IniEntry>::iterator entry;
     426  for (entry = section->entries.begin(); entry!=section->entries.end(); entry++)
     427    if (entry->name == entryName )
     428      break;
     429
     430  //found it?
     431  if ( entry != section->entries.end() )
     432  {
     433    entry->value = value;
     434
     435    return true;
     436  }
     437  else
     438  {
    445439    //not found -> create it
    446440    (*section).entries.push_back(IniEntry());
     
    448442    (*section).entries.back().name = entryName;
    449443    (*section).entries.back().value = value;
    450     PRINTF(5)("Added Entry %s with Value '%s' to Section %s\n",
    451     (*section).entries.back().name.c_str(),
    452     (*section).entries.back().value.c_str(),
    453     (*section).name);
     444    PRINTF(5)("Added Entry '%s' with Value '%s' to Section '%s'\n",
     445              (*section).entries.back().name.c_str(),
     446              (*section).entries.back().value.c_str(),
     447              (*section).name);
    454448    this->currentEntry = --(*section).entries.end();
    455449    return true;
    456450  }
     451  return false;
    457452}
    458453
     
    725720void IniParser::debug() const
    726721{
    727   PRINTF(0)("Iniparser %s - debug\n", this->fileName.c_str());
     722  PRINT(0)("Iniparser '%s' - debug\n", this->fileName.c_str());
    728723  if (!this->comment.empty())
    729     PRINTF(0)("FileComment:\n %s\n\n", this->comment.c_str());
     724    PRINT(0)("FileComment:\n '%s'\n\n", this->comment.c_str());
    730725
    731726  if (!this->fileName.empty())
    732727  {
     728    if (sections.empty())
     729      PRINT(0)("No Sections defined\n");
    733730    std::list<IniSection>::const_iterator section;
    734731    for (section = this->sections.begin(); section != this->sections.end(); section++)
     
    737734        PRINTF(0)(" %s\n", (*section).comment.c_str());
    738735      PRINTF(0)(" [%s]\n", (*section).name.c_str());
     736
     737      if ((*section).entries.empty())
     738        PRINT(0)("No Entries defined within Section '%s'\n", (*section).name.c_str());
    739739
    740740      std::list<IniEntry>::const_iterator entry;
     
    748748  }
    749749  else
    750     PRINTF(1)("no opened ini-file.\n");
    751 }
    752 
     750    PRINTF(0)("no opened ini-file.\n");
     751}
     752
  • branches/qt_gui/src/lib/parser/ini_parser/ini_parser.h

    r7626 r7629  
    6666    bool addVar(const std::string& entryName, const std::string& value, const std::string& sectionName = "" );
    6767    const std::string& getVar(const std::string& entryName, const std::string& sectionName, const std::string& defaultValue = "") const;
    68     bool IniParser::editVar(const std::string& entryName, const std::string& value, const std::string& sectionName = "");
     68    bool IniParser::editVar(const std::string& entryName, const std::string& value, const std::string& sectionName = "", bool createMissing = true);
    6969    void setEntryComment(const std::string& comment, const std::string& entryName, const std::string& sectionName);
    7070    const std::string& getEntryComment(const std::string& entryName, const std::string& sectionName) const;
  • branches/qt_gui/src/lib/util/preferences.cc

    r7627 r7629  
    1717
    1818#include "preferences.h"
    19 
    20 using namespace std;
     19#include "lib/parser/ini_parser/ini_parser.h"
    2120
    2221
     
    281280  //if ( didChanges )
    282281  {
     282    iniParser.debug();
    283283    iniParser.writeFile( this->fileName );
    284284  }
  • branches/qt_gui/src/lib/util/preferences.h

    r7627 r7629  
    99#include "base_object.h"
    1010#include "multi_type.h"
    11 #include "lib/parser/ini_parser/ini_parser.h"
    1211
    1312// FORWARD DECLARATION
Note: See TracChangeset for help on using the changeset viewer.