Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Dec 6, 2005, 11:39:05 PM (18 years ago)
Author:
bensch
Message:

orxonox/trunk: small rearangements

File:
1 edited

Legend:

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

    r5944 r5945  
    4343{
    4444  this->fileName = NULL;
    45 
     45  this->comment = NULL;
    4646
    4747  if (fileName != NULL)
     
    117117{
    118118  FILE*    stream;           //< The stream we use to read the file.
     119  int      lineCount = 0;    //< The Count of lines.
     120
    119121
    120122  if (this->fileName != NULL)
     
    142144    while( fgets (lineBuffer, PARSELINELENGHT, stream))
    143145    {
     146//      if (lineCount == 0)
     147
    144148      lineBegin = lineBuffer;
    145149      // remove newline char, and \0-terminate
     
    183187
    184188        this->addVar(lineBegin, valueBegin);
     189
     190        lineCount++;
    185191      }
    186192    }
     
    203209{
    204210  FILE*    stream;           //!< The stream we use to read the file.
    205   if( fileName == NULL)
     211  if( fileName == NULL && (fileName = this->fileName) == NULL )
    206212    return false;
    207213
     
    224230  }
    225231  fclose(stream);
     232}
     233
     234void IniParser::setFileComment(const char* fileComment)
     235{
     236
    226237}
    227238
     
    267278
    268279
     280void IniParser::setSectionComment(const char* comment, const char* sectionName)
     281{
     282
     283}
     284
     285
     286const char* IniParser::getSectionComment(const char* sectionName) const
     287{
     288
     289}
     290
     291
    269292/**
    270293 * @brief moves to the first section
     
    296319  else
    297320    return NULL;
    298 }
    299 
    300 
    301 /**
    302  * @brief moves to the first Variable of the current Section
    303  */
    304 void IniParser::firstVar()
    305 {
    306   if (!this->sections.empty() &&
    307       this->currentSection != this->sections.end())
    308     this->currentEntry = (*this->currentSection).entries.begin();
    309 }
    310 
    311 
    312 /**
    313  * @brief gets the next VarName = VarValue pair from the parsing stream
    314  * @return true on success, false otherwise (in the latter case name and value will be NULL)
    315  */
    316 bool IniParser::nextVar()
    317 {
    318   if ( this->sections.empty()
    319        || this->currentSection == this->sections.end()
    320        || this->currentEntry == (*this->currentSection).entries.end())
    321     return false;
    322 
    323   this->currentEntry++;
    324 
    325   if (this->currentEntry == (*this->currentSection).entries.end())
    326     return false;
    327   else
    328     return true;
    329321}
    330322
     
    351343  else
    352344    section = this->currentSection;
     345
    353346  if (section == this->sections.end())
    354347    return false;
     
    367360    strcpy((*section).entries.back().value, value);
    368361    PRINTF(5)("Added Entry %s with Value '%s' to Section %s\n",
    369               (*section).entries.back().name,
    370               (*section).entries.back().value,
    371               (*section).name);
     362              (*section).entries.back().name,
     363              (*section).entries.back().value,
     364              (*section).name);
    372365    return true;
    373366  }
     
    387380const char* IniParser::getVar(const char* entryName, const char* sectionName, const char* defaultValue) const
    388381{
    389   if (fileName != NULL)
    390   {
    391     std::list<IniSection>::const_iterator section;
    392     if (sectionName != NULL)
    393       {
    394         for (section = this->sections.begin(); section != this->sections.end(); section++)
    395           {
    396             if (!strcmp((*section).name, sectionName))
    397               {
    398                 break;
    399               }
    400           }
    401       }
    402     else
    403       section = this->currentSection;
    404 
    405    if (section == this->sections.end())
    406      {
    407        PRINTF(2)("Section %s that should be containing %s not found.\n", sectionName, entryName);
    408        return (defaultValue);
    409      }
     382  if (this->fileName != NULL)
     383  {
     384    std::list<IniSection>::const_iterator section = this->getSectionIT(sectionName);
     385
     386  if (section == this->sections.end())
     387    {
     388      PRINTF(2)("Section %s that should be containing %s not found.\n", sectionName, entryName);
     389      return (defaultValue);
     390    }
    410391
    411392    std::list<IniEntry>::const_iterator entry;
    412393    for (entry = (*section).entries.begin(); entry != (*section).entries.end(); entry++)
    413394      if (!strcmp((*entry).name, entryName))
    414         return (*entry).value;
     395        return (*entry).value;
    415396    PRINTF(2)("Entry '%s' in section '%s' not found.\n", entryName, sectionName);
    416397
     
    422403
    423404}
     405
     406
     407const char* IniParser::setEntryComment(const char* comment, const char* entryName, const char* sectionName)
     408{
     409
     410
     411}
     412
     413
     414const char* IniParser::getEntryComment(const char* entryName, const char* sectionName) const
     415{
     416
     417
     418}
     419
     420
     421/**
     422 * @brief moves to the first Variable of the current Section
     423 */
     424void IniParser::firstVar()
     425{
     426  if (!this->sections.empty() &&
     427       this->currentSection != this->sections.end())
     428    this->currentEntry = (*this->currentSection).entries.begin();
     429}
     430
     431
     432/**
     433 * @brief gets the next VarName = VarValue pair from the parsing stream
     434 * @return true on success, false otherwise (in the latter case name and value will be NULL)
     435 */
     436bool IniParser::nextVar()
     437{
     438  if ( this->sections.empty()
     439       || this->currentSection == this->sections.end()
     440       || this->currentEntry == (*this->currentSection).entries.end())
     441    return false;
     442
     443  this->currentEntry++;
     444
     445  if (this->currentEntry == (*this->currentSection).entries.end())
     446    return false;
     447  else
     448    return true;
     449}
     450
    424451
    425452
     
    464491
    465492
     493std::list<IniParser::IniSection>::const_iterator IniParser::getSectionIT(const char* sectionName) const
     494{
     495  std::list<IniSection>::const_iterator section;
     496  if (sectionName != NULL)
     497  {
     498    for (section = this->sections.begin(); section != this->sections.end(); section++)
     499    {
     500      if (!strcmp((*section).name, sectionName))
     501      {
     502        break;
     503      }
     504    }
     505  }
     506  else
     507    section = this->currentSection;
     508
     509  return section;
     510}
     511
     512
     513std::list<IniParser::IniEntry>::const_iterator IniParser::getEntryIT(const char* entryName, const char* sectionName) const
     514{
     515  if (entryName == NULL)
     516    return this->currentEntry;
     517
     518}
     519
     520
     521
    466522/**
    467523 * @brief output the whole tree in a nice and easy way.
Note: See TracChangeset for help on using the changeset viewer.