- Timestamp:
- Dec 27, 2007, 5:49:03 AM (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/FICN/src/orxonox/core/ConfigValueContainer.cc
r682 r698 36 36 namespace orxonox 37 37 { 38 std::list<std::string>* ConfigValueContainer::configFileLines_s = 0; // Set the static member variable configFileLines_s to zero39 bool ConfigValueContainer::readConfigFile_s = false; // Set the static member variable readConfigFile_s to false40 41 38 /** 42 39 @brief Constructor: Converts the default-value to a string, checks the config-file for a changed value, sets the intern value variable. … … 438 435 { 439 436 // Read the file if needed 440 if (!ConfigValueContainer:: readConfigFile_s)437 if (!ConfigValueContainer::finishedReadingConfigFile()) 441 438 ConfigValueContainer::readConfigFile(CONFIGFILEPATH); 442 439 … … 450 447 bool success = false; 451 448 std::list<std::string>::iterator it1; 452 for(it1 = ConfigValueContainer:: configFileLines_s->begin(); it1 != ConfigValueContainer::configFileLines_s->end(); ++it1)449 for(it1 = ConfigValueContainer::getConfigFileLines().begin(); it1 != ConfigValueContainer::getConfigFileLines().end(); ++it1) 453 450 { 454 451 // Don't try to parse comments … … 464 461 // Iterate through all lines in the section 465 462 std::list<std::string>::iterator it2; 466 for(it2 = ++it1; it2 != ConfigValueContainer:: configFileLines_s->end(); ++it2)463 for(it2 = ++it1; it2 != ConfigValueContainer::getConfigFileLines().end(); ++it2) 467 464 { 468 465 // Don't try to parse comments … … 495 492 { 496 493 // The next section startet, so our line isn't yet in the file - now we add it and safe the file 497 this->configFileLine_ = this-> configFileLines_s->insert(positionToPutNewLineAt, this->varname_ + "=" + this->defvalueString_);494 this->configFileLine_ = this->getConfigFileLines().insert(positionToPutNewLineAt, this->varname_ + "=" + this->defvalueString_); 498 495 ConfigValueContainer::writeConfigFile(CONFIGFILEPATH); 499 496 success = true; … … 515 512 { 516 513 // Looks like we found the right section, but the file ended without containing our variable - so we add it and safe the file 517 this->configFileLine_ = this-> configFileLines_s->insert(positionToPutNewLineAt, this->varname_ + "=" + this->defvalueString_);514 this->configFileLine_ = this->getConfigFileLines().insert(positionToPutNewLineAt, this->varname_ + "=" + this->defvalueString_); 518 515 ConfigValueContainer::writeConfigFile(CONFIGFILEPATH); 519 516 success = true; … … 527 524 { 528 525 // We obviously didn't found the right section, so we'll create it 529 this-> configFileLines_s->push_back("[" + this->classname_ + "]"); // Create the section530 this-> configFileLines_s->push_back(this->varname_ + "=" + this->defvalueString_); // Create the line531 this->configFileLine_ = --this-> configFileLines_s->end(); // Set the pointer to the last element526 this->getConfigFileLines().push_back("[" + this->classname_ + "]"); // Create the section 527 this->getConfigFileLines().push_back(this->varname_ + "=" + this->defvalueString_); // Create the line 528 this->configFileLine_ = --this->getConfigFileLines().end(); // Set the pointer to the last element 532 529 success = true; 533 this-> configFileLines_s->push_back(""); // Add an empty line - this is needed for the algorithm in the searchConfigFileLine-function530 this->getConfigFileLines().push_back(""); // Add an empty line - this is needed for the algorithm in the searchConfigFileLine-function 534 531 ConfigValueContainer::writeConfigFile(CONFIGFILEPATH); // Save the changed config-file 535 532 } … … 601 598 602 599 /** 600 @returns a list, containing all entrys in the config-file. 601 */ 602 std::list<std::string>& ConfigValueContainer::getConfigFileLines() 603 { 604 // This is done to avoid problems while executing this code before main() 605 static std::list<std::string> configFileLinesStaticReference = std::list<std::string>(); 606 return configFileLinesStaticReference; 607 } 608 609 /** 610 @brief Returns true if the ConfigFile is read and stored into the ConfigFile-lines-list. 611 @param finished This is used to change the state 612 @return True if the ConfigFile is read and stored into the ConfigFile-lines-list 613 */ 614 bool ConfigValueContainer::finishedReadingConfigFile(bool finished) 615 { 616 // This is done to avoid problems while executing this code before main() 617 static bool finishedReadingConfigFileStaticVariable = false; 618 619 if (finished) 620 finishedReadingConfigFileStaticVariable = true; 621 622 return finishedReadingConfigFileStaticVariable; 623 } 624 625 /** 603 626 @brief Reads the config-file and stores the lines in a list. 604 627 @param filename The name of the config-file … … 606 629 void ConfigValueContainer::readConfigFile(const std::string& filename) 607 630 { 608 ConfigValueContainer::readConfigFile_s = true; 609 610 // Create the list if needed 611 if (!ConfigValueContainer::configFileLines_s) 612 ConfigValueContainer::configFileLines_s = new std::list<std::string>; 631 ConfigValueContainer::finishedReadingConfigFile(true); 613 632 614 633 // This creates the file if it's not existing … … 627 646 { 628 647 file.getline(line, 1024); 629 ConfigValueContainer:: configFileLines_s->push_back(line);648 ConfigValueContainer::getConfigFileLines().push_back(line); 630 649 // std::cout << "### ->" << line << "<- : empty: " << isEmpty(line) << " comment: " << isComment(line) << std::endl; 631 650 } 632 651 633 652 // The last line is useless 634 ConfigValueContainer:: configFileLines_s->pop_back();653 ConfigValueContainer::getConfigFileLines().pop_back(); 635 654 636 655 // Add an empty line to the end of the file if needed 637 656 // this is needed for the algorithm in the searchConfigFileLine-function 638 if ((ConfigValueContainer:: configFileLines_s->size() > 0) && !isEmpty(*ConfigValueContainer::configFileLines_s->rbegin()))657 if ((ConfigValueContainer::getConfigFileLines().size() > 0) && !isEmpty(*ConfigValueContainer::getConfigFileLines().rbegin())) 639 658 { 640 659 // std::cout << "### newline added" << std::endl; 641 ConfigValueContainer:: configFileLines_s->push_back("");660 ConfigValueContainer::getConfigFileLines().push_back(""); 642 661 } 643 662 … … 652 671 { 653 672 // Make sure we stored the config-file in the list 654 if (!ConfigValueContainer:: readConfigFile_s)673 if (!ConfigValueContainer::finishedReadingConfigFile()) 655 674 ConfigValueContainer::readConfigFile(filename); 656 675 … … 661 680 // Iterate through the list an write the lines into the file 662 681 std::list<std::string>::iterator it; 663 for(it = ConfigValueContainer:: configFileLines_s->begin(); it != ConfigValueContainer::configFileLines_s->end(); ++it)682 for(it = ConfigValueContainer::getConfigFileLines().begin(); it != ConfigValueContainer::getConfigFileLines().end(); ++it) 664 683 { 665 684 file << (*it) << std::endl;
Note: See TracChangeset
for help on using the changeset viewer.