Index: trunk/src/lib/parser/ini_parser/ini_parser.cc
===================================================================
--- trunk/src/lib/parser/ini_parser/ini_parser.cc	(revision 5953)
+++ trunk/src/lib/parser/ini_parser/ini_parser.cc	(revision 7221)
@@ -40,10 +40,10 @@
  * @param fileName: the path and name of the file to parse
  */
-IniParser::IniParser (const char* fileName)
-{
-  this->fileName = NULL;
-  this->comment = NULL;
-
-  if (fileName != NULL)
+IniParser::IniParser (const std::string& fileName)
+{
+  this->fileName = "";
+  this->comment = "";
+
+  if (!fileName.empty())
     this->readFile(fileName);
 }
@@ -56,6 +56,8 @@
 {
   this->deleteSections();
-  this->setFileName(NULL);
-}
+  this->setFileName("");
+}
+
+const std::string IniParser::emptyString = "";
 
 
@@ -66,25 +68,8 @@
 {
   // in all sections
-  while(!this->sections.empty())
-  {
-     IniSection section = this->sections.front();
-
-    // in all entries of the sections
-    while(!section.entries.empty())
-    {
-      // delete all strings of entries.
-      IniEntry entry = section.entries.front();
-      delete[] entry.name;
-      delete[] entry.value;
-      delete[] entry.comment;
-      section.entries.pop_front();
-    }
-    // delete all Sections
-    delete[] section.name;
-    delete[] section.comment;
-    this->sections.pop_front();
-  }
+  this->sections.clear();
+
   this->currentSection = this->sections.end();
-  this->setFileName(NULL);
+  this->setFileName("");
 }
 
@@ -95,19 +80,8 @@
  * If fileName is NULL the new Name will be set to NULL too.
  */
-void IniParser::setFileName(const char* fileName)
-{
-  if (this->fileName != NULL)
-    delete[] this->fileName;
-  if  (this->comment != NULL)
-    delete[] this->comment;
-  this->comment = NULL;
-
-  if (fileName != NULL)
-  {
-    this->fileName = new char[strlen(fileName)+1];
-    strcpy(this->fileName, fileName);
-  }
-  else
-    this->fileName = NULL;
+void IniParser::setFileName(const std::string& fileName)
+{
+  this->comment = "";
+  this->fileName = fileName;
 }
 
@@ -121,17 +95,18 @@
  * and the new one will be opened.
  */
-bool IniParser::readFile(const char* fileName)
+bool IniParser::readFile(const std::string& fileName)
 {
   FILE*    stream;           //< The stream we use to read the file.
   int      lineCount = 0;    //< The Count of lines.
 
-  if (this->fileName != NULL)
+  if (!this->fileName.empty())
     this->deleteSections();
-  if( fileName == NULL)
-    return false;
-
-  if( (stream = fopen (fileName, "r")) == NULL)
-  {
-    PRINTF(1)("IniParser could not open %s\n", fileName);
+
+  if( fileName.empty())
+    return false;
+
+  if( (stream = fopen (fileName.c_str(), "r")) == NULL)
+  {
+    PRINTF(1)("IniParser could not open %s\n", fileName.c_str());
     return false;
   }
@@ -143,6 +118,6 @@
     // READING IN THE INI-FILE //
     /////////////////////////////
-    char lineBuffer[PARSELINELENGHT];
-    char buffer[PARSELINELENGHT];
+    char lineBuffer[PARSELINELENGHT+1];
+    char buffer[PARSELINELENGHT+1];
     const char* lineBegin;
     char* ptr;
@@ -154,13 +129,17 @@
       if( (ptr = strchr( lineBuffer, '\n')) != NULL)
         *ptr = 0;
+      else
+        lineBuffer[PARSELINELENGHT] = 0;
       // cut up to the beginning of the line.
       while((*lineBegin == ' ' || *lineBegin == '\t') && lineBegin < lineBuffer + strlen(lineBuffer))
         ++lineBegin;
 
+      if ( !strcmp( lineBegin, "" ) )
+        continue;
+
       // check if we have a FileComment
       if ( (*lineBegin == '#' || *lineBegin == ';'))
       {
-        char* newCommenLine = new char[strlen(lineBegin)+1];
-        strcpy(newCommenLine, lineBegin);
+        string newCommenLine = lineBegin;
         this->commentList.push_back(newCommenLine);
         continue;
@@ -191,5 +170,6 @@
           continue;
         }
-        if( ptr == lineBegin) {
+        if( ptr == lineBegin)
+        {
           lineCount++;
           continue;
@@ -228,53 +208,43 @@
  * @return true on success false otherwise
  */
-bool IniParser::writeFile(const char* fileName) const
+bool IniParser::writeFile(const std::string& fileName) const
 {
   FILE*    stream;           //!< The stream we use to read the file.
-  if( fileName == NULL && (fileName = this->fileName) == NULL )
-    return false;
-
-  if( (stream = fopen (fileName, "w")) == NULL)
-  {
-    PRINTF(1)("IniParser could not open %s\n", fileName);
-    return false;
-  }
-  else
-  {
-    if (this->comment != NULL)
-      fprintf(stream, "%s\n\n", this->comment);
+  if( fileName.empty())
+    return false;
+
+  if( (stream = fopen (fileName.c_str(), "w")) == NULL)
+  {
+    PRINTF(1)("IniParser could not open %s\n", fileName.c_str());
+    return false;
+  }
+  else
+  {
+    if (!this->comment.empty())
+      fprintf(stream, "%s\n\n", this->comment.c_str());
 
     std::list<IniSection>::const_iterator section;
     for (section = this->sections.begin(); section != this->sections.end(); section++)
+    {
+      if (!(*section).comment.empty())
+        fprintf(stream, "%s", (*section).comment.c_str());
+      fprintf(stream, "\n [%s]\n", (*section).name.c_str());
+
+      std::list<IniEntry>::const_iterator entry;
+      for (entry = (*section).entries.begin(); entry != (*section).entries.end(); entry++)
       {
-        if ((*section).comment != NULL)
-          fprintf(stream, "%s", (*section).comment);
-        fprintf(stream, "\n [%s]\n", (*section).name);
-
-        std::list<IniEntry>::const_iterator entry;
-        for (entry = (*section).entries.begin(); entry != (*section).entries.end(); entry++)
-        {
-          if ((*entry).comment != NULL)
-            fprintf(stream, "%s", (*entry).comment);
-          fprintf(stream, "   %s = %s\n", (*entry).name, (*entry).value);
-         }
+        if (!(*entry).comment.empty())
+          fprintf(stream, "%s", (*entry).comment.c_str());
+        fprintf(stream, "   %s = %s\n", (*entry).name.c_str(), (*entry).value.c_str());
       }
+    }
   }
   fclose(stream);
 }
 
-void IniParser::setFileComment(const char* fileComment)
-{
-  if (this->comment != NULL)
-    delete this->comment;
-
-  if (fileComment != NULL)
-  {
-    this->comment = new char[strlen(fileComment)+1];
-    strcpy(this->comment, fileComment);
-  }
-  else
-    this->comment = NULL;
-}
-
+void IniParser::setFileComment(const std::string& fileComment)
+{
+  this->comment = fileComment;
+}
 
 /**
@@ -284,17 +254,18 @@
  * @return true on success... there is only success or segfault :)
  */
-bool IniParser::addSection(const char* sectionName)
-{
-  if (sectionName == NULL)
-    return false;
-  this->sections.push_back(IniSection());
-  this->sections.back().comment = NULL;
-  this->sections.back().name = new char[strlen(sectionName)+1];
-  strcpy(this->sections.back().name, sectionName);
+bool IniParser::addSection(const std::string& sectionName)
+{
+  if (sectionName.empty())
+    return false;
+  IniSection newSection;
+  newSection.name = sectionName;
+  newSection.comment = "";
+
+  this->sections.push_back(newSection);
 
   this->currentSection = --this->sections.end();
   if (!this->sections.empty())
-      this->currentEntry = (*this->currentSection).entries.begin();
-  PRINTF(5)("Added Section %s\n", sectionName);
+    this->currentEntry = (*this->currentSection).entries.begin();
+  PRINTF(5)("Added Section %s\n", sectionName.c_str());
   return true;
 }
@@ -306,5 +277,5 @@
  * @return true on success or false if the section could not be found
  */
-bool IniParser::getSection(const char* sectionName)
+bool IniParser::getSection(const std::string& sectionName)
 {
   this->currentSection = this->getSectionIT(sectionName);
@@ -321,5 +292,5 @@
  *
  */
-void IniParser::setSectionComment(const char* comment, const char* sectionName)
+void IniParser::setSectionComment(const std::string& comment, const std::string& sectionName)
 {
   std::list<IniSection>::iterator section = this->getSectionIT(sectionName);
@@ -327,13 +298,5 @@
     return;
 
-  if ((*section).comment != NULL)
-    delete[] (*section).comment;
-  if (comment != NULL)
-  {
-    (*section).comment = new char[strlen (comment)+1];
-    strcpy((*section).comment, comment);
-  }
-  else
-    (*section).comment = NULL;
+  (*section).comment = comment;
 }
 
@@ -342,5 +305,5 @@
  * @returns the Comment, or NULL on error.
  */
-const char* IniParser::getSectionComment(const char* sectionName) const
+const std::string& IniParser::getSectionComment(const std::string& sectionName) const
 {
   std::list<IniSection>::const_iterator section = this->getSectionIT(sectionName);
@@ -348,5 +311,5 @@
     return (*section).comment;
   else
-    return NULL;
+    return IniParser::emptyString;
 }
 
@@ -367,18 +330,18 @@
  * @returns the name of the section if found, NULL otherwise
  */
-const char* IniParser::nextSection()
+const std::string& IniParser::nextSection()
 {
   if (this->currentSection == this->sections.end())
-    return NULL;
+    return IniParser::emptyString;
 
   this->currentSection++;
 
   if (this->currentSection != this->sections.end())
-    {
-      this->currentEntry = (*this->currentSection).entries.begin();
-      return this->currentSection->name;
-    }
-  else
-    return NULL;
+  {
+    this->currentEntry = (*this->currentSection).entries.begin();
+    return this->currentSection->name;
+  }
+  else
+    return IniParser::emptyString;
 }
 
@@ -393,12 +356,12 @@
  * @return true if everything is ok false on error
  */
-bool IniParser::addVar(const char* entryName, const char* value, const char* sectionName)
+bool IniParser::addVar(const std::string& entryName, const std::string& value, const std::string& sectionName)
 {
   std::list<IniSection>::iterator section;
 
-  if (sectionName != NULL)
+  if (!sectionName.empty())
   {
     for (section = this->sections.begin(); section != this->sections.end(); section++)
-      if (!strcmp((*section).name, sectionName))
+      if ((*section).name == sectionName)
         break;
   }
@@ -411,5 +374,5 @@
   if (section == this->sections.end())
   {
-    PRINTF(2)("section '%s' not found for value '%s'\n", sectionName, entryName);
+    PRINTF(2)("section '%s' not found for value '%s'\n", sectionName.c_str(), entryName.c_str());
     return false;
   }
@@ -417,13 +380,11 @@
   {
     (*section).entries.push_back(IniEntry());
-    (*section).entries.back().comment = NULL;
-    (*section).entries.back().name = new char[strlen(entryName)+1];
-    strcpy((*section).entries.back().name, entryName);
-    (*section).entries.back().value = new char[strlen(value)+1];
-    strcpy((*section).entries.back().value, value);
+    (*section).entries.back().comment = "";
+    (*section).entries.back().name = entryName;
+    (*section).entries.back().value = value;
     PRINTF(5)("Added Entry %s with Value '%s' to Section %s\n",
-              (*section).entries.back().name,
-              (*section).entries.back().value,
-              (*section).name);
+              (*section).entries.back().name.c_str(),
+              (*section).entries.back().value.c_str(),
+              (*section).name.c_str());
     this->currentEntry = --(*section).entries.end();
     return true;
@@ -442,13 +403,12 @@
  * lead to unwanted behaviour.
 */
-const char* IniParser::getVar(const char* entryName, const char* sectionName, const char* defaultValue) const
-{
-  if (this->fileName != NULL)
+const std::string& IniParser::getVar(const std::string& entryName, const std::string& sectionName, const std::string& defaultValue) const
+{
+  if (!this->fileName.empty())
   {
     std::list<IniEntry>::const_iterator entry = this->getEntryIT(entryName, sectionName);
-    if (entry != NULL &&  !strcmp((*entry).name, entryName))
+    if (entry != NULL &&  (*entry).name == entryName)
       return (*entry).value;
-    PRINTF(2)("Entry '%s' in section '%s' not found.\n", entryName, sectionName);
-
+    PRINTF(2)("Entry '%s' in section '%s' not found.\n", entryName.c_str(), sectionName.c_str());
   }
   else
@@ -456,5 +416,4 @@
 
   return defaultValue;
-
 }
 
@@ -465,19 +424,8 @@
  * @param sectionName the Name of the Section
  */
-void IniParser::setEntryComment(const char* comment, const char* entryName, const char* sectionName)
+void IniParser::setEntryComment(const std::string& comment, const std::string& entryName, const std::string& sectionName)
 {
   std::list<IniEntry>::iterator entry = this->getEntryIT(entryName, sectionName);
-
-  if ((*entry).comment != NULL)
-    delete[] (*entry).comment;
-  if (comment != NULL)
-  {
-    (*entry).comment = new char[strlen (comment)+1];
-    strcpy((*entry).comment, comment);
-  }
-  else
-    (*entry).comment = NULL;
-
-
+  (*entry).comment = comment;
 }
 
@@ -487,5 +435,5 @@
  * @returns the queried Comment.
  */
-const char* IniParser::getEntryComment(const char* entryName, const char* sectionName) const
+const std::string& IniParser::getEntryComment(const std::string& entryName, const std::string& sectionName) const
 {
   std::list<IniEntry>::const_iterator entry = this->getEntryIT(entryName, sectionName);
@@ -501,5 +449,5 @@
 {
   if (!this->sections.empty() &&
-       this->currentSection != this->sections.end())
+      this->currentSection != this->sections.end())
     this->currentEntry = (*this->currentSection).entries.begin();
 }
@@ -530,5 +478,5 @@
  * @returns the name of the Current selected Section
  */
-const char* IniParser::getCurrentSection() const
+const std::string& IniParser::getCurrentSection() const
 {
   if (!this->sections.empty() &&
@@ -536,6 +484,6 @@
     return this->currentSection->name;
   else
-    return NULL;
- }
+    return IniParser::emptyString ;
+}
 
 
@@ -543,12 +491,12 @@
  * @returns the current entries Name, or NULL if we havn't selected a Entry
  */
-const char* IniParser::getCurrentName() const
-{
- if (!this->sections.empty() &&
-     this->currentSection != this->sections.end() &&
-     this->currentEntry != (*this->currentSection).entries.end())
-   return (*this->currentEntry).name;
- else
-   return NULL;
+const std::string& IniParser::getCurrentName() const
+{
+  if (!this->sections.empty() &&
+      this->currentSection != this->sections.end() &&
+      this->currentEntry != (*this->currentSection).entries.end())
+    return (*this->currentEntry).name;
+  else
+    return emptyString;
 }
 
@@ -556,5 +504,5 @@
  * @returns the current entries Value, or NULL if we havn't selected a Entry
  */
-const char* IniParser::getCurrentValue() const
+const std::string& IniParser::getCurrentValue() const
 {
   if (!this->sections.empty() &&
@@ -563,5 +511,5 @@
     return (*this->currentEntry).value;
   else
-    return NULL;
+    return IniParser::emptyString;
 }
 
@@ -571,12 +519,12 @@
  * @param sectionName the Name of the Section to get the Iterator from
  */
-std::list<IniParser::IniSection>::const_iterator IniParser::getSectionIT(const char* sectionName) const
+std::list<IniParser::IniSection>::const_iterator IniParser::getSectionIT(const std::string& sectionName) const
 {
   std::list<IniSection>::const_iterator section = this->currentSection;
-  if (sectionName == NULL)
+  if (sectionName.empty())
     return this->currentSection;
   else
     for (section = this->sections.begin(); section != this->sections.end(); section++)
-      if (!strcmp((*section).name, sectionName))
+      if ((*section).name == sectionName)
         break;
   return section;
@@ -588,12 +536,12 @@
  * @param sectionName the Name of the Section to get the Iterator from
  */
-std::list<IniParser::IniSection>::iterator IniParser::getSectionIT(const char* sectionName)
+std::list<IniParser::IniSection>::iterator IniParser::getSectionIT(const std::string& sectionName)
 {
   std::list<IniSection>::iterator section = this->currentSection;
-  if (sectionName == NULL)
+  if (sectionName.empty())
     return this->currentSection;
   else
     for (section = this->sections.begin(); section != this->sections.end(); section++)
-      if (!strcmp((*section).name, sectionName))
+      if ((*section).name == sectionName)
         break;
   return section;
@@ -606,7 +554,7 @@
  * @param sectionName the Name of the Section to get the Iterator from
  */
-std::list<IniParser::IniEntry>::const_iterator IniParser::getEntryIT(const char* entryName, const char* sectionName) const
-{
-  if (entryName == NULL)
+std::list<IniParser::IniEntry>::const_iterator IniParser::getEntryIT(const std::string& entryName, const std::string& sectionName) const
+{
+  if (entryName.empty())
     return this->currentEntry;
   std::list<IniSection>::const_iterator section = this->getSectionIT(sectionName);
@@ -615,5 +563,5 @@
   if (section != this->sections.end())
     for (entry = (*section).entries.begin(); entry != (*section).entries.end(); entry++)
-      if (!strcmp((*entry).name, entryName))
+      if ((*entry).name == entryName)
         break;
   if (entry == (*section).entries.end())
@@ -629,7 +577,7 @@
  * @param sectionName the Name of the Section to get the Iterator from
  */
-std::list<IniParser::IniEntry>::iterator IniParser::getEntryIT(const char* entryName, const char* sectionName)
-{
-  if (entryName == NULL)
+std::list<IniParser::IniEntry>::iterator IniParser::getEntryIT(const std::string& entryName, const std::string& sectionName)
+{
+  if (entryName.empty())
     return this->currentEntry;
   std::list<IniSection>::iterator section = this->getSectionIT(sectionName);
@@ -638,5 +586,5 @@
   if (section != this->sections.end())
     for (entry = (*section).entries.begin(); entry != (*section).entries.end(); entry++)
-      if (!strcmp((*entry).name, entryName))
+      if ((*entry).name == entryName)
         break;
   if (entry == (*section).entries.end())
@@ -652,25 +600,17 @@
 void IniParser::setFileComment()
 {
-  if (this->comment != NULL)
-    delete[] this->comment;
-
-  if (this->commentList.empty()) {
-    this->comment = NULL;
+  if (this->commentList.empty())
+  {
+    this->comment = "";
     return;
   }
 
-  unsigned int stringLength = 1;
   std::list<char*>::iterator comment;
-  for (comment = this->commentList.begin(); comment != this->commentList.end(); comment++)
-    stringLength += strlen((*comment)) +1;
-
-  this->comment = new char[stringLength];
-  this->comment[0] = '\0';
+
   while (!this->commentList.empty())
   {
-    if (*this->comment != '\0')
-      strcat(this->comment, "\n");
-    strcat(this->comment, this->commentList.front());
-    delete[] this->commentList.front();
+    if (this->comment[0] != '\0')
+      this->comment += "\n";
+    this->comment += this->commentList.front();
     this->commentList.pop_front();
   }
@@ -682,25 +622,14 @@
 void IniParser::setSectionComment()
 {
-  if ((*this->currentSection).comment != NULL)
-    delete[] (*this->currentSection).comment;
-
-  if (this->commentList.empty()) {
-    (*this->currentSection).comment = NULL;
+  (*this->currentSection).comment = "";
+
+  if (this->commentList.empty())
     return;
-  }
-
-  unsigned int stringLength = 1;
-  std::list<char*>::iterator comment;
-  for (comment = this->commentList.begin(); comment != this->commentList.end(); comment++)
-    stringLength += strlen((*comment)) +1;
-
-  (*this->currentSection).comment = new char[stringLength];
-  (*this->currentSection).comment[0] = '\0';
+
   while (!this->commentList.empty())
   {
-    if (*(*this->currentSection).comment != '\0')
-      strcat((*this->currentSection).comment, "\n");
-    strcat((*this->currentSection).comment, this->commentList.front());
-    delete[] this->commentList.front();
+    if ((*this->currentSection).comment[0] != '\0')
+      (*this->currentSection).comment += "\n";
+    (*this->currentSection).comment += this->commentList.front();
     this->commentList.pop_front();
   }
@@ -712,28 +641,15 @@
 void IniParser::setEntryComment()
 {
-  if ((*this->currentEntry).comment != NULL)
-    delete[] (*this->currentEntry).comment;
-
-  if (this->commentList.empty()) {
-    (*this->currentEntry).comment = NULL;
+  (*this->currentEntry).comment = "";
+  if (this->commentList.empty())
     return;
-  }
-
-  unsigned int stringLength = 1;
-  std::list<char*>::iterator comment;
-  for (comment = this->commentList.begin(); comment != this->commentList.end(); comment++)
-    stringLength += strlen((*comment)) +1;
-
-  (*this->currentEntry).comment = new char[stringLength];
-  (*this->currentEntry).comment[0] = '\0';
+
   while (!this->commentList.empty())
   {
-    if (*(*this->currentEntry).comment != '\0')
-      strcat((*this->currentEntry).comment, "\n");
-    strcat((*this->currentEntry).comment, this->commentList.front());
-    delete[] this->commentList.front();
+    if ((*this->currentEntry).comment[0] != '\0')
+      (*this->currentEntry).comment += "\n";
+    (*this->currentEntry).comment += this->commentList.front();
     this->commentList.pop_front();
   }
-
 }
 
@@ -744,23 +660,23 @@
 void IniParser::debug() const
 {
-  PRINTF(0)("Iniparser %s - debug\n", this->fileName);
-  if (this->comment != NULL)
-    PRINTF(0)("FileComment:\n %s\n\n", this->comment);
-
-  if (this->fileName != NULL)
+  PRINTF(0)("Iniparser %s - debug\n", this->fileName.c_str());
+  if (!this->comment.empty())
+    PRINTF(0)("FileComment:\n %s\n\n", this->comment.c_str());
+
+  if (!this->fileName.empty())
   {
     std::list<IniSection>::const_iterator section;
     for (section = this->sections.begin(); section != this->sections.end(); section++)
     {
-      if ((*section).comment != NULL)
-        PRINTF(0)(" %s\n", (*section).comment);
-      PRINTF(0)(" [%s]\n", (*section).name);
+      if (!(*section).comment.empty())
+        PRINTF(0)(" %s\n", (*section).comment.c_str());
+      PRINTF(0)(" [%s]\n", (*section).name.c_str());
 
       std::list<IniEntry>::const_iterator entry;
       for (entry = (*section).entries.begin(); entry != (*section).entries.end(); entry++)
       {
-        if ((*entry).comment != NULL)
-          PRINTF(0)(" %s\n", (*entry).comment);
-        PRINTF(0)("   '%s' -> '%s'\n", (*entry).name, (*entry).value);
+        if (!(*entry).comment.empty())
+          PRINTF(0)(" %s\n", (*entry).comment.c_str());
+        PRINTF(0)("   '%s' -> '%s'\n", (*entry).name.c_str(), (*entry).value.c_str());
       }
     }
