Changeset 5952 in orxonox.OLD for trunk/src/lib/parser
- Timestamp:
- Dec 7, 2005, 1:41:10 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
r5951 r5952 287 287 bool IniParser::addSection(const char* sectionName) 288 288 { 289 if (sectionName == NULL) 290 return false; 289 291 this->sections.push_back(IniSection()); 290 292 this->sections.back().comment = NULL; … … 307 309 bool IniParser::getSection(const char* sectionName) 308 310 { 309 std::list<IniSection>::iterator section; 310 for (section = this->sections.begin(); section != this->sections.end(); section++) 311 if (!strcmp((*section).name, sectionName)) 312 { 313 this->currentSection = section; 314 this->currentEntry = (*this->currentSection).entries.begin(); 315 return true; 316 } 317 return false; 311 this->currentSection = this->getSectionIT(sectionName); 312 if (this->currentSection != this->sections.end()) 313 { 314 this->currentEntry = (*this->currentSection).entries.begin(); 315 return true; 316 } 317 else 318 return false; 318 319 } 319 320 … … 323 324 void IniParser::setSectionComment(const char* comment, const char* sectionName) 324 325 { 325 326 327 } 328 329 /** 330 * 326 std::list<IniSection>::iterator section = this->getSectionIT(sectionName); 327 if (section == this->sections.end()) 328 return; 329 330 if ((*section).comment != NULL) 331 delete[] (*section).comment; 332 if (comment != NULL) 333 { 334 (*section).comment = new char[strlen (comment)+1]; 335 strcpy((*section).comment, comment); 336 } 337 else 338 (*section).comment = NULL; 339 } 340 341 /** 342 * @param sectionName the Section to query for 343 * @returns the Comment, or NULL on error. 331 344 */ 332 345 const char* IniParser::getSectionComment(const char* sectionName) const 333 346 { 334 347 std::list<IniSection>::const_iterator section = this->getSectionIT(sectionName); 348 if (section != this->sections.end()) 349 return (*section).comment; 350 else 351 return NULL; 335 352 } 336 353 … … 430 447 if (this->fileName != NULL) 431 448 { 432 std::list<IniSection>::const_iterator section = this->getSectionIT(sectionName); 433 434 if (section == this->sections.end()) 435 { 436 PRINTF(2)("Section %s that should be containing %s not found.\n", sectionName, entryName); 437 return (defaultValue); 438 } 439 440 std::list<IniEntry>::const_iterator entry; 441 for (entry = (*section).entries.begin(); entry != (*section).entries.end(); entry++) 442 if (!strcmp((*entry).name, entryName)) 443 return (*entry).value; 449 std::list<IniEntry>::const_iterator entry = this->getEntryIT(entryName, sectionName); 450 if (!strcmp((*entry).name, entryName)) 451 return (*entry).value; 444 452 PRINTF(2)("Entry '%s' in section '%s' not found.\n", entryName, sectionName); 445 453 446 454 } 447 455 else 448 PRINTF(2)(" %s not opened\n", fileName);456 PRINTF(2)("no File opened\n"); 449 457 450 458 return defaultValue; … … 454 462 /** 455 463 * Set the Comment of a specified Entry. 456 */ 457 const char* IniParser::setEntryComment(const char* comment, const char* entryName, const char* sectionName) 458 { 459 460 461 } 462 463 /** 464 * 464 * @param comment the Comment to set 465 * @param entryName the Name of the Entry 466 * @param sectionName the Name of the Section 467 */ 468 void IniParser::setEntryComment(const char* comment, const char* entryName, const char* sectionName) 469 { 470 std::list<IniEntry>::iterator entry = this->getEntryIT(entryName, sectionName); 471 472 if ((*entry).comment != NULL) 473 delete[] (*entry).comment; 474 if (comment != NULL) 475 { 476 (*entry).comment = new char[strlen (comment)+1]; 477 strcpy((*entry).comment, comment); 478 } 479 else 480 (*entry).comment = NULL; 481 482 483 } 484 485 /** 486 * @param entryName the Entry to query for 487 * @param sectionName the Section to Query for 488 * @returns the queried Comment. 465 489 */ 466 490 const char* IniParser::getEntryComment(const char* entryName, const char* sectionName) const 467 491 { 468 469 492 std::list<IniEntry>::const_iterator entry = this->getEntryIT(entryName, sectionName); 493 494 return (*entry).comment; 470 495 } 471 496 … … 550 575 { 551 576 std::list<IniSection>::const_iterator section = this->currentSection; 552 if (sectionName != NULL) 577 if (sectionName == NULL) 578 return this->currentSection; 579 else 553 580 for (section = this->sections.begin(); section != this->sections.end(); section++) 554 581 if (!strcmp((*section).name, sectionName)) … … 565 592 { 566 593 std::list<IniSection>::iterator section = this->currentSection; 567 if (sectionName != NULL) 594 if (sectionName == NULL) 595 return this->currentSection; 596 else 568 597 for (section = this->sections.begin(); section != this->sections.end(); section++) 569 598 if (!strcmp((*section).name, sectionName)) -
trunk/src/lib/parser/ini_parser/ini_parser.h
r5951 r5952 68 68 bool addVar(const char* entryName, const char* value, const char* sectionName = NULL); 69 69 const char* getVar(const char* entryName, const char* sectionName, const char* defaultValue = "") const; 70 const char*setEntryComment(const char* comment, const char* entryName, const char* sectionName);70 void setEntryComment(const char* comment, const char* entryName, const char* sectionName); 71 71 const char* getEntryComment(const char* entryName, const char* sectionName) const; 72 72
Note: See TracChangeset
for help on using the changeset viewer.