Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 7203 in orxonox.OLD for branches/std/src/lib/parser/ini_parser


Ignore:
Timestamp:
Mar 9, 2006, 5:28:10 PM (19 years ago)
Author:
bensch
Message:

orxonox/trunk: compiles again, BUT well…. i do not expect it to run anymore

Location:
branches/std/src/lib/parser/ini_parser
Files:
2 edited

Legend:

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

    r5953 r7203  
    4040 * @param fileName: the path and name of the file to parse
    4141 */
    42 IniParser::IniParser (const char* fileName)
    43 {
    44   this->fileName = NULL;
    45   this->comment = NULL;
    46 
    47   if (fileName != NULL)
     42IniParser::IniParser (const std::string& fileName)
     43{
     44  this->fileName = "";
     45  this->comment = "";
     46
     47  if (!fileName.empty())
    4848    this->readFile(fileName);
    4949}
     
    5959}
    6060
     61const std::string IniParser::emptyString = "";
     62
    6163
    6264/**
     
    6870  while(!this->sections.empty())
    6971  {
    70      IniSection section = this->sections.front();
     72    IniSection section = this->sections.front();
    7173
    7274    // in all entries of the sections
     
    7577      // delete all strings of entries.
    7678      IniEntry entry = section.entries.front();
    77       delete[] entry.name;
    78       delete[] entry.value;
    79       delete[] entry.comment;
    8079      section.entries.pop_front();
    8180    }
    8281    // delete all Sections
    83     delete[] section.name;
    84     delete[] section.comment;
    8582    this->sections.pop_front();
    8683  }
     
    9592 * If fileName is NULL the new Name will be set to NULL too.
    9693 */
    97 void IniParser::setFileName(const char* fileName)
    98 {
    99   if (this->fileName != NULL)
    100     delete[] this->fileName;
    101   if  (this->comment != NULL)
    102     delete[] this->comment;
    103   this->comment = NULL;
    104 
    105   if (fileName != NULL)
    106   {
    107     this->fileName = new char[strlen(fileName)+1];
    108     strcpy(this->fileName, fileName);
    109   }
    110   else
    111     this->fileName = NULL;
     94void IniParser::setFileName(const std::string& fileName)
     95{
     96  this->comment = "";
     97
     98  if (!fileName.empty())
     99    this->fileName = fileName;
     100  else
     101    this->fileName = "";
    112102}
    113103
     
    121111 * and the new one will be opened.
    122112 */
    123 bool IniParser::readFile(const char* fileName)
     113bool IniParser::readFile(const std::string& fileName)
    124114{
    125115  FILE*    stream;           //< The stream we use to read the file.
    126116  int      lineCount = 0;    //< The Count of lines.
    127117
    128   if (this->fileName != NULL)
     118  if (!this->fileName.empty())
    129119    this->deleteSections();
    130   if( fileName == NULL)
    131     return false;
    132 
    133   if( (stream = fopen (fileName, "r")) == NULL)
    134   {
    135     PRINTF(1)("IniParser could not open %s\n", fileName);
     120  if( fileName.empty())
     121    return false;
     122
     123  if( (stream = fopen (fileName.c_str(), "r")) == NULL)
     124  {
     125    PRINTF(1)("IniParser could not open %s\n", fileName.c_str());
    136126    return false;
    137127  }
     
    191181          continue;
    192182        }
    193         if( ptr == lineBegin) {
     183        if( ptr == lineBegin)
     184        {
    194185          lineCount++;
    195186          continue;
     
    228219 * @return true on success false otherwise
    229220 */
    230 bool IniParser::writeFile(const char* fileName) const
     221bool IniParser::writeFile(const std::string& fileName) const
    231222{
    232223  FILE*    stream;           //!< The stream we use to read the file.
    233   if( fileName == NULL && (fileName = this->fileName) == NULL )
    234     return false;
    235 
    236   if( (stream = fopen (fileName, "w")) == NULL)
    237   {
    238     PRINTF(1)("IniParser could not open %s\n", fileName);
    239     return false;
    240   }
    241   else
    242   {
    243     if (this->comment != NULL)
    244       fprintf(stream, "%s\n\n", this->comment);
     224  if( fileName.empty())
     225    return false;
     226
     227  if( (stream = fopen (fileName.c_str(), "w")) == NULL)
     228  {
     229    PRINTF(1)("IniParser could not open %s\n", fileName.c_str());
     230    return false;
     231  }
     232  else
     233  {
     234    if (!this->comment.empty())
     235      fprintf(stream, "%s\n\n", this->comment.c_str());
    245236
    246237    std::list<IniSection>::const_iterator section;
    247238    for (section = this->sections.begin(); section != this->sections.end(); section++)
     239    {
     240      if (!(*section).comment.empty())
     241        fprintf(stream, "%s", (*section).comment.c_str());
     242      fprintf(stream, "\n [%s]\n", (*section).name.c_str());
     243
     244      std::list<IniEntry>::const_iterator entry;
     245      for (entry = (*section).entries.begin(); entry != (*section).entries.end(); entry++)
    248246      {
    249         if ((*section).comment != NULL)
    250           fprintf(stream, "%s", (*section).comment);
    251         fprintf(stream, "\n [%s]\n", (*section).name);
    252 
    253         std::list<IniEntry>::const_iterator entry;
    254         for (entry = (*section).entries.begin(); entry != (*section).entries.end(); entry++)
    255         {
    256           if ((*entry).comment != NULL)
    257             fprintf(stream, "%s", (*entry).comment);
    258           fprintf(stream, "   %s = %s\n", (*entry).name, (*entry).value);
    259          }
     247        if (!(*entry).comment.empty())
     248          fprintf(stream, "%s", (*entry).comment.c_str());
     249        fprintf(stream, "   %s = %s\n", (*entry).name.c_str(), (*entry).value.c_str());
    260250      }
     251    }
    261252  }
    262253  fclose(stream);
    263254}
    264255
    265 void IniParser::setFileComment(const char* fileComment)
    266 {
    267   if (this->comment != NULL)
    268     delete this->comment;
    269 
    270   if (fileComment != NULL)
    271   {
    272     this->comment = new char[strlen(fileComment)+1];
    273     strcpy(this->comment, fileComment);
    274   }
    275   else
    276     this->comment = NULL;
    277 }
    278 
     256void IniParser::setFileComment(const std::string& fileComment)
     257{
     258  this->comment = fileComment;
     259}
    279260
    280261/**
     
    284265 * @return true on success... there is only success or segfault :)
    285266 */
    286 bool IniParser::addSection(const char* sectionName)
    287 {
    288   if (sectionName == NULL)
     267bool IniParser::addSection(const std::string& sectionName)
     268{
     269  if (sectionName.empty())
    289270    return false;
    290271  this->sections.push_back(IniSection());
    291   this->sections.back().comment = NULL;
    292   this->sections.back().name = new char[strlen(sectionName)+1];
    293   strcpy(this->sections.back().name, sectionName);
     272  this->sections.back().comment = "";
     273  this->sections.back().name = sectionName;
    294274
    295275  this->currentSection = --this->sections.end();
    296276  if (!this->sections.empty())
    297       this->currentEntry = (*this->currentSection).entries.begin();
     277    this->currentEntry = (*this->currentSection).entries.begin();
    298278  PRINTF(5)("Added Section %s\n", sectionName);
    299279  return true;
     
    306286 * @return true on success or false if the section could not be found
    307287 */
    308 bool IniParser::getSection(const char* sectionName)
     288bool IniParser::getSection(const std::string& sectionName)
    309289{
    310290  this->currentSection = this->getSectionIT(sectionName);
     
    321301 *
    322302 */
    323 void IniParser::setSectionComment(const char* comment, const char* sectionName)
     303void IniParser::setSectionComment(const std::string& comment, const std::string& sectionName)
    324304{
    325305  std::list<IniSection>::iterator section = this->getSectionIT(sectionName);
     
    327307    return;
    328308
    329   if ((*section).comment != NULL)
    330     delete[] (*section).comment;
    331   if (comment != NULL)
    332   {
    333     (*section).comment = new char[strlen (comment)+1];
    334     strcpy((*section).comment, comment);
    335   }
    336   else
    337     (*section).comment = NULL;
     309  (*section).comment = comment;
    338310}
    339311
     
    342314 * @returns the Comment, or NULL on error.
    343315 */
    344 const char* IniParser::getSectionComment(const char* sectionName) const
     316const std::string& IniParser::getSectionComment(const std::string& sectionName) const
    345317{
    346318  std::list<IniSection>::const_iterator section = this->getSectionIT(sectionName);
     
    348320    return (*section).comment;
    349321  else
    350     return NULL;
     322    return IniParser::emptyString;
    351323}
    352324
     
    367339 * @returns the name of the section if found, NULL otherwise
    368340 */
    369 const char* IniParser::nextSection()
     341const std::string& IniParser::nextSection()
    370342{
    371343  if (this->currentSection == this->sections.end())
    372     return NULL;
     344    return IniParser::emptyString;
    373345
    374346  this->currentSection++;
    375347
    376348  if (this->currentSection != this->sections.end())
    377     {
    378       this->currentEntry = (*this->currentSection).entries.begin();
    379       return this->currentSection->name;
    380     }
    381   else
    382     return NULL;
     349  {
     350    this->currentEntry = (*this->currentSection).entries.begin();
     351    return this->currentSection->name;
     352  }
     353  else
     354    return IniParser::emptyString;
    383355}
    384356
     
    393365 * @return true if everything is ok false on error
    394366 */
    395 bool IniParser::addVar(const char* entryName, const char* value, const char* sectionName)
     367bool IniParser::addVar(const std::string& entryName, const std::string& value, const std::string& sectionName)
    396368{
    397369  std::list<IniSection>::iterator section;
    398370
    399   if (sectionName != NULL)
     371  if (!sectionName.empty())
    400372  {
    401373    for (section = this->sections.begin(); section != this->sections.end(); section++)
    402       if (!strcmp((*section).name, sectionName))
     374      if ((*section).name == sectionName)
    403375        break;
    404376  }
     
    411383  if (section == this->sections.end())
    412384  {
    413     PRINTF(2)("section '%s' not found for value '%s'\n", sectionName, entryName);
     385    PRINTF(2)("section '%s' not found for value '%s'\n", sectionName.c_str(), entryName.c_str());
    414386    return false;
    415387  }
     
    417389  {
    418390    (*section).entries.push_back(IniEntry());
    419     (*section).entries.back().comment = NULL;
    420     (*section).entries.back().name = new char[strlen(entryName)+1];
    421     strcpy((*section).entries.back().name, entryName);
    422     (*section).entries.back().value = new char[strlen(value)+1];
    423     strcpy((*section).entries.back().value, value);
     391    (*section).entries.back().comment = "";
     392    (*section).entries.back().name = entryName;
     393    (*section).entries.back().value = value;
    424394    PRINTF(5)("Added Entry %s with Value '%s' to Section %s\n",
    425               (*section).entries.back().name,
    426               (*section).entries.back().value,
    427               (*section).name);
     395              (*section).entries.back().name.c_str(),
     396              (*section).entries.back().value.c_str(),
     397              (*section).name.c_str());
    428398    this->currentEntry = --(*section).entries.end();
    429399    return true;
     
    442412 * lead to unwanted behaviour.
    443413*/
    444 const char* IniParser::getVar(const char* entryName, const char* sectionName, const char* defaultValue) const
    445 {
    446   if (this->fileName != NULL)
     414const std::string& IniParser::getVar(const std::string& entryName, const std::string& sectionName, const std::string& defaultValue) const
     415{
     416  if (!this->fileName.empty())
    447417  {
    448418    std::list<IniEntry>::const_iterator entry = this->getEntryIT(entryName, sectionName);
    449     if (entry != NULL &&  !strcmp((*entry).name, entryName))
     419    if (entry != NULL &&  (*entry).name == entryName)
    450420      return (*entry).value;
    451     PRINTF(2)("Entry '%s' in section '%s' not found.\n", entryName, sectionName);
     421    PRINTF(2)("Entry '%s' in section '%s' not found.\n", entryName.c_str(), sectionName.c_str());
    452422
    453423  }
     
    456426
    457427  return defaultValue;
    458 
    459428}
    460429
     
    465434 * @param sectionName the Name of the Section
    466435 */
    467 void IniParser::setEntryComment(const char* comment, const char* entryName, const char* sectionName)
     436void IniParser::setEntryComment(const std::string& comment, const std::string& entryName, const std::string& sectionName)
    468437{
    469438  std::list<IniEntry>::iterator entry = this->getEntryIT(entryName, sectionName);
    470 
    471   if ((*entry).comment != NULL)
    472     delete[] (*entry).comment;
    473   if (comment != NULL)
    474   {
    475     (*entry).comment = new char[strlen (comment)+1];
    476     strcpy((*entry).comment, comment);
    477   }
    478   else
    479     (*entry).comment = NULL;
    480 
    481 
     439  (*entry).comment = comment;
    482440}
    483441
     
    487445 * @returns the queried Comment.
    488446 */
    489 const char* IniParser::getEntryComment(const char* entryName, const char* sectionName) const
     447const std::string& IniParser::getEntryComment(const std::string& entryName, const std::string& sectionName) const
    490448{
    491449  std::list<IniEntry>::const_iterator entry = this->getEntryIT(entryName, sectionName);
     
    501459{
    502460  if (!this->sections.empty() &&
    503        this->currentSection != this->sections.end())
     461      this->currentSection != this->sections.end())
    504462    this->currentEntry = (*this->currentSection).entries.begin();
    505463}
     
    530488 * @returns the name of the Current selected Section
    531489 */
    532 const char* IniParser::getCurrentSection() const
     490const std::string& IniParser::getCurrentSection() const
    533491{
    534492  if (!this->sections.empty() &&
     
    536494    return this->currentSection->name;
    537495  else
    538     return NULL;
    539  }
     496    return IniParser::emptyString ;
     497}
    540498
    541499
     
    543501 * @returns the current entries Name, or NULL if we havn't selected a Entry
    544502 */
    545 const char* IniParser::getCurrentName() const
    546 {
    547  if (!this->sections.empty() &&
    548      this->currentSection != this->sections.end() &&
    549      this->currentEntry != (*this->currentSection).entries.end())
    550    return (*this->currentEntry).name;
    551  else
    552    return NULL;
     503const std::string& IniParser::getCurrentName() const
     504{
     505  if (!this->sections.empty() &&
     506      this->currentSection != this->sections.end() &&
     507      this->currentEntry != (*this->currentSection).entries.end())
     508    return (*this->currentEntry).name;
     509  else
     510    return emptyString;
    553511}
    554512
     
    556514 * @returns the current entries Value, or NULL if we havn't selected a Entry
    557515 */
    558 const char* IniParser::getCurrentValue() const
     516const std::string& IniParser::getCurrentValue() const
    559517{
    560518  if (!this->sections.empty() &&
     
    563521    return (*this->currentEntry).value;
    564522  else
    565     return NULL;
     523    return IniParser::emptyString;
    566524}
    567525
     
    571529 * @param sectionName the Name of the Section to get the Iterator from
    572530 */
    573 std::list<IniParser::IniSection>::const_iterator IniParser::getSectionIT(const char* sectionName) const
     531std::list<IniParser::IniSection>::const_iterator IniParser::getSectionIT(const std::string& sectionName) const
    574532{
    575533  std::list<IniSection>::const_iterator section = this->currentSection;
    576   if (sectionName == NULL)
     534  if (sectionName.empty())
    577535    return this->currentSection;
    578536  else
    579537    for (section = this->sections.begin(); section != this->sections.end(); section++)
    580       if (!strcmp((*section).name, sectionName))
     538      if ((*section).name == sectionName)
    581539        break;
    582540  return section;
     
    588546 * @param sectionName the Name of the Section to get the Iterator from
    589547 */
    590 std::list<IniParser::IniSection>::iterator IniParser::getSectionIT(const char* sectionName)
     548std::list<IniParser::IniSection>::iterator IniParser::getSectionIT(const std::string& sectionName)
    591549{
    592550  std::list<IniSection>::iterator section = this->currentSection;
    593   if (sectionName == NULL)
     551  if (sectionName.empty())
    594552    return this->currentSection;
    595553  else
    596554    for (section = this->sections.begin(); section != this->sections.end(); section++)
    597       if (!strcmp((*section).name, sectionName))
     555      if ((*section).name == sectionName)
    598556        break;
    599557  return section;
     
    606564 * @param sectionName the Name of the Section to get the Iterator from
    607565 */
    608 std::list<IniParser::IniEntry>::const_iterator IniParser::getEntryIT(const char* entryName, const char* sectionName) const
    609 {
    610   if (entryName == NULL)
     566std::list<IniParser::IniEntry>::const_iterator IniParser::getEntryIT(const std::string& entryName, const std::string& sectionName) const
     567{
     568  if (entryName.empty())
    611569    return this->currentEntry;
    612570  std::list<IniSection>::const_iterator section = this->getSectionIT(sectionName);
     
    615573  if (section != this->sections.end())
    616574    for (entry = (*section).entries.begin(); entry != (*section).entries.end(); entry++)
    617       if (!strcmp((*entry).name, entryName))
     575      if ((*entry).name == entryName)
    618576        break;
    619577  if (entry == (*section).entries.end())
     
    629587 * @param sectionName the Name of the Section to get the Iterator from
    630588 */
    631 std::list<IniParser::IniEntry>::iterator IniParser::getEntryIT(const char* entryName, const char* sectionName)
    632 {
    633   if (entryName == NULL)
     589std::list<IniParser::IniEntry>::iterator IniParser::getEntryIT(const std::string& entryName, const std::string& sectionName)
     590{
     591  if (entryName.empty())
    634592    return this->currentEntry;
    635593  std::list<IniSection>::iterator section = this->getSectionIT(sectionName);
     
    638596  if (section != this->sections.end())
    639597    for (entry = (*section).entries.begin(); entry != (*section).entries.end(); entry++)
    640       if (!strcmp((*entry).name, entryName))
     598      if ((*entry).name == entryName)
    641599        break;
    642600  if (entry == (*section).entries.end())
     
    652610void IniParser::setFileComment()
    653611{
    654   if (this->comment != NULL)
    655     delete[] this->comment;
    656 
    657   if (this->commentList.empty()) {
    658     this->comment = NULL;
     612  if (this->commentList.empty())
     613  {
     614    this->comment = "";
    659615    return;
    660616  }
    661617
    662   unsigned int stringLength = 1;
    663618  std::list<char*>::iterator comment;
    664   for (comment = this->commentList.begin(); comment != this->commentList.end(); comment++)
    665     stringLength += strlen((*comment)) +1;
    666 
    667   this->comment = new char[stringLength];
    668   this->comment[0] = '\0';
     619
    669620  while (!this->commentList.empty())
    670621  {
    671     if (*this->comment != '\0')
    672       strcat(this->comment, "\n");
    673     strcat(this->comment, this->commentList.front());
    674     delete[] this->commentList.front();
     622    if (this->comment[0] != '\0')
     623      this->comment += "\n";
     624    this->comment += this->commentList.front();
    675625    this->commentList.pop_front();
    676626  }
     
    682632void IniParser::setSectionComment()
    683633{
    684   if ((*this->currentSection).comment != NULL)
    685     delete[] (*this->currentSection).comment;
    686 
    687   if (this->commentList.empty()) {
    688     (*this->currentSection).comment = NULL;
     634  (*this->currentSection).comment = "";
     635
     636  if (this->commentList.empty())
    689637    return;
    690   }
    691 
    692   unsigned int stringLength = 1;
    693   std::list<char*>::iterator comment;
    694   for (comment = this->commentList.begin(); comment != this->commentList.end(); comment++)
    695     stringLength += strlen((*comment)) +1;
    696 
    697   (*this->currentSection).comment = new char[stringLength];
    698   (*this->currentSection).comment[0] = '\0';
     638
    699639  while (!this->commentList.empty())
    700640  {
    701     if (*(*this->currentSection).comment != '\0')
    702       strcat((*this->currentSection).comment, "\n");
    703     strcat((*this->currentSection).comment, this->commentList.front());
    704     delete[] this->commentList.front();
     641    if ((*this->currentSection).comment[0] != '\0')
     642      (*this->currentSection).comment += "\n";
     643    (*this->currentSection).comment += this->commentList.front();
    705644    this->commentList.pop_front();
    706645  }
     
    712651void IniParser::setEntryComment()
    713652{
    714   if ((*this->currentEntry).comment != NULL)
    715     delete[] (*this->currentEntry).comment;
    716 
    717   if (this->commentList.empty()) {
    718     (*this->currentEntry).comment = NULL;
     653  (*this->currentEntry).comment = "";
     654  if (this->commentList.empty())
    719655    return;
    720   }
    721 
    722   unsigned int stringLength = 1;
    723   std::list<char*>::iterator comment;
    724   for (comment = this->commentList.begin(); comment != this->commentList.end(); comment++)
    725     stringLength += strlen((*comment)) +1;
    726 
    727   (*this->currentEntry).comment = new char[stringLength];
    728   (*this->currentEntry).comment[0] = '\0';
     656
    729657  while (!this->commentList.empty())
    730658  {
    731     if (*(*this->currentEntry).comment != '\0')
    732       strcat((*this->currentEntry).comment, "\n");
    733     strcat((*this->currentEntry).comment, this->commentList.front());
    734     delete[] this->commentList.front();
     659    if ((*this->currentEntry).comment[0] != '\0')
     660      (*this->currentEntry).comment += "\n";
     661    (*this->currentEntry).comment += this->commentList.front();
    735662    this->commentList.pop_front();
    736663  }
    737 
    738664}
    739665
     
    744670void IniParser::debug() const
    745671{
    746   PRINTF(0)("Iniparser %s - debug\n", this->fileName);
    747   if (this->comment != NULL)
    748     PRINTF(0)("FileComment:\n %s\n\n", this->comment);
    749 
    750   if (this->fileName != NULL)
     672  PRINTF(0)("Iniparser %s - debug\n", this->fileName.c_str());
     673  if (!this->comment.empty())
     674    PRINTF(0)("FileComment:\n %s\n\n", this->comment.c_str());
     675
     676  if (!this->fileName.empty())
    751677  {
    752678    std::list<IniSection>::const_iterator section;
    753679    for (section = this->sections.begin(); section != this->sections.end(); section++)
    754680    {
    755       if ((*section).comment != NULL)
    756         PRINTF(0)(" %s\n", (*section).comment);
    757       PRINTF(0)(" [%s]\n", (*section).name);
     681      if (!(*section).comment.empty())
     682        PRINTF(0)(" %s\n", (*section).comment.c_str());
     683      PRINTF(0)(" [%s]\n", (*section).name.c_str());
    758684
    759685      std::list<IniEntry>::const_iterator entry;
    760686      for (entry = (*section).entries.begin(); entry != (*section).entries.end(); entry++)
    761687      {
    762         if ((*entry).comment != NULL)
    763           PRINTF(0)(" %s\n", (*entry).comment);
    764         PRINTF(0)("   '%s' -> '%s'\n", (*entry).name, (*entry).value);
     688        if (!(*entry).comment.empty())
     689          PRINTF(0)(" %s\n", (*entry).comment.c_str());
     690        PRINTF(0)("   '%s' -> '%s'\n", (*entry).name.c_str(), (*entry).value.c_str());
    765691      }
    766692    }
  • branches/std/src/lib/parser/ini_parser/ini_parser.h

    r6981 r7203  
    1515
    1616#include <list>
     17#include <string>
    1718
    1819//! ini-file parser
     
    2728    struct IniEntry
    2829    {
    29       char*               comment;  //!< A Comment that is appendet to the Top of this Entry.
    30       char*               name;     //!< name of a given Entry
    31       char*               value;    //!< value of a given Entry
     30      std::string         comment;  //!< A Comment that is appendet to the Top of this Entry.
     31      std::string         name;     //!< name of a given Entry
     32      std::string         value;    //!< value of a given Entry
    3233    };
    3334
     
    3536    struct IniSection
    3637    {
    37       char*               comment;  //!< A Comment that is appendet to the Top of this Section.
    38       char*               name;     //!< name of a given section
     38      std::string         comment;  //!< A Comment that is appendet to the Top of this Section.
     39      std::string         name;     //!< name of a given section
    3940      std::list<IniEntry> entries;  //!< a list of entries for this section
    4041    };
     
    4243
    4344  public:
    44     IniParser (const char* filename = NULL);
     45    IniParser (const std::string& filename = "");
    4546    virtual ~IniParser ();
    4647
    4748    /** @returns true if the file is opened, false otherwise*/
    48     bool isOpen() const { return (this->fileName != NULL)? true : false; };
     49    bool isOpen() const { return (!this->fileName.empty())? true : false; };
    4950    /** @returns the fileName we have opened. */
    50     const char* getFileName() const { return this->fileName; };
     51    const std::string& getFileName() const { return this->fileName; };
    5152
    52     bool readFile(const char* fileName);
    53     bool writeFile(const char* fileName) const;
     53    bool readFile(const std::string& fileName);
     54    bool writeFile(const std::string& fileName) const;
    5455
    55     void setFileComment(const char* fileComment);
    56     const char* getFileComment() const { return this->comment; };
     56    void setFileComment(const std::string& fileComment);
     57    const std::string& getFileComment() const { return this->comment; };
    5758
    58     bool addSection(const char* sectionName);
    59     bool getSection(const char* sectionName);
    60     void setSectionComment(const char* comment, const char* sectionName);
    61     const char* getSectionComment(const char* sectionNane) const;
     59    bool addSection(const std::string& sectionName);
     60    bool getSection(const std::string& sectionName);
     61    void setSectionComment(const std::string& comment, const std::string& sectionName);
     62    const std::string& getSectionComment(const std::string& sectionNane) const;
    6263
    6364    // iterate through sections with these Functions
    6465    void firstSection();
    65     const char* nextSection();
     66    const std::string& nextSection();
    6667
    6768
    68     bool addVar(const char* entryName, const char* value, const char* sectionName = NULL);
    69     const char* getVar(const char* entryName, const char* sectionName, const char* defaultValue = "") const;
    70     void setEntryComment(const char* comment, const char* entryName, const char* sectionName);
    71     const char* getEntryComment(const char* entryName, const char* sectionName) const;
     69    bool addVar(const std::string& entryName, const std::string& value, const std::string& sectionName = NULL);
     70    const std::string& getVar(const std::string& entryName, const std::string& sectionName, const std::string& defaultValue = "") const;
     71    void setEntryComment(const std::string& comment, const std::string& entryName, const std::string& sectionName);
     72    const std::string& getEntryComment(const std::string& entryName, const std::string& sectionName) const;
    7273
    7374    // iterate Through Variables with these Functions.
     
    7778
    7879    // retrieving functions when iterating.
    79     const char* getCurrentSection() const;
    80     const char* getCurrentName() const;
    81     const char* getCurrentValue() const;
     80    const std::string& getCurrentSection() const;
     81    const std::string& getCurrentName() const;
     82    const std::string& getCurrentValue() const;
    8283
    8384
     
    8889  private:
    8990    void deleteSections();
    90     void setFileName(const char* fileName);
     91    void setFileName(const std::string& fileName);
    9192
    9293    void setFileComment();
     
    9495    void setEntryComment();
    9596
    96     std::list<IniSection>::const_iterator getSectionIT(const char* sectionName) const;
    97     std::list<IniSection>::iterator getSectionIT(const char* sectionName);
     97    std::list<IniSection>::const_iterator getSectionIT(const std::string& sectionName) const;
     98    std::list<IniSection>::iterator getSectionIT(const std::string& sectionName);
    9899
    99     std::list<IniEntry>::const_iterator getEntryIT(const char* entryName, const char* sectionName = NULL) const;
    100     std::list<IniEntry>::iterator getEntryIT(const char* entryName, const char* sectionName = NULL);
     100    std::list<IniEntry>::const_iterator getEntryIT(const std::string& entryName, const std::string& sectionName = NULL) const;
     101    std::list<IniEntry>::iterator getEntryIT(const std::string& entryName, const std::string& sectionName = NULL);
    101102
    102103  private:
    103     char*                            fileName;        //!< The name of the File that was parsed.
    104     char*                            comment;         //!< A Comment for the header of this File.
     104    std::string                      fileName;        //!< The name of the File that was parsed.
     105    std::string                      comment;         //!< A Comment for the header of this File.
    105106    std::list<IniSection>            sections;        //!< a list of all stored Sections of the Parser
    106107    std::list<IniSection>::iterator  currentSection;  //!< the current selected Section
    107108    std::list<IniEntry>::iterator    currentEntry;    //!< the current selected entry (in currentSection)
    108109
    109     std::list<char*>                 commentList;     //!< A list of Comments. (this is for temporary saving of Comments, that are inserted in front of Sections/Entries.)
     110    std::list<std::string>           commentList;     //!< A list of Comments. (this is for temporary saving of Comments, that are inserted in front of Sections/Entries.)
     111
     112
     113    static const std::string         emptyString;
    110114};
    111115
Note: See TracChangeset for help on using the changeset viewer.