Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 5015 in orxonox.OLD for orxonox/trunk/src/lib/util/ini_parser.cc


Ignore:
Timestamp:
Aug 14, 2005, 5:25:53 PM (19 years ago)
Author:
bensch
Message:

orxonox/trunk: robust IniParser

File:
1 edited

Legend:

Unmodified
Added
Removed
  • orxonox/trunk/src/lib/util/ini_parser.cc

    r5014 r5015  
    2323#include "list.h"
    2424#include "stdlibincl.h"
    25 
    26 #include "resource_manager.h"
    2725#include "debug.h"
    2826
     
    5351}
    5452
     53/**
     54 * removes all the sections. This is like delete, but even cooler :)
     55 */
    5556void IniParser::deleteSections()
    5657{
     
    8081  }
    8182  delete this->sections;
     83  this->currentEntry = NULL;
     84  this->currentSection = NULL;
    8285  this->sections = NULL;
    8386}
     
    8891 * @return true on success false otherwise;
    8992*/
    90 bool IniParser::openFile(const char* filename)
     93bool IniParser::openFile(const char* fileName)
    9194{
    9295  FILE*    stream;           //!< The stream we use to read the file.
    9396
    94 
    95   if( filename == NULL)
    96     return false;
    97   char* tmpName = ResourceManager::homeDirCheck(filename);
    9897
    9998  if (sections != NULL)
    10099    deleteSections();
    101 
    102   if( (stream = fopen (tmpName, "r")) == NULL)
    103   {
    104     PRINTF(1)("IniParser could not open %s\n", filename);
    105     delete tmpName;
     100  if( fileName == NULL)
     101    return false;
     102
     103  if( (stream = fopen (fileName, "r")) == NULL)
     104  {
     105    PRINTF(1)("IniParser could not open %s\n", fileName);
    106106    return false;
    107107  }
     
    189189    {
    190190      this->currentSection = sectionEnum;
     191      this->currentEntry = NULL;
    191192      delete sectionIt;
    192193      return true;
     
    200201
    201202/**
     203 * moves to the first section
     204 */
     205void IniParser::getFirstSection()
     206{
     207  if (this->sections)
     208    this->currentSection = this->sections->firstElement();
     209  else
     210    this->currentSection = NULL;
     211  this->currentEntry = NULL;
     212}
     213
     214/**
    202215 * searches the next section
    203216 * @returns the name of the section if found, NULL otherwise
     
    210223  {
    211224    if (this->sections)
    212       this->currentSection = sections->nextElement(this->currentSection);
    213   }
     225    {
     226      if (this->currentSection == this->sections->lastElement())
     227        this->currentSection = NULL;
     228      else
     229        this->currentSection = this->sections->nextElement(this->currentSection);
     230    }
     231  }
     232
    214233  if (this->currentSection != NULL)
    215234    return this->currentSection->name;
     
    219238
    220239/**
     240 * moves to the first Variable of the current Section
     241 */
     242void IniParser::getFirstVar()
     243{
     244  if (this->currentSection)
     245    this->currentEntry = this->currentSection->entries->firstElement();
     246  else
     247    this->currentEntry = NULL;
     248}
     249
     250/**
    221251 *  gets the next VarName=VarValue pair from the parsing stream
    222  * @param name: a pointer to the Name of the next Var
    223  * @param value: a pointer to the Value of the next Var
    224252 * @return true on success, false otherwise (in the latter case name and value will be NULL)
    225253 */
    226254bool IniParser::nextVar()
    227255{
    228   if (this->currentSection == NULL)
    229     return false;
    230   if(this->currentEntry == this->currentSection->entries->lastElement())
     256  if (this->currentSection == NULL
     257      || this->currentEntry == NULL
     258      || this->currentEntry == this->currentSection->entries->lastElement())
    231259  {
    232260    this->currentEntry = NULL;
    233261    return false;
    234262  }
    235   if (this->currentEntry == NULL)
    236     this->currentEntry = this->currentSection->entries->firstElement();
    237   else
    238     this->currentEntry = this->currentSection->entries->nextElement(this->currentEntry);
     263  this->currentEntry = this->currentSection->entries->nextElement(this->currentEntry);
    239264
    240265  if (this->currentEntry == NULL)
Note: See TracChangeset for help on using the changeset viewer.