Changeset 7661 in orxonox.OLD for trunk/src/lib/parser/ini_parser
- Timestamp:
- May 18, 2006, 12:55:34 AM (19 years ago)
- Location:
- trunk/src/lib/parser/ini_parser
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/lib/parser/ini_parser/ini_parser.cc
r7256 r7661 108 108 if( (stream = fopen (fileName.c_str(), "r")) == NULL) 109 109 { 110 PRINTF(1)("IniParser could not open %s \n", fileName.c_str());110 PRINTF(1)("IniParser could not open %s for reading\n", fileName.c_str()); 111 111 return false; 112 112 } … … 216 216 if( (stream = fopen (fileName.c_str(), "w")) == NULL) 217 217 { 218 PRINTF(1)("IniParser could not open %s \n", fileName.c_str());218 PRINTF(1)("IniParser could not open %s for writing\n", fileName.c_str()); 219 219 return false; 220 220 } … … 401 401 * @return true if everything is ok false on error 402 402 */ 403 bool IniParser::editVar(const std::string& entryName, const std::string& value, const std::string& sectionName )403 bool IniParser::editVar(const std::string& entryName, const std::string& value, const std::string& sectionName, bool createMissing) 404 404 { 405 405 std::list<IniSection>::iterator section; … … 416 416 if (section == this->sections.end()) 417 417 { 418 IniSection sec; 419 sec.comment = ""; 420 sec.name = sectionName; 421 section = this->sections.insert(this->sections.end(), sec); 422 } 423 424 if (section == this->sections.end()) 425 { 426 PRINTF(2)("section '%s' not found for value '%s'\n", sectionName.c_str(), entryName.c_str()); 427 return false; 428 } 429 else 430 { 431 //try find item 432 std::list<IniEntry>::iterator entry; 433 for (entry = section->entries.begin(); entry!=section->entries.end(); entry++) 434 if (entry->name == entryName ) 418 this->addSection(sectionName); 419 for (section = this->sections.begin(); section != this->sections.end(); section++) 420 if ((*section).name == sectionName) 435 421 break; 436 437 //found it? 438 if ( entry != section->entries.end() ) 439 { 440 entry->value = value; 441 442 return true; 443 } 444 422 } 423 424 //try find item 425 std::list<IniEntry>::iterator entry; 426 for (entry = section->entries.begin(); entry!=section->entries.end(); entry++) 427 if (entry->name == entryName ) 428 break; 429 430 //found it? 431 if ( entry != section->entries.end() ) 432 { 433 entry->value = value; 434 435 return true; 436 } 437 else 438 { 445 439 //not found -> create it 446 440 (*section).entries.push_back(IniEntry()); … … 448 442 (*section).entries.back().name = entryName; 449 443 (*section).entries.back().value = value; 450 PRINTF(5)("Added Entry %s with Value '%s' to Section %s\n",451 (*section).entries.back().name.c_str(),452 (*section).entries.back().value.c_str(),453 (*section).name);444 PRINTF(5)("Added Entry '%s' with Value '%s' to Section '%s'\n", 445 (*section).entries.back().name.c_str(), 446 (*section).entries.back().value.c_str(), 447 (*section).name); 454 448 this->currentEntry = --(*section).entries.end(); 455 449 return true; 456 450 } 451 return false; 457 452 } 458 453 … … 725 720 void IniParser::debug() const 726 721 { 727 PRINT F(0)("Iniparser %s- debug\n", this->fileName.c_str());722 PRINT(0)("Iniparser '%s' - debug\n", this->fileName.c_str()); 728 723 if (!this->comment.empty()) 729 PRINT F(0)("FileComment:\n %s\n\n", this->comment.c_str());724 PRINT(0)("FileComment:\n '%s'\n\n", this->comment.c_str()); 730 725 731 726 if (!this->fileName.empty()) 732 727 { 728 if (sections.empty()) 729 PRINT(0)("No Sections defined\n"); 733 730 std::list<IniSection>::const_iterator section; 734 731 for (section = this->sections.begin(); section != this->sections.end(); section++) … … 737 734 PRINTF(0)(" %s\n", (*section).comment.c_str()); 738 735 PRINTF(0)(" [%s]\n", (*section).name.c_str()); 736 737 if ((*section).entries.empty()) 738 PRINT(0)("No Entries defined within Section '%s'\n", (*section).name.c_str()); 739 739 740 740 std::list<IniEntry>::const_iterator entry; … … 748 748 } 749 749 else 750 PRINTF( 1)("no opened ini-file.\n");751 } 752 750 PRINTF(0)("no opened ini-file.\n"); 751 } 752 -
trunk/src/lib/parser/ini_parser/ini_parser.h
r7256 r7661 10 10 11 11 #define PARSELINELENGHT 512 //!< how many chars to read at once 12 #ifndef NULL13 #define NULL 0x0 //!< NULL14 #endif15 12 13 #include "src/lib/util/file.h" 16 14 #include <list> 17 #include <string>18 15 19 16 //! ini-file parser … … 21 18 * This class can be used to load an initializer file and parse it's contents for variablename=value pairs. 22 19 */ 23 class IniParser 20 class IniParser : public File 24 21 { 25 22 private: … … 47 44 48 45 /** @returns true if the file is opened, false otherwise*/ 49 bool isOpen() const { return (!this->fileName.empty())? true : false; };46 bool isOpen() const { return true; } ///HACK //(this->fileName.empty()) ? false : true; }; 50 47 /** @returns the fileName we have opened. */ 51 48 const std::string& getFileName() const { return this->fileName; }; … … 69 66 bool addVar(const std::string& entryName, const std::string& value, const std::string& sectionName = "" ); 70 67 const std::string& getVar(const std::string& entryName, const std::string& sectionName, const std::string& defaultValue = "") const; 71 bool IniParser::editVar(const std::string& entryName, const std::string& value, const std::string& sectionName = "" );68 bool IniParser::editVar(const std::string& entryName, const std::string& value, const std::string& sectionName = "", bool createMissing = true); 72 69 void setEntryComment(const std::string& comment, const std::string& entryName, const std::string& sectionName); 73 70 const std::string& getEntryComment(const std::string& entryName, const std::string& sectionName) const;
Note: See TracChangeset
for help on using the changeset viewer.