Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 5952 in orxonox.OLD for trunk/src/lib/parser


Ignore:
Timestamp:
Dec 7, 2005, 1:41:10 AM (19 years ago)
Author:
bensch
Message:

orxonox/trunk: more functionality to the ini_parser

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

Legend:

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

    r5951 r5952  
    287287bool IniParser::addSection(const char* sectionName)
    288288{
     289  if (sectionName == NULL)
     290    return false;
    289291  this->sections.push_back(IniSection());
    290292  this->sections.back().comment = NULL;
     
    307309bool IniParser::getSection(const char* sectionName)
    308310{
    309   std::list<IniSection>::iterator section;
    310   for (section = this->sections.begin(); section != this->sections.end(); section++)
    311     if (!strcmp((*section).name, sectionName))
    312       {
    313         this->currentSection = section;
    314         this->currentEntry = (*this->currentSection).entries.begin();
    315         return true;
    316       }
    317   return false;
     311  this->currentSection = this->getSectionIT(sectionName);
     312  if (this->currentSection != this->sections.end())
     313  {
     314    this->currentEntry = (*this->currentSection).entries.begin();
     315    return true;
     316  }
     317  else
     318    return false;
    318319}
    319320
     
    323324void IniParser::setSectionComment(const char* comment, const char* sectionName)
    324325{
    325 
    326 
    327 }
    328 
    329 /**
    330  *
     326  std::list<IniSection>::iterator section = this->getSectionIT(sectionName);
     327  if (section == this->sections.end())
     328    return;
     329
     330  if ((*section).comment != NULL)
     331    delete[] (*section).comment;
     332  if (comment != NULL)
     333  {
     334    (*section).comment = new char[strlen (comment)+1];
     335    strcpy((*section).comment, comment);
     336  }
     337  else
     338    (*section).comment = NULL;
     339}
     340
     341/**
     342 * @param sectionName the Section to query for
     343 * @returns the Comment, or NULL on error.
    331344 */
    332345const char* IniParser::getSectionComment(const char* sectionName) const
    333346{
    334 
     347  std::list<IniSection>::const_iterator section = this->getSectionIT(sectionName);
     348  if (section != this->sections.end())
     349    return (*section).comment;
     350  else
     351    return NULL;
    335352}
    336353
     
    430447  if (this->fileName != NULL)
    431448  {
    432     std::list<IniSection>::const_iterator section = this->getSectionIT(sectionName);
    433 
    434   if (section == this->sections.end())
    435     {
    436       PRINTF(2)("Section %s that should be containing %s not found.\n", sectionName, entryName);
    437       return (defaultValue);
    438     }
    439 
    440     std::list<IniEntry>::const_iterator entry;
    441     for (entry = (*section).entries.begin(); entry != (*section).entries.end(); entry++)
    442       if (!strcmp((*entry).name, entryName))
    443         return (*entry).value;
     449    std::list<IniEntry>::const_iterator entry = this->getEntryIT(entryName, sectionName);
     450    if (!strcmp((*entry).name, entryName))
     451      return (*entry).value;
    444452    PRINTF(2)("Entry '%s' in section '%s' not found.\n", entryName, sectionName);
    445453
    446454  }
    447455  else
    448     PRINTF(2)("%s not opened\n", fileName);
     456    PRINTF(2)("no File opened\n");
    449457
    450458  return defaultValue;
     
    454462/**
    455463 * Set the Comment of a specified Entry.
    456  */
    457 const char* IniParser::setEntryComment(const char* comment, const char* entryName, const char* sectionName)
    458 {
    459 
    460 
    461 }
    462 
    463 /**
    464  *
     464 * @param comment the Comment to set
     465 * @param entryName the Name of the Entry
     466 * @param sectionName the Name of the Section
     467 */
     468void IniParser::setEntryComment(const char* comment, const char* entryName, const char* sectionName)
     469{
     470  std::list<IniEntry>::iterator entry = this->getEntryIT(entryName, sectionName);
     471
     472  if ((*entry).comment != NULL)
     473    delete[] (*entry).comment;
     474  if (comment != NULL)
     475  {
     476    (*entry).comment = new char[strlen (comment)+1];
     477    strcpy((*entry).comment, comment);
     478  }
     479  else
     480    (*entry).comment = NULL;
     481
     482
     483}
     484
     485/**
     486 * @param entryName the Entry to query for
     487 * @param sectionName the Section to Query for
     488 * @returns the queried Comment.
    465489 */
    466490const char* IniParser::getEntryComment(const char* entryName, const char* sectionName) const
    467491{
    468 
    469 
     492  std::list<IniEntry>::const_iterator entry = this->getEntryIT(entryName, sectionName);
     493
     494  return (*entry).comment;
    470495}
    471496
     
    550575{
    551576  std::list<IniSection>::const_iterator section = this->currentSection;
    552   if (sectionName != NULL)
     577  if (sectionName == NULL)
     578    return this->currentSection;
     579  else
    553580    for (section = this->sections.begin(); section != this->sections.end(); section++)
    554581      if (!strcmp((*section).name, sectionName))
     
    565592{
    566593  std::list<IniSection>::iterator section = this->currentSection;
    567   if (sectionName != NULL)
     594  if (sectionName == NULL)
     595    return this->currentSection;
     596  else
    568597    for (section = this->sections.begin(); section != this->sections.end(); section++)
    569598      if (!strcmp((*section).name, sectionName))
  • trunk/src/lib/parser/ini_parser/ini_parser.h

    r5951 r5952  
    6868    bool addVar(const char* entryName, const char* value, const char* sectionName = NULL);
    6969    const char* getVar(const char* entryName, const char* sectionName, const char* defaultValue = "") const;
    70     const char* setEntryComment(const char* comment, const char* entryName, const char* sectionName);
     70    void setEntryComment(const char* comment, const char* entryName, const char* sectionName);
    7171    const char* getEntryComment(const char* entryName, const char* sectionName) const;
    7272
Note: See TracChangeset for help on using the changeset viewer.