Changeset 7256 in orxonox.OLD for trunk/src/lib/parser/ini_parser
- Timestamp:
- Mar 30, 2006, 11:45:31 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
r7221 r7256 392 392 } 393 393 394 /** 395 * @brief edits the entry speciefied by entryName in sectionName/currentSection or creates it if it doesn't exist 396 * @param entryName the Name of the Entry to add 397 * @param value the value to assign to this entry 398 * @param sectionName if NULL then this entry will be set to the currentSection 399 * otherwise to the section refered to by sectionName. 400 * If both are NULL no entry will be added 401 * @return true if everything is ok false on error 402 */ 403 bool IniParser::editVar(const std::string& entryName, const std::string& value, const std::string& sectionName) 404 { 405 std::list<IniSection>::iterator section; 406 407 if (!sectionName.empty()) 408 { 409 for (section = this->sections.begin(); section != this->sections.end(); section++) 410 if ((*section).name == sectionName) 411 break; 412 } 413 else 414 section = this->currentSection; 415 416 if (section == this->sections.end()) 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 ) 435 break; 436 437 //found it? 438 if ( entry != section->entries.end() ) 439 { 440 entry->value = value; 441 442 return true; 443 } 444 445 //not found -> create it 446 (*section).entries.push_back(IniEntry()); 447 (*section).entries.back().comment = ""; 448 (*section).entries.back().name = entryName; 449 (*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); 454 this->currentEntry = --(*section).entries.end(); 455 return true; 456 } 457 } 458 394 459 395 460 /** -
trunk/src/lib/parser/ini_parser/ini_parser.h
r7221 r7256 69 69 bool addVar(const std::string& entryName, const std::string& value, const std::string& sectionName = "" ); 70 70 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 = ""); 71 72 void setEntryComment(const std::string& comment, const std::string& entryName, const std::string& sectionName); 72 73 const std::string& getEntryComment(const std::string& entryName, const std::string& sectionName) const;
Note: See TracChangeset
for help on using the changeset viewer.