Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 5031 in orxonox.OLD for orxonox/trunk/src/lib/util


Ignore:
Timestamp:
Aug 15, 2005, 9:39:51 PM (19 years ago)
Author:
bensch
Message:

orxonox/trunk: made the IniParser more standAlone
also fixed all remaing SubProjects, so they compile again

Location:
orxonox/trunk/src/lib/util
Files:
2 edited

Legend:

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

    r5022 r5031  
    2222
    2323#include "list.h"
    24 #include "stdlibincl.h"
     24#include <stdlib.h>
     25#include <string.h>
    2526#include "debug.h"
    2627
     
    3334IniParser::IniParser (const char* fileName)
    3435{
    35   this->setClassID(CL_INI_PARSER, "IniParser");
    36 
    3736  this->currentEntry = NULL;
    3837  this->currentSection = NULL;
    3938  this->sections = NULL;
     39  this->fileName = NULL;
    4040  if (fileName != NULL)
    4141    this->readFile(fileName);
     
    8383  this->currentSection = NULL;
    8484  this->sections = NULL;
    85   this->setName(NULL);
     85  this->setFileName(NULL);
    8686}
    8787
     
    9898  if( fileName == NULL)
    9999    return false;
    100   this->setName(fileName);
     100  this->setFileName(fileName);
    101101
    102102  if( (stream = fopen (fileName, "r")) == NULL)
     
    234234  this->currentSection = newSection;
    235235  this->sections->add(newSection);
    236   PRINTF(0)("Added Section %s\n", sectionName);
     236  PRINTF(5)("Added Section %s\n", sectionName);
    237237  return true;
    238238}
     
    375375    strcpy(newEntry->value, value);
    376376    this->currentSection->entries->add(newEntry);
     377    PRINTF(5)("Added Entry %s with Value '%s' to Section %s\n", newEntry->name, newEntry->name, addSection->name);
    377378    return true;
    378379  }
     
    421422  }
    422423  else
    423     PRINTF(1)("%s not opened\n", this->getName());
     424    PRINTF(1)("%s not opened\n", fileName);
    424425
    425426  return defaultValue;
     
    427428}
    428429
     430
     431void IniParser::setFileName(const char* fileName)
     432{
     433  if (this->fileName)
     434    delete []this->fileName;
     435  if (fileName)
     436  {
     437    this->fileName = new char[strlen(fileName)+1];
     438    strcpy(this->fileName, fileName);
     439  }
     440  else
     441    this->fileName = NULL;
     442}
     443
     444
    429445/**
    430446 * output the whole tree in a nice and easy way.
     
    432448void IniParser::debug() const
    433449{
    434   PRINTF(0)("Iniparser %s - debug\n", this->getName());
     450  PRINTF(0)("Iniparser %s - debug\n", this->fileName);
    435451  if (this->sections)
    436452  {
     
    456472  }
    457473  else
    458     PRINTF(1)("%s not opened\n", this->getName());
    459 }
     474    PRINTF(1)("%s not opened\n", fileName);
     475}
  • orxonox/trunk/src/lib/util/ini_parser.h

    r5020 r5031  
    1010
    1111#define PARSELINELENGHT     512       //!< how many chars to read at once
    12 
    13 #include "base_object.h"
     12#ifndef NULL
     13#define NULL 0x0                      //!< NULL
     14#endif
    1415
    1516// FORWARD DEFINITION //
     
    2021 * This class can be used to load an initializer file and parse it's contents for variablename=value pairs.
    2122 */
    22 class IniParser : public BaseObject
     23class IniParser
    2324{
    2425  private:
     
    5354    /** @returns true if the file is opened, false otherwise*/
    5455    bool isOpen() const { return (sections != NULL)?true:false; };
     56    /** @returns the fileName we have opened. */
     57    const char* getFileName() const { return this->fileName; };
    5558
    5659    bool addVar(const char* entryName, const char* value, const char* sectionName = NULL);
     
    7174  private:
    7275    void deleteSections();
     76    void setFileName(const char* fileName);
    7377
    7478  private:
     79    char*                 fileName;        //!< The name of the File that was parsed.
    7580    tList<IniSection>*    sections;        //!< a list of all stored Sections of the Parser
    7681    IniSection*           currentSection;  //!< the current selected Section
Note: See TracChangeset for help on using the changeset viewer.