Changeset 5031 in orxonox.OLD for orxonox/trunk/src/lib/util
- Timestamp:
- Aug 15, 2005, 9:39:51 PM (19 years ago)
- Location:
- orxonox/trunk/src/lib/util
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
orxonox/trunk/src/lib/util/ini_parser.cc
r5022 r5031 22 22 23 23 #include "list.h" 24 #include "stdlibincl.h" 24 #include <stdlib.h> 25 #include <string.h> 25 26 #include "debug.h" 26 27 … … 33 34 IniParser::IniParser (const char* fileName) 34 35 { 35 this->setClassID(CL_INI_PARSER, "IniParser");36 37 36 this->currentEntry = NULL; 38 37 this->currentSection = NULL; 39 38 this->sections = NULL; 39 this->fileName = NULL; 40 40 if (fileName != NULL) 41 41 this->readFile(fileName); … … 83 83 this->currentSection = NULL; 84 84 this->sections = NULL; 85 this->set Name(NULL);85 this->setFileName(NULL); 86 86 } 87 87 … … 98 98 if( fileName == NULL) 99 99 return false; 100 this->set Name(fileName);100 this->setFileName(fileName); 101 101 102 102 if( (stream = fopen (fileName, "r")) == NULL) … … 234 234 this->currentSection = newSection; 235 235 this->sections->add(newSection); 236 PRINTF( 0)("Added Section %s\n", sectionName);236 PRINTF(5)("Added Section %s\n", sectionName); 237 237 return true; 238 238 } … … 375 375 strcpy(newEntry->value, value); 376 376 this->currentSection->entries->add(newEntry); 377 PRINTF(5)("Added Entry %s with Value '%s' to Section %s\n", newEntry->name, newEntry->name, addSection->name); 377 378 return true; 378 379 } … … 421 422 } 422 423 else 423 PRINTF(1)("%s not opened\n", this->getName());424 PRINTF(1)("%s not opened\n", fileName); 424 425 425 426 return defaultValue; … … 427 428 } 428 429 430 431 void 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 429 445 /** 430 446 * output the whole tree in a nice and easy way. … … 432 448 void IniParser::debug() const 433 449 { 434 PRINTF(0)("Iniparser %s - debug\n", this-> getName());450 PRINTF(0)("Iniparser %s - debug\n", this->fileName); 435 451 if (this->sections) 436 452 { … … 456 472 } 457 473 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 10 10 11 11 #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 14 15 15 16 // FORWARD DEFINITION // … … 20 21 * This class can be used to load an initializer file and parse it's contents for variablename=value pairs. 21 22 */ 22 class IniParser : public BaseObject23 class IniParser 23 24 { 24 25 private: … … 53 54 /** @returns true if the file is opened, false otherwise*/ 54 55 bool isOpen() const { return (sections != NULL)?true:false; }; 56 /** @returns the fileName we have opened. */ 57 const char* getFileName() const { return this->fileName; }; 55 58 56 59 bool addVar(const char* entryName, const char* value, const char* sectionName = NULL); … … 71 74 private: 72 75 void deleteSections(); 76 void setFileName(const char* fileName); 73 77 74 78 private: 79 char* fileName; //!< The name of the File that was parsed. 75 80 tList<IniSection>* sections; //!< a list of all stored Sections of the Parser 76 81 IniSection* currentSection; //!< the current selected Section
Note: See TracChangeset
for help on using the changeset viewer.