Changeset 6388 in orxonox.OLD for branches/preferences/src/lib/parser/ini_parser
- Timestamp:
- Jan 2, 2006, 11:09:42 PM (19 years ago)
- Location:
- branches/preferences/src/lib/parser/ini_parser
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/preferences/src/lib/parser/ini_parser/ini_parser.cc
r5953 r6388 431 431 } 432 432 433 /** 434 * @brief edits the entry speciefied by entryName in sectionName/currentSection or creates it if it doesn't exist 435 * @param entryName the Name of the Entry to add 436 * @param value the value to assign to this entry 437 * @param sectionName if NULL then this entry will be set to the currentSection 438 * otherwise to the section refered to by sectionName. 439 * If both are NULL no entry will be added 440 * @return true if everything is ok false on error 441 */ 442 bool IniParser::editVar(const char* entryName, const char* value, const char* sectionName) 443 { 444 std::list<IniSection>::iterator section; 445 446 if (sectionName != NULL) 447 { 448 for (section = this->sections.begin(); section != this->sections.end(); section++) 449 if (!strcmp((*section).name, sectionName)) 450 break; 451 } 452 else 453 section = this->currentSection; 454 455 if (section == this->sections.end()) 456 { 457 assert( sectionName != NULL ); 458 459 IniSection sec; 460 sec.comment = NULL; 461 sec.name = new char[strlen(sectionName)+1]; 462 strcpy(sec.name, sectionName); 463 section = this->sections.insert(this->sections.end(), sec); 464 } 465 466 if (section == this->sections.end()) 467 { 468 PRINTF(2)("section '%s' not found for value '%s'\n", sectionName, entryName); 469 return false; 470 } 471 else 472 { 473 //try find item 474 std::list<IniEntry>::iterator entry; 475 for (entry = section->entries.begin(); entry!=section->entries.end(); entry++) 476 if (!strcmp( entry->name, entryName )) 477 break; 478 479 //found it? 480 if ( entry != section->entries.end() ) 481 { 482 if ( entry->value != NULL ) 483 { 484 delete[] entry->value; 485 } 486 entry->value = new char[strlen(value)+1]; 487 strcpy(entry->value, value); 488 489 return true; 490 } 491 492 //not found -> create it 493 (*section).entries.push_back(IniEntry()); 494 (*section).entries.back().comment = NULL; 495 (*section).entries.back().name = new char[strlen(entryName)+1]; 496 strcpy((*section).entries.back().name, entryName); 497 (*section).entries.back().value = new char[strlen(value)+1]; 498 strcpy((*section).entries.back().value, value); 499 PRINTF(5)("Added Entry %s with Value '%s' to Section %s\n", 500 (*section).entries.back().name, 501 (*section).entries.back().value, 502 (*section).name); 503 this->currentEntry = --(*section).entries.end(); 504 return true; 505 } 506 } 507 433 508 434 509 /** -
branches/preferences/src/lib/parser/ini_parser/ini_parser.h
r5952 r6388 67 67 68 68 bool addVar(const char* entryName, const char* value, const char* sectionName = NULL); 69 bool editVar(const char* entryName, const char* value, const char* sectionName = NULL); 69 70 const char* getVar(const char* entryName, const char* sectionName, const char* defaultValue = "") const; 70 71 void setEntryComment(const char* comment, const char* entryName, const char* sectionName);
Note: See TracChangeset
for help on using the changeset viewer.