Changeset 5945 in orxonox.OLD for trunk/src/lib/parser/ini_parser/ini_parser.cc
- Timestamp:
- Dec 6, 2005, 11:39:05 PM (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/lib/parser/ini_parser/ini_parser.cc
r5944 r5945 43 43 { 44 44 this->fileName = NULL; 45 45 this->comment = NULL; 46 46 47 47 if (fileName != NULL) … … 117 117 { 118 118 FILE* stream; //< The stream we use to read the file. 119 int lineCount = 0; //< The Count of lines. 120 119 121 120 122 if (this->fileName != NULL) … … 142 144 while( fgets (lineBuffer, PARSELINELENGHT, stream)) 143 145 { 146 // if (lineCount == 0) 147 144 148 lineBegin = lineBuffer; 145 149 // remove newline char, and \0-terminate … … 183 187 184 188 this->addVar(lineBegin, valueBegin); 189 190 lineCount++; 185 191 } 186 192 } … … 203 209 { 204 210 FILE* stream; //!< The stream we use to read the file. 205 if( fileName == NULL )211 if( fileName == NULL && (fileName = this->fileName) == NULL ) 206 212 return false; 207 213 … … 224 230 } 225 231 fclose(stream); 232 } 233 234 void IniParser::setFileComment(const char* fileComment) 235 { 236 226 237 } 227 238 … … 267 278 268 279 280 void IniParser::setSectionComment(const char* comment, const char* sectionName) 281 { 282 283 } 284 285 286 const char* IniParser::getSectionComment(const char* sectionName) const 287 { 288 289 } 290 291 269 292 /** 270 293 * @brief moves to the first section … … 296 319 else 297 320 return NULL; 298 }299 300 301 /**302 * @brief moves to the first Variable of the current Section303 */304 void IniParser::firstVar()305 {306 if (!this->sections.empty() &&307 this->currentSection != this->sections.end())308 this->currentEntry = (*this->currentSection).entries.begin();309 }310 311 312 /**313 * @brief gets the next VarName = VarValue pair from the parsing stream314 * @return true on success, false otherwise (in the latter case name and value will be NULL)315 */316 bool IniParser::nextVar()317 {318 if ( this->sections.empty()319 || this->currentSection == this->sections.end()320 || this->currentEntry == (*this->currentSection).entries.end())321 return false;322 323 this->currentEntry++;324 325 if (this->currentEntry == (*this->currentSection).entries.end())326 return false;327 else328 return true;329 321 } 330 322 … … 351 343 else 352 344 section = this->currentSection; 345 353 346 if (section == this->sections.end()) 354 347 return false; … … 367 360 strcpy((*section).entries.back().value, value); 368 361 PRINTF(5)("Added Entry %s with Value '%s' to Section %s\n", 369 370 371 362 (*section).entries.back().name, 363 (*section).entries.back().value, 364 (*section).name); 372 365 return true; 373 366 } … … 387 380 const char* IniParser::getVar(const char* entryName, const char* sectionName, const char* defaultValue) const 388 381 { 389 if (fileName != NULL) 390 { 391 std::list<IniSection>::const_iterator section; 392 if (sectionName != NULL) 393 { 394 for (section = this->sections.begin(); section != this->sections.end(); section++) 395 { 396 if (!strcmp((*section).name, sectionName)) 397 { 398 break; 399 } 400 } 401 } 402 else 403 section = this->currentSection; 404 405 if (section == this->sections.end()) 406 { 407 PRINTF(2)("Section %s that should be containing %s not found.\n", sectionName, entryName); 408 return (defaultValue); 409 } 382 if (this->fileName != NULL) 383 { 384 std::list<IniSection>::const_iterator section = this->getSectionIT(sectionName); 385 386 if (section == this->sections.end()) 387 { 388 PRINTF(2)("Section %s that should be containing %s not found.\n", sectionName, entryName); 389 return (defaultValue); 390 } 410 391 411 392 std::list<IniEntry>::const_iterator entry; 412 393 for (entry = (*section).entries.begin(); entry != (*section).entries.end(); entry++) 413 394 if (!strcmp((*entry).name, entryName)) 414 395 return (*entry).value; 415 396 PRINTF(2)("Entry '%s' in section '%s' not found.\n", entryName, sectionName); 416 397 … … 422 403 423 404 } 405 406 407 const char* IniParser::setEntryComment(const char* comment, const char* entryName, const char* sectionName) 408 { 409 410 411 } 412 413 414 const char* IniParser::getEntryComment(const char* entryName, const char* sectionName) const 415 { 416 417 418 } 419 420 421 /** 422 * @brief moves to the first Variable of the current Section 423 */ 424 void IniParser::firstVar() 425 { 426 if (!this->sections.empty() && 427 this->currentSection != this->sections.end()) 428 this->currentEntry = (*this->currentSection).entries.begin(); 429 } 430 431 432 /** 433 * @brief gets the next VarName = VarValue pair from the parsing stream 434 * @return true on success, false otherwise (in the latter case name and value will be NULL) 435 */ 436 bool IniParser::nextVar() 437 { 438 if ( this->sections.empty() 439 || this->currentSection == this->sections.end() 440 || this->currentEntry == (*this->currentSection).entries.end()) 441 return false; 442 443 this->currentEntry++; 444 445 if (this->currentEntry == (*this->currentSection).entries.end()) 446 return false; 447 else 448 return true; 449 } 450 424 451 425 452 … … 464 491 465 492 493 std::list<IniParser::IniSection>::const_iterator IniParser::getSectionIT(const char* sectionName) const 494 { 495 std::list<IniSection>::const_iterator section; 496 if (sectionName != NULL) 497 { 498 for (section = this->sections.begin(); section != this->sections.end(); section++) 499 { 500 if (!strcmp((*section).name, sectionName)) 501 { 502 break; 503 } 504 } 505 } 506 else 507 section = this->currentSection; 508 509 return section; 510 } 511 512 513 std::list<IniParser::IniEntry>::const_iterator IniParser::getEntryIT(const char* entryName, const char* sectionName) const 514 { 515 if (entryName == NULL) 516 return this->currentEntry; 517 518 } 519 520 521 466 522 /** 467 523 * @brief output the whole tree in a nice and easy way.
Note: See TracChangeset
for help on using the changeset viewer.