Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 7661 in orxonox.OLD for trunk/src/lib/parser/ini_parser


Ignore:
Timestamp:
May 18, 2006, 12:55:34 AM (19 years ago)
Author:
bensch
Message:

orxonox/trunk: merged the QT_GUI back to the trunk
merged with command:
svn merge https://svn.orxonox.net/orxonox/branches/qt_gui . -r7607:HEAD

absolutely no conflicts :)

Location:
trunk/src/lib/parser/ini_parser
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/lib/parser/ini_parser/ini_parser.cc

    r7256 r7661  
    108108  if( (stream = fopen (fileName.c_str(), "r")) == NULL)
    109109  {
    110     PRINTF(1)("IniParser could not open %s\n", fileName.c_str());
     110    PRINTF(1)("IniParser could not open %s for reading\n", fileName.c_str());
    111111    return false;
    112112  }
     
    216216  if( (stream = fopen (fileName.c_str(), "w")) == NULL)
    217217  {
    218     PRINTF(1)("IniParser could not open %s\n", fileName.c_str());
     218    PRINTF(1)("IniParser could not open %s for writing\n", fileName.c_str());
    219219    return false;
    220220  }
     
    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
  • trunk/src/lib/parser/ini_parser/ini_parser.h

    r7256 r7661  
    1010
    1111#define PARSELINELENGHT     512       //!< how many chars to read at once
    12 #ifndef NULL
    13  #define NULL 0x0                     //!< NULL
    14 #endif
    1512
     13#include "src/lib/util/file.h"
    1614#include <list>
    17 #include <string>
    1815
    1916//! ini-file parser
     
    2118 * This class can be used to load an initializer file and parse it's contents for variablename=value pairs.
    2219 */
    23 class IniParser
     20class IniParser : public File
    2421{
    2522  private:
     
    4744
    4845    /** @returns true if the file is opened, false otherwise*/
    49     bool isOpen() const { return (!this->fileName.empty())? true : false; };
     46    bool isOpen() const { return true; } ///HACK //(this->fileName.empty()) ? false : true; };
    5047    /** @returns the fileName we have opened. */
    5148    const std::string& getFileName() const { return this->fileName; };
     
    6966    bool addVar(const std::string& entryName, const std::string& value, const std::string& sectionName = "" );
    7067    const std::string& getVar(const std::string& entryName, const std::string& sectionName, const std::string& defaultValue = "") const;
    71     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);
    7269    void setEntryComment(const std::string& comment, const std::string& entryName, const std::string& sectionName);
    7370    const std::string& getEntryComment(const std::string& entryName, const std::string& sectionName) const;
Note: See TracChangeset for help on using the changeset viewer.