Changeset 698
- Timestamp:
- Dec 27, 2007, 5:49:03 AM (17 years ago)
- Location:
- code/branches/FICN/src/orxonox/core
- Files:
-
- 6 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; -
code/branches/FICN/src/orxonox/core/ConfigValueContainer.h
r682 r698 86 86 ConfigValueContainer(const std::string& classname, const std::string& varname, Ogre::ColourValue defvalue); 87 87 88 static std::list<std::string>& getConfigFileLines(); 89 static bool finishedReadingConfigFile(bool finished = false); 88 90 void setConfigFileEntyToDefault(); 89 91 void searchConfigFileLine(); … … 143 145 144 146 std::list<std::string>::iterator configFileLine_; //!< An iterator, pointing to the entry of the variable in the config-file 145 static std::list<std::string>* configFileLines_s; //!< A list, containing all entrys in the config-file146 static bool readConfigFile_s; //!< True if the config-file is read and stored in the list147 147 148 148 enum VariableType -
code/branches/FICN/src/orxonox/core/Factory.cc
r682 r698 104 104 Factory* Factory::getFactoryPointer() 105 105 { 106 static Factory theOneAndOnly Instance = Factory();107 return &theOneAndOnly Instance;106 static Factory theOneAndOnlyFactoryInstance = Factory(); 107 return &theOneAndOnlyFactoryInstance; 108 108 } 109 109 } -
code/branches/FICN/src/orxonox/core/Identifier.cc
r696 r698 38 38 // ### Identifier ### 39 39 // ############################### 40 int Identifier::hierarchyCreatingCounter_s = 0; // Set the static member variable hierarchyCreatingCounter_s to zero 41 unsigned int Identifier::classIDcounter_s = 0; // Set the static member variable classIDcounter_s to zero 40 int Identifier::hierarchyCreatingCounter_s = 0; // Set the static member variable hierarchyCreatingCounter_s to zero (this static member variable is ok: it's used in main(), not before) 42 41 43 42 /** … … 50 49 51 50 this->children_ = new IdentifierList; 52 this->classID_ = Identifier::classIDcounter_s++; 51 52 // Use a static variable because the classID gets created before main() and that's why we should avoid static member variables 53 static unsigned int classIDcounter_s = 0; 54 this->classID_ = classIDcounter_s++; 53 55 } 54 56 -
code/branches/FICN/src/orxonox/core/Identifier.h
r696 r698 137 137 { this->configValues_[varname] = container; } 138 138 139 st d::map<std::string, Identifier*>& getIdentifierMap();139 static std::map<std::string, Identifier*>& getIdentifierMap(); 140 140 141 141 private: … … 171 171 bool bCreatedOneObject_; //!< True if at least one object of the given type was created (used to determine the need of storing the parents) 172 172 static int hierarchyCreatingCounter_s; //!< Bigger than zero if at least one Identifier stores its parents (its an int instead of a bool to avoid conflicts with multithreading) 173 static unsigned int classIDcounter_s; //!< The number of existing Identifiers174 173 unsigned int classID_; //!< The network ID to identify a class through the network 175 174 std::map<std::string, ConfigValueContainer*> configValues_; //!< A map to link the string of configurable variables with their ConfigValueContainer … … 197 196 private: 198 197 ClassIdentifier(); 199 ClassIdentifier(const ClassIdentifier<T>& identifier) {} // don't copy200 ~ClassIdentifier() ;198 ClassIdentifier(const ClassIdentifier<T>& identifier) {} // don't copy 199 ~ClassIdentifier() {} // don't delete 201 200 202 201 ObjectList<T>* objects_; //!< The ObjectList, containing all objects of type T … … 211 210 ClassIdentifier<T>::ClassIdentifier() 212 211 { 213 this->objects_ = new ObjectList<T>;212 this->objects_ = ObjectList<T>::getList(); 214 213 this->bSetName_ = false; 215 }216 217 /**218 @brief Destructor: Deletes the ObjectList, sets the singleton-pointer to zero.219 */220 template <class T>221 ClassIdentifier<T>::~ClassIdentifier()222 {223 delete this->objects_;224 214 } 225 215 -
code/branches/FICN/src/orxonox/core/ObjectList.h
r682 r698 82 82 { 83 83 public: 84 static ObjectList<T>* getList(); 85 86 ObjectListElement<T>* add(T* object); 87 // void remove(OrxonoxClass* object, bool bIterateForwards = true); 88 89 /** @returns the first element in the list */ 90 inline static Iterator<T> start() 91 { return Iterator<T>(getList()->first_); } 92 93 /** @returns the last element in the list */ 94 inline static Iterator<T> end() 95 { return Iterator<T>(getList()->last_); } 96 97 ObjectListElement<T>* first_; //!< The first element in the list 98 ObjectListElement<T>* last_; //!< The last element in the list 99 100 private: 84 101 ObjectList(); 85 102 ~ObjectList(); 86 ObjectListElement<T>* add(T* object);87 // void remove(OrxonoxClass* object, bool bIterateForwards = true);88 89 /** @returns the first element in the list */90 inline static Iterator<T> start()91 { return Iterator<T>(pointer_s->first_); }92 93 /** @returns the last element in the list */94 inline static Iterator<T> end()95 { return Iterator<T>(pointer_s->last_); }96 97 ObjectListElement<T>* first_; //!< The first element in the list98 ObjectListElement<T>* last_; //!< The last element in the list99 100 private:101 static ObjectList<T>* pointer_s; //!< A static pointer to the last created list (different for all T)102 103 }; 103 104 template <class T>105 ObjectList<T>* ObjectList<T>::pointer_s = 0; // Set the static member variable pointer_s to zero106 104 107 105 /** … … 113 111 this->first_ = 0; 114 112 this->last_ = 0; 115 116 // ObjectLists are only created by Identifiers and therefore only one ObjectList of each T will exist.117 // Thats why pointer_s is in fact a pointer to the only ObjectList for a type, which makes it almost a singleton.118 this->pointer_s = this;119 113 } 120 114 … … 132 126 this->first_ = temp; 133 127 } 128 } 129 130 /** 131 @returns a pointer to the only existing instance for the given class T. 132 */ 133 template <class T> 134 ObjectList<T>* ObjectList<T>::getList() 135 { 136 static ObjectList<T> theOnlyObjectListObjectForClassT = ObjectList<T>(); 137 return &theOnlyObjectListObjectForClassT; 134 138 } 135 139
Note: See TracChangeset
for help on using the changeset viewer.