Changeset 5936 in orxonox.OLD for trunk/src/lib/util
- Timestamp:
- Dec 6, 2005, 2:12:18 AM (19 years ago)
- Location:
- trunk/src/lib/util
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/lib/util/ini_parser.cc
r5935 r5936 63 63 while(!this->sections.empty()) 64 64 { 65 66 IniSection section = this->sections.front(); 65 IniSection section = this->sections.front(); 67 66 68 67 // in all entries of the sections … … 79 78 this->sections.pop_front(); 80 79 } 80 this->currentSection = this->sections.end(); 81 81 this->setFileName(NULL); 82 82 } … … 196 196 * @return true on success false otherwise 197 197 */ 198 bool IniParser::writeFile(const char* fileName) 198 bool IniParser::writeFile(const char* fileName) const 199 199 { 200 200 FILE* stream; //!< The stream we use to read the file. … … 209 209 else 210 210 { 211 std::list<IniSection>:: iterator section;211 std::list<IniSection>::const_iterator section; 212 212 for (section = this->sections.begin(); section != this->sections.end(); section++) 213 213 { 214 214 fprintf(stream, "\n [%s]\n", (*section).name); 215 215 216 std::list<IniEntry>:: iterator entry;216 std::list<IniEntry>::const_iterator entry; 217 217 for (entry = (*section).entries.begin(); entry != (*section).entries.end(); entry++) 218 218 fprintf(stream, " %s = %s\n", (*entry).name, (*entry).value); … … 238 238 this->currentSection = --this->sections.end(); 239 239 if (!this->sections.empty()) 240 this->currentEntry = (*this->currentSection).entries.begin();240 this->currentEntry = (*this->currentSection).entries.begin(); 241 241 PRINTF(5)("Added Section %s\n", sectionName); 242 242 return true; … … 248 248 * @param sectionName: the name of the section to set the cursor to 249 249 * @return true on success or false if the section could not be found 250 */251 bool IniParser::getSection( 250 */ 251 bool IniParser::getSection(const char* sectionName) 252 252 { 253 253 std::list<IniSection>::iterator section; … … 259 259 return true; 260 260 } 261 262 261 return false; 263 262 } … … 267 266 * @brief moves to the first section 268 267 */ 269 void IniParser:: getFirstSection()268 void IniParser::firstSection() 270 269 { 271 270 this->currentSection = this->sections.begin(); … … 283 282 if (this->currentSection == this->sections.end()) 284 283 return NULL; 285 else 286 { 287 this->currentSection++; 288 } 289 if (this->currentSection == this->sections.end()) 290 return NULL; 284 285 this->currentSection++; 291 286 292 287 if (this->currentSection != this->sections.end()) … … 303 298 * @brief moves to the first Variable of the current Section 304 299 */ 305 void IniParser::getFirstVar() 306 { 307 if (this->currentSection != this->sections.end()) 300 void IniParser::firstVar() 301 { 302 if (!this->sections.empty() && 303 this->currentSection != this->sections.end()) 308 304 this->currentEntry = (*this->currentSection).entries.begin(); 309 305 } … … 342 338 { 343 339 std::list<IniSection>::iterator section; 344 340 345 341 if (sectionName != NULL) 346 342 { … … 351 347 else 352 348 section = this->currentSection; 349 if (section == this->sections.end()) 350 return false; 353 351 354 352 if (section == this->sections.end()) … … 364 362 (*section).entries.back().value = new char[strlen(value)+1]; 365 363 strcpy((*section).entries.back().value, value); 366 PRINTF(5)("Added Entry %s with Value '%s' to Section %s\n", entryName, value, (*section).name); 364 PRINTF(5)("Added Entry %s with Value '%s' to Section %s\n", 365 (*section).entries.back().name, 366 (*section).entries.back().value, 367 (*section).name); 367 368 return true; 368 369 } … … 387 388 if (sectionName != NULL) 388 389 { 389 390 390 for (section = this->sections.begin(); section != this->sections.end(); section++) 391 391 { … … 399 399 else 400 400 section = this->currentSection; 401 402 if (section == this->sections.end()) 403 return (defaultValue); 401 404 402 405 std::list<IniEntry>::const_iterator entry; … … 420 423 const char* IniParser::getCurrentSection() const 421 424 { 422 return (this->currentSection!=NULL) ? 423 this->currentSection->name : 424 NULL; 425 if (!this->sections.empty() && 426 this->currentSection != this->sections.end()) 427 return this->currentSection->name; 428 else 429 return NULL; 425 430 } 426 431 … … 432 437 { 433 438 if (!this->sections.empty() && 439 this->currentSection != this->sections.end() && 434 440 this->currentEntry != (*this->currentSection).entries.end()) 435 441 return (*this->currentEntry).name; … … 443 449 const char* IniParser::getCurrentValue() const 444 450 { 445 if (!this->sections.empty() 446 && this->currentEntry != (*this->currentSection).entries.end()) 451 if (!this->sections.empty() && 452 this->currentSection != this->sections.end() && 453 this->currentEntry != (*this->currentSection).entries.end()) 447 454 return (*this->currentEntry).value; 448 455 else -
trunk/src/lib/util/ini_parser.h
r5935 r5936 43 43 44 44 bool readFile(const char* fileName); 45 bool writeFile(const char* fileName) ;45 bool writeFile(const char* fileName) const; 46 46 47 47 bool addSection(const char* sectionName); … … 51 51 bool isOpen() const { return (this->fileName != NULL)? true : false; }; 52 52 53 void getFirstSection();53 void firstSection(); 54 54 const char* nextSection(); 55 55 … … 60 60 const char* getVar(const char* entryName, const char* sectionName, const char* defaultValue = "") const; 61 61 62 void getFirstVar();62 void firstVar(); 63 63 bool nextVar(); 64 64
Note: See TracChangeset
for help on using the changeset viewer.