Changeset 447 for code/branches/objecthierarchy/src
- Timestamp:
- Dec 9, 2007, 11:21:14 PM (17 years ago)
- Location:
- code/branches/objecthierarchy/src/orxonox/core
- Files:
-
- 13 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/objecthierarchy/src/orxonox/core/ClassFactory.h
r365 r447 34 34 /** 35 35 @brief Adds the ClassFactory to the Identifier of the same type and creates a new object to retrieve the parents. 36 @return True, because the compiler only allows assignments before main()36 @return Always true (this is needed because the compiler only allows assignments before main()) 37 37 */ 38 38 template <class T> -
code/branches/objecthierarchy/src/orxonox/core/ConfigValueContainer.cc
r435 r447 8 8 namespace orxonox 9 9 { 10 std::list<std::string>* ConfigValueContainer::configFileLines_s = 0; 11 bool ConfigValueContainer::readConfigFile_s = false; 12 10 std::list<std::string>* ConfigValueContainer::configFileLines_s = 0; // Set the static member variable configFileLines_s to zero 11 bool ConfigValueContainer::readConfigFile_s = false; // Set the static member variable readConfigFile_s to false 12 13 /** 14 @brief Constructor: Converts the default-value to a string, checks the config-file for a changed value, sets this->value_int_. 15 @param classname The name of the class the variable belongs to 16 @param varname The name of the variable 17 @param defvalue The default-value 18 */ 13 19 ConfigValueContainer::ConfigValueContainer(const std::string& classname, const std::string& varname, int defvalue) 14 20 { 21 // Try to convert the default-value from int to string 15 22 std::ostringstream ostream; 16 17 23 if (ostream << defvalue) 18 24 this->defvalue_ = ostream.str(); … … 20 26 this->defvalue_ = "0"; 21 27 28 // Set the default values, then get the value-string 22 29 this->setDefaultValues(classname, varname); 23 30 std::string valueString = this->getValueString(); 24 31 32 // Try to convert the value-string to int 25 33 std::istringstream istream(valueString); 26 34 if (!(istream >> this->value_int_)) 27 35 { 36 // The conversion failed - use the default value and restore the entry in the config-file 28 37 this->value_int_ = defvalue; 29 38 (*this->configFileLine_) = this->varname_ + "=" + this->defvalue_; … … 32 41 } 33 42 43 /** 44 @brief Constructor: Converts the default-value to a string, checks the config-file for a changed value, sets this->value_double_. 45 @param classname The name of the class the variable belongs to 46 @param varname The name of the variable 47 @param defvalue The default-value 48 */ 34 49 ConfigValueContainer::ConfigValueContainer(const std::string& classname, const std::string& varname, double defvalue) 35 50 { 51 // Try to convert the default-value from double to string 36 52 std::ostringstream ostream; 37 38 53 if (ostream << defvalue) 39 54 this->defvalue_ = ostream.str(); … … 41 56 this->defvalue_ = "0.000000"; 42 57 58 // Set the default values, then get the value-string 43 59 this->setDefaultValues(classname, varname); 44 60 std::string valueString = this->getValueString(); 45 61 62 // Try to convert the value-string to double 46 63 std::istringstream istream(valueString); 47 64 if (!(istream >> this->value_double_)) 48 65 { 66 // The conversion failed - use the default value and restore the entry in the config-file 49 67 this->value_double_ = defvalue; 50 68 (*this->configFileLine_) = this->varname_ + "=" + this->defvalue_; … … 53 71 } 54 72 73 /** 74 @brief Constructor: Converts the default-value to a string, checks the config-file for a changed value, sets this->value_bool_. 75 @param classname The name of the class the variable belongs to 76 @param varname The name of the variable 77 @param defvalue The default-value 78 */ 55 79 ConfigValueContainer::ConfigValueContainer(const std::string& classname, const std::string& varname, bool defvalue) 56 80 { 81 // Convert the default-value from bool to string 57 82 if (defvalue) 58 83 this->defvalue_ = "true"; … … 60 85 this->defvalue_ = "false"; 61 86 87 // Set the default values, then get the value-string 62 88 this->setDefaultValues(classname, varname); 63 89 std::string valueString = this->getValueString(); 64 90 91 // Try to parse the value-string - is it a word? 65 92 if (valueString.find("true") < valueString.size() || valueString.find("yes") < valueString.size()) 66 93 this->value_bool_ = true; … … 69 96 else 70 97 { 98 // Its not a known word - is it a number? 71 99 std::istringstream istream(valueString); 72 100 if (!(istream >> this->value_bool_)) 73 101 { 102 // The conversion failed - use the default value and restore the entry in the config-file 74 103 this->value_bool_ = defvalue; 75 104 (*this->configFileLine_) = this->varname_ + "=" + this->defvalue_; … … 79 108 } 80 109 110 /** 111 @brief Constructor: Converts the default-value to a string, checks the config-file for a changed value, sets this->value_string_. 112 @param classname The name of the class the variable belongs to 113 @param varname The name of the variable 114 @param defvalue The default-value 115 */ 81 116 ConfigValueContainer::ConfigValueContainer(const std::string& classname, const std::string& varname, const char* defvalue) 82 117 { 118 // Not much to do here - just set all member-variables and check the config-file 83 119 this->defvalue_ = defvalue; 84 120 this->setDefaultValues(classname, varname); … … 86 122 } 87 123 124 /** 125 @brief Constructor: Converts the default-value to a string, checks the config-file for a changed value, sets this->value_vector3_. 126 @param classname The name of the class the variable belongs to 127 @param varname The name of the variable 128 @param defvalue The default-value 129 */ 88 130 ConfigValueContainer::ConfigValueContainer(const std::string& classname, const std::string& varname, Ogre::Vector3 defvalue) 89 131 { 132 // Try to convert the default-value from Vector3 to string 90 133 std::ostringstream ostream; 91 134 if (ostream << "(" << defvalue.x << "," << defvalue.y << "," << defvalue.z << ")") … … 94 137 this->defvalue_ = "(0,0,0)"; 95 138 139 // Set the default values, then get the value-string 96 140 this->setDefaultValues(classname, varname); 97 141 std::string valueString = this->getValueString(); 98 142 143 // Strip the value-string 144 valueString = this->getStrippedLine(valueString); 99 145 unsigned int pos; 100 while ((pos = valueString.find(" ")) < valueString.length())101 valueString.erase(pos, 1);102 146 while ((pos = valueString.find("(")) < valueString.length()) 103 147 valueString.erase(pos, 1); … … 107 151 valueString.replace(pos, 1, " "); 108 152 153 // Try to convert the stripped value-string to Vector3 109 154 std::istringstream istream(valueString); 110 111 155 if (!(istream >> this->value_vector3_.x)) 112 156 { 157 // The conversion failed - use the default value and restore the entry in the config-file 113 158 this->value_vector3_.x = defvalue.x; 114 159 (*this->configFileLine_) = this->varname_ + "=" + this->defvalue_; … … 117 162 if (!(istream >> this->value_vector3_.y)) 118 163 { 164 // The conversion failed - use the default value and restore the entry in the config-file 119 165 this->value_vector3_.y = defvalue.y; 120 166 (*this->configFileLine_) = this->varname_ + "=" + this->defvalue_; … … 123 169 if (!(istream >> this->value_vector3_.z)) 124 170 { 171 // The conversion failed - use the default value and restore the entry in the config-file 125 172 this->value_vector3_.z = defvalue.z; 126 173 (*this->configFileLine_) = this->varname_ + "=" + this->defvalue_; … … 129 176 } 130 177 178 /** 179 @brief Constructor: Converts the default-value to a string, checks the config-file for a changed value, sets this->value_colourvalue_. 180 @param classname The name of the class the variable belongs to 181 @param varname The name of the variable 182 @param defvalue The default-value 183 */ 131 184 ConfigValueContainer::ConfigValueContainer(const std::string& classname, const std::string& varname, Ogre::ColourValue defvalue) 132 185 { 186 // Try to convert the default-value from ColourValue to string 133 187 std::ostringstream ostream; 134 188 if (ostream << "(" << defvalue.r << "," << defvalue.g << "," << defvalue.b << "," << defvalue.a << ")") … … 137 191 this->defvalue_ = "(0,0,0,0)"; 138 192 193 // Set the default values, then get the value-string 139 194 this->setDefaultValues(classname, varname); 140 195 std::string valueString = this->getValueString(); 141 196 197 // Strip the value-string 198 valueString = this->getStrippedLine(valueString); 142 199 unsigned int pos; 143 while ((pos = valueString.find(" ")) < valueString.length())144 valueString.erase(pos, 1);145 200 while ((pos = valueString.find("(")) < valueString.length()) 146 201 valueString.erase(pos, 1); … … 150 205 valueString.replace(pos, 1, " "); 151 206 207 // Try to convert the stripped value-string to Vector3 152 208 std::istringstream istream(valueString); 153 154 209 if (!(istream >> this->value_colourvalue_.r)) 155 210 { 211 // The conversion failed - use the default value and restore the entry in the config-file 156 212 this->value_colourvalue_.r = defvalue.r; 157 213 (*this->configFileLine_) = this->varname_ + "=" + this->defvalue_; … … 160 216 if (!(istream >> this->value_colourvalue_.g)) 161 217 { 218 // The conversion failed - use the default value and restore the entry in the config-file 162 219 this->value_colourvalue_.g = defvalue.g; 163 220 (*this->configFileLine_) = this->varname_ + "=" + this->defvalue_; … … 166 223 if (!(istream >> this->value_colourvalue_.b)) 167 224 { 225 // The conversion failed - use the default value and restore the entry in the config-file 168 226 this->value_colourvalue_.b = defvalue.b; 169 227 (*this->configFileLine_) = this->varname_ + "=" + this->defvalue_; … … 172 230 if (!(istream >> this->value_colourvalue_.a)) 173 231 { 232 // The conversion failed - use the default value and restore the entry in the config-file 174 233 this->value_colourvalue_.a = defvalue.a; 175 234 (*this->configFileLine_) = this->varname_ + "=" + this->defvalue_; … … 178 237 } 179 238 239 /** 240 @brief Sets the default values of the container and searches the coresponding entry in the config-file. 241 @param classname The name of the class the variable belongs to 242 @param varname The name of the variable 243 */ 180 244 void ConfigValueContainer::setDefaultValues(const std::string& classname, const std::string& varname) 181 245 { 246 // Set the class and variable names 182 247 this->classname_ = classname; 183 248 this->varname_ = varname; 184 249 250 // Search the entry in the config-file 185 251 this->searchConfigFileLine(); 186 252 253 // Set the values of all types to zero 187 254 this->value_int_ = 0; 188 255 this->value_double_ = 0.000000; … … 193 260 } 194 261 262 /** 263 @brief Searches the corresponding entry in the config-file and creates it, if there is no entry. 264 */ 195 265 void ConfigValueContainer::searchConfigFileLine() 196 266 { 267 // Read the file if needed 197 268 if (!ConfigValueContainer::readConfigFile_s) 198 269 ConfigValueContainer::readConfigFile(CONFIGFILEPATH); 199 270 271 // Just in case something goes wrong 200 272 this->configFileLine_ = 0; 201 273 274 // The string of the section we're searching 202 275 std::string section = ""; 203 276 section.append("["); … … 205 278 section.append("]"); 206 279 280 // Iterate through all config-file-lines 207 281 bool success = false; 208 282 std::list<std::string>::iterator it1; 209 283 for(it1 = ConfigValueContainer::configFileLines_s->begin(); it1 != ConfigValueContainer::configFileLines_s->end(); ++it1) 210 284 { 285 // Don't try to parse comments 211 286 if (this->isComment(*it1)) 212 287 continue; … … 214 289 if ((*it1).find(section) < (*it1).length()) 215 290 { 291 // We found the right section 216 292 bool bLineIsEmpty = false; 217 293 std::list<std::string>::iterator positionToPutNewLineAt; 218 294 295 // Iterate through all lines in the section 219 296 std::list<std::string>::iterator it2; 220 297 for(it2 = ++it1; it2 != ConfigValueContainer::configFileLines_s->end(); ++it2) 221 298 { 299 // Don't try to parse comments 222 300 if (this->isComment(*it2)) 223 301 continue; 224 302 303 // This if-else block is used to write a new line right after the last line of the 304 // section but in front of the following empty lines before the next section. 305 // (So this helps to keep a nice formatting with empty-lines between sections in the config-file) 225 306 if (this->isEmpty(*it2)) 226 307 { … … 239 320 } 240 321 322 // Look out for the beginning of the next section 241 323 unsigned int open = (*it2).find("["); 242 324 unsigned int close = (*it2).find("]"); 243 325 if ((open < (*it2).length()) && (close < (*it2).length()) && (open < close)) 244 326 { 327 // The next section startet, so our line isn't yet in the file - now we add it and safe the file 245 328 this->configFileLine_ = this->configFileLines_s->insert(positionToPutNewLineAt, this->varname_ + "=" + this->defvalue_); 246 329 ConfigValueContainer::writeConfigFile(CONFIGFILEPATH); … … 249 332 } 250 333 334 // Look out for the variable-name 251 335 if ((*it2).find(this->varname_) < (*it2).length()) 252 336 { 337 // We found the right line - safe it and return 253 338 this->configFileLine_ = it2; 254 339 success = true; … … 256 341 } 257 342 } 343 344 // Check if we succeeded 258 345 if (!success) 259 346 { 347 // Looks like we found the right section, but the file ended without containing our variable - so we add it and safe the file 260 348 this->configFileLine_ = this->configFileLines_s->insert(positionToPutNewLineAt, this->varname_ + "=" + this->defvalue_); 261 349 ConfigValueContainer::writeConfigFile(CONFIGFILEPATH); … … 265 353 } 266 354 } 355 356 // Check if we succeeded 267 357 if (!success) 268 358 { 269 this->configFileLines_s->push_back("[" + this->classname_ + "]"); 270 this->configFileLines_s->push_back(this->varname_ + "=" + this->defvalue_); 271 this->configFileLine_ = --this->configFileLines_s->end(); 359 // We obviously didn't found the right section, so we'll create it 360 this->configFileLines_s->push_back("[" + this->classname_ + "]"); // Create the section 361 this->configFileLines_s->push_back(this->varname_ + "=" + this->defvalue_); // Create the line 362 this->configFileLine_ = --this->configFileLines_s->end(); // Set the pointer to the last element 272 363 success = true; 273 this->configFileLines_s->push_back(""); 274 ConfigValueContainer::writeConfigFile(CONFIGFILEPATH); 275 } 276 } 277 364 this->configFileLines_s->push_back(""); // Add an empty line - this is needed for the algorithm in the searchConfigFileLine-function 365 ConfigValueContainer::writeConfigFile(CONFIGFILEPATH); // Save the changed config-file 366 } 367 } 368 369 /** 370 @brief Determines if a line in the config-file is a comment. 371 @param line The line to check 372 @return True = it's a comment 373 */ 278 374 bool ConfigValueContainer::isComment(const std::string& line) 279 375 { 376 // Strip the line, whitespaces are disturbing 280 377 std::string teststring = getStrippedLine(line); 281 378 379 // There are four possible comment-symbols: 380 // 1) #comment in script-language style 381 // 2) %comment in matlab style 382 // 3) ;comment in unreal tournament config-file style 383 // 4) //comment in code style 282 384 if (teststring[0] == '#' || teststring[0] == '%' || teststring[0] == ';' || (teststring[0] == '/' && teststring[0] == '/')) 283 385 return true; … … 286 388 } 287 389 390 /** 391 @brief Determines if a line in the config-file is empty (contains only whitespaces). 392 @param line The line to check 393 @return True = it's empty 394 */ 288 395 bool ConfigValueContainer::isEmpty(const std::string& line) 289 396 { … … 291 398 } 292 399 400 /** 401 @brief Removes all whitespaces from a line. 402 @param line The line to strip 403 @return The stripped line 404 */ 293 405 std::string ConfigValueContainer::getStrippedLine(const std::string& line) 294 406 { … … 301 413 } 302 414 415 /** 416 @brief Returns the part in the corresponding config-file-entry of the container that defines the value. 417 @param bStripped True = strip the value-string 418 @return The value-string 419 */ 303 420 std::string ConfigValueContainer::getValueString(bool bStripped) 304 421 { … … 312 429 } 313 430 431 /** 432 @brief Reads the config-file and stores the lines in a list. 433 @param filename The name of the config-file 434 */ 314 435 void ConfigValueContainer::readConfigFile(const std::string& filename) 315 436 { 316 437 ConfigValueContainer::readConfigFile_s = true; 317 438 439 // Create the list if needed 318 440 if (!ConfigValueContainer::configFileLines_s) 319 441 ConfigValueContainer::configFileLines_s = new std::list<std::string>; 320 442 443 // This creates the file if it's not existing 321 444 std::ofstream createFile; 322 445 createFile.open(filename.c_str(), std::fstream::app); 323 446 createFile.close(); 324 447 448 // Open the file 325 449 std::ifstream file; 326 450 file.open(filename.c_str(), std::fstream::in); … … 328 452 char line[1024]; 329 453 454 // Iterate through the file and add the lines into the list 330 455 while (file.good() && !file.eof()) 331 456 { … … 335 460 } 336 461 462 // The last line is useless 337 463 ConfigValueContainer::configFileLines_s->pop_back(); 338 464 465 // Add an empty line to the end of the file if needed 466 // this is needed for the algorithm in the searchConfigFileLine-function 339 467 if ((ConfigValueContainer::configFileLines_s->size() > 0) && !isEmpty(*ConfigValueContainer::configFileLines_s->rbegin())) 340 468 { … … 346 474 } 347 475 476 /** 477 @param Writes the content of the list, containing all lines of the config-file, into the config-file. 478 @param filename The name of the config-file 479 */ 348 480 void ConfigValueContainer::writeConfigFile(const std::string& filename) 349 481 { 350 ConfigValueContainer::readConfigFile_s = true; 351 352 if (!ConfigValueContainer::configFileLines_s) 353 ConfigValueContainer::configFileLines_s = new std::list<std::string>; 354 355 std::ofstream createFile; 356 createFile.open(filename.c_str(), std::fstream::app); 357 createFile.close(); 358 482 // Make sure we stored the config-file in the list 483 if (!ConfigValueContainer::readConfigFile_s) 484 ConfigValueContainer::readConfigFile(filename); 485 486 // Open the file 359 487 std::ofstream file; 360 488 file.open(filename.c_str(), std::fstream::out); 361 489 490 // Iterate through the list an write the lines into the file 362 491 std::list<std::string>::iterator it; 363 492 for(it = ConfigValueContainer::configFileLines_s->begin(); it != ConfigValueContainer::configFileLines_s->end(); ++it) -
code/branches/objecthierarchy/src/orxonox/core/ConfigValueContainer.h
r434 r447 1 /*! 2 @file ConfigValueContainer.h 3 @brief Definition of the ConfigValueContainer class. 4 5 The ConfigValueContainer class contains all needed informations about a configurable variable: 6 - the name of the variable 7 - the name of the class the variable belongs to 8 - the default value 9 - the user-specified value 10 - a pointer to the entry in the config-file 11 12 This is needed to assign the configured values to all newly created objects. 13 */ 14 1 15 #ifndef _ConfigValueContainer_H__ 2 16 #define _ConfigValueContainer_H__ … … 9 23 namespace orxonox 10 24 { 25 //! The ConfigValuecontainer contains all needed informations about a configurable variable. 26 /** 27 The ConfigValueContainer class contains all needed informations about a configurable variable: 28 - the name of the variable 29 - the name of the class the variable belongs to 30 - the default value 31 - the user-specified value 32 - a pointer to the entry in the config-file 33 34 This is needed to assign the configured values to all newly created objects. 35 36 The container searches for the entry in the config file. 37 If there is an entry, it parses the specified value and assigns it to the variable of the right type. 38 If there is no entry, it adds the entry with the default-value to the section of the variables class. 39 If there is no section, the section and the entry are added to the end of the config-file. 40 */ 11 41 class ConfigValueContainer 12 42 { … … 29 59 static void writeConfigFile(const std::string& filename); 30 60 61 /** @returns the value of the type int. @param value This is only needed to determine the right type. */ 31 62 inline int getValue(int value) { return this->value_int_; } 63 /** @returns the value of the type double. @param value This is only needed to determine the right type. */ 32 64 inline double getValue(double value) { return this->value_double_; } 65 /** @returns the value of the type bool. @param value This is only needed to determine the right type. */ 33 66 inline bool getValue(bool value) { return this->value_bool_; } 67 /** @returns the value of the type std::string. @param value This is only needed to determine the right type. */ 34 68 inline std::string getValue(const std::string& value) { return this->value_string_; } 69 /** @returns the value of the type Vector3. @param value This is only needed to determine the right type. */ 35 70 inline Ogre::Vector3 getValue(const Ogre::Vector3& value) { return this->value_vector3_; } 71 /** @returns the value of the type Colour£Value. @param value This is only needed to determine the right type. */ 36 72 inline Ogre::ColourValue getValue(const Ogre::ColourValue& value) { return this->value_colourvalue_; } 37 73 38 74 private: 39 std::string classname_; 40 std::string varname_; 41 std::string defvalue_; 75 std::string classname_; //!< The name of the class the variable belongs to 76 std::string varname_; //!< The name of the variable 77 std::string defvalue_; //!< The string of the default-variable 42 78 43 int value_int_; 44 double value_double_; 45 bool value_bool_; 46 std::string value_string_; 47 Ogre::Vector3 value_vector3_; 48 Ogre::ColourValue value_colourvalue_; 79 int value_int_; //!< The value, if the variable is of the type int 80 double value_double_; //!< The value, if the variable is of the type double 81 bool value_bool_; //!< The value, if the variable is of the type bool 82 std::string value_string_; //!< The value, if the variable is of the type string 83 Ogre::Vector3 value_vector3_; //!< The value, if the variable is of the type Vector3 84 Ogre::ColourValue value_colourvalue_; //!< The value, if the variable is of the type ColourValue 49 85 50 std::list<std::string>::iterator configFileLine_; 51 static std::list<std::string>* configFileLines_s; 52 static bool readConfigFile_s; 86 std::list<std::string>::iterator configFileLine_; //!< An iterator, pointing to the entry of the variable in the config-file 87 static std::list<std::string>* configFileLines_s; //!< A list, containing all entrys in the config-file 88 static bool readConfigFile_s; //!< True if the config-file is read and stored in the list 53 89 }; 54 90 } -
code/branches/objecthierarchy/src/orxonox/core/CoreIncludes.h
r443 r447 1 1 /** 2 2 @file CoreIncludes.h 3 @brief Definition of macros for the class-hierarchy and the factory.3 @brief Definition of macros and typedefs. 4 4 5 5 Every class needs the RegisterObject(class) macro in its constructor. If the class is an interface … … 21 21 #include "OgreColourValue.h" 22 22 23 24 // Some typedefs 23 25 namespace orxonox 24 26 { … … 27 29 } 28 30 29 // Intern macro, containing the common parts of RegisterObject and RegisterRootObject 31 32 /** 33 @brief Intern macro, containing the common parts of RegisterObject and RegisterRootObject. 34 @param ClassName The name of the class 35 @param bRootClass True if the class is directly derived from OrxonoxClass 36 */ 30 37 #define InternRegisterObject(ClassName, bRootClass) \ 31 38 this->setIdentifier(ClassIdentifier<ClassName>::registerClass(this->getParents(), #ClassName, bRootClass)); \ … … 34 41 ClassIdentifier<ClassName>::addObject(this) 35 42 36 // Intern macro, containing the specific part of RegisterRootObject 43 /** 44 @brief Intern macro, containing the specific part of RegisterRootObject. 45 @param ClassName The name of the class 46 */ 37 47 #define InternRegisterRootObject(ClassName) \ 38 48 if (Identifier::isCreatingHierarchy() && !this->getParents()) \ … … 40 50 InternRegisterObject(ClassName, true) 41 51 42 // RegisterObject - with and without debug output 52 /** 53 @brief RegisterObject - with and without debug output. 54 @param ClassName The name of the class 55 */ 43 56 #if HIERARCHY_VERBOSE 44 57 #define RegisterObject(ClassName) \ … … 50 63 #endif 51 64 52 // RegisterRootObject - with and without debug output 65 /** 66 @brief RegisterRootObject - with and without debug output. 67 @param ClassName The name of the class 68 */ 53 69 #if HIERARCHY_VERBOSE 54 70 #define RegisterRootObject(ClassName) \ … … 60 76 #endif 61 77 62 // Class(ClassName) returns the Identifier of the given class 78 /** 79 @brief Returns the Identifier of the given class. 80 @param ClassName The name of the class 81 */ 63 82 #define Class(ClassName) \ 64 83 ClassIdentifier<ClassName>::getIdentifier() 65 84 66 // Creates the entry in the Factory 85 /** 86 @brief Creates the entry in the Factory. 87 @param ClassName The name of the class 88 */ 67 89 #define CreateFactory(ClassName) \ 68 90 bool bCreated##ClassName##Factory = ClassFactory<ClassName>::create() 69 91 70 // ID(StringOrInt) returns the Identifier with either a given name or a given NetworkID through the factory 92 /** 93 @brief Returns the Identifier with either a given name or a given network ID through the factory. 94 @param StringOrInt The name or the network ID of the class 95 */ 71 96 #define ID(StringOrInt) \ 72 97 Factory::getIdentifier(StringOrInt) 73 98 74 // bla 99 /** 100 @brief Assigns the value, defined in the config-file, to the variable (or the default-value, if there is no entry in the file). 101 @param varname The name of the variable 102 @param defvalue The default-value of the variable 103 */ 75 104 #define SetConfigValue(varname, defvalue) \ 76 105 ConfigValueContainer* container##varname = this->getIdentifier()->getConfigValueContainer(#varname); \ -
code/branches/objecthierarchy/src/orxonox/core/Factory.cc
r365 r447 24 24 25 25 /** 26 @returns the Identifier with a given network ID.27 @param id The network ID of the wanted Identifier26 @returns the Identifier with a given network ID. 27 @param id The network ID of the wanted Identifier 28 28 */ 29 29 Identifier* Factory::getIdentifier(const unsigned int id) … … 50 50 51 51 /** 52 @brief Removes the entry with the old network ID and adds a new one.52 @brief Removes the entry with the old network ID and adds a new one. 53 53 @param identifier The identifier to change 54 54 @param oldID The old networkID -
code/branches/objecthierarchy/src/orxonox/core/Factory.h
r383 r447 3 3 @brief Definition of the Factory and the BaseFactory class. 4 4 5 The Factory is a singleton, containing two maps to map either the name or the network ID5 The Factory is a singleton, containing two maps to map either the name or the network ID 6 6 of a class with the corresponding Identifier. 7 7 … … 28 28 // ### Factory ### 29 29 // ############################### 30 //! The Factory is used to map name or networkID of a class with its Identifier.30 //! The Factory is used to map the name or the network ID of a class with its Identifier. 31 31 class Factory 32 32 { … … 43 43 44 44 static Factory* pointer_s; //!< The pointer to the singleton 45 std::map<std::string, Identifier*> identifierStringMap_; //!< The map mapping string withIdentifier46 std::map<unsigned int, Identifier*> identifierNetworkIDMap_; //!< The map mapping networkID withIdentifier45 std::map<std::string, Identifier*> identifierStringMap_; //!< The map, mapping the name with the Identifier 46 std::map<unsigned int, Identifier*> identifierNetworkIDMap_; //!< The map, mapping the network ID with the Identifier 47 47 }; 48 48 -
code/branches/objecthierarchy/src/orxonox/core/Identifier.cc
r365 r447 12 12 // ############################### 13 13 int Identifier::hierarchyCreatingCounter_s = 0; // Set the static member variable hierarchyCreatingCounter_s to zero 14 unsigned int Identifier::classIDcounter_s = 0; // Set the static member variable classIDcounter_s to zero14 unsigned int Identifier::classIDcounter_s = 0; // Set the static member variable classIDcounter_s to zero 15 15 16 16 /** … … 79 79 80 80 /** 81 @brief Sets the network ID to a new value and changes the entry in the Factory.82 @param id The new network ID81 @brief Sets the network ID to a new value and changes the entry in the Factory. 82 @param id The new network ID 83 83 */ 84 84 void Identifier::setNetworkID(unsigned int id) -
code/branches/objecthierarchy/src/orxonox/core/Identifier.h
r434 r447 7 7 - a list with all objects 8 8 - parents and childs 9 - the factory , if available9 - the factory (if available) 10 10 - the networkID that can be synchronised with the server 11 - all configurable variables (if available) 11 12 12 13 Every object has a pointer to the Identifier of its class. This allows the use isA(...), … … 18 19 19 20 SubclassIdentifier is a separated class, acting like an Identifier, but has a given class. 20 You can only assign Identifiers of the given class ora derivative to a SubclassIdentifier.21 You can only assign Identifiers of exactly the given class or of a derivative to a SubclassIdentifier. 21 22 */ 22 23 … … 48 49 - a list with all objects 49 50 - parents and childs 50 - the factory , if available51 - the factory (if available) 51 52 - the networkID that can be synchronised with the server 53 - all configurable variables (if available) 52 54 53 55 Every object has a pointer to the Identifier of its class. This allows the use isA(...), … … 87 89 inline IdentifierList& getChildren() const { return *this->children_; } 88 90 89 /** @returns true, if a branch of the class-hierarchy is getting created, causing all new objects to store their parents. */91 /** @returns true, if a branch of the class-hierarchy is being created, causing all new objects to store their parents. */ 90 92 inline static bool isCreatingHierarchy() { return (hierarchyCreatingCounter_s > 0); } 91 93 92 /** @returns the NetworkID to identify a class through the network. */94 /** @returns the network ID to identify a class through the network. */ 93 95 inline const unsigned int getNetworkID() const { return this->classID_; } 94 96 97 /** @brief Sets the network ID to a new value. @param id The new value */ 95 98 void setNetworkID(unsigned int id); 96 99 100 /** @returns the ConfigValueContainer of a variable, given by the string of its name. @param varname The name of the variable */ 97 101 inline ConfigValueContainer* getConfigValueContainer(const std::string& varname) 98 102 { return this->configValues_[varname]; } 99 103 104 /** @brief Sets the ConfigValueContainer of a variable, given by the string of its name. @param varname The name of the variablee @param container The container */ 100 105 inline void setConfigValueContainer(const std::string& varname, ConfigValueContainer* container) 101 106 { this->configValues_[varname] = container; } … … 134 139 std::string name_; //!< The name of the class the Identifier belongs to 135 140 136 BaseFactory* factory_; //!< The Factory, able to create new objects of the given class 141 BaseFactory* factory_; //!< The Factory, able to create new objects of the given class (if available) 137 142 bool bCreatedOneObject_; //!< True if at least one object of the given type was created (used to determine the need of storing the parents) 138 143 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) 139 static unsigned int classIDcounter_s; //!< The number of uniqueIdentifiers140 unsigned int classID_; //!< The network ID to identify a class through the network141 std::map<std::string, ConfigValueContainer*> configValues_; 144 static unsigned int classIDcounter_s; //!< The number of existing Identifiers 145 unsigned int classID_; //!< The network ID to identify a class through the network 146 std::map<std::string, ConfigValueContainer*> configValues_; //!< A map to link the string of configurable variables with their ConfigValueContainer 142 147 }; 143 148 … … 173 178 174 179 /** 175 @brief Constructor: Create the ObjectList.180 @brief Constructor: Creates the ObjectList. 176 181 */ 177 182 template <class T> … … 182 187 183 188 /** 184 @brief Destructor: Delete the ObjectList, setthe singleton-pointer to zero.189 @brief Destructor: Deletes the ObjectList, sets the singleton-pointer to zero. 185 190 */ 186 191 template <class T> … … 195 200 @param parents An IdentifierList, containing the Identifiers of all parents of the class 196 201 @param name A string, containing exactly the name of the class 197 @param bRootClass True if the class is either an Interface or BaseObject itself202 @param bRootClass True if the class is either an Interface or the BaseObject itself 198 203 @return The ClassIdentifier itself 199 204 */ … … 235 240 236 241 /** 237 @returns the Identifier itself 242 @returns the Identifier itself. 238 243 */ 239 244 template <class T> … … 270 275 //! The SubclassIdentifier acts almost like an Identifier, but has some prerequisites. 271 276 /** 272 You can only assign Identifiers that belong to a class of at least B(or derived) to a SubclassIdentifier<T>.277 You can only assign an Identifier that belongs to a class T (or derived) to a SubclassIdentifier<T>. 273 278 If you assign something else, the program aborts. 274 279 Because we know the minimal type, a dynamic_cast is done, which makes it easier to create a new object. … … 323 328 324 329 /** 325 @brief Creates a new object of the type of the assigned identifier and dynamic_casts it to the minimal type given by the SubclassIdentifier.330 @brief Creates a new object of the type of the assigned Identifier and dynamic_casts it to the minimal type given by T. 326 331 @return The new object 327 332 */ … … 330 335 BaseObject* newObject = this->identifier_->fabricate(); 331 336 332 // Check if the creation w orked337 // Check if the creation was successful 333 338 if (newObject) 334 339 { -
code/branches/objecthierarchy/src/orxonox/core/IdentifierList.cc
r365 r447 101 101 102 102 /** 103 @returns a string, containing the names of all Identifiers in the list.103 @returns a string, containing a list of the names of all Identifiers in the list. 104 104 */ 105 105 std::string IdentifierList::toString() const -
code/branches/objecthierarchy/src/orxonox/core/Iterator.h
r365 r447 4 4 5 5 The Iterator of a given class allows to iterate through an ObjectList, containing all objects of that type. 6 This is the only way to access the objects in an ObjectList.6 This is the only way to access the objects stored in an ObjectList. 7 7 8 8 Usage: … … 13 13 } 14 14 15 Warning: Don't delete an objectdirectly through the iterator.15 Warning: Don't delete objects directly through the iterator. 16 16 */ 17 17 … … 27 27 public: 28 28 /** 29 @brief Constructor: Sets the element whereon the iterator pointsto zero.29 @brief Constructor: Sets the element, whereon the iterator points, to zero. 30 30 */ 31 31 Iterator() … … 35 35 36 36 /** 37 @brief Constructor: Sets the element whereon the iterator pointsto a given element.37 @brief Constructor: Sets the element, whereon the iterator points, to a given element. 38 38 @param element The element to start with 39 39 */ … … 44 44 45 45 /** 46 @brief Overloading of the ++it operator: Iterator iterates to the next object in the list.46 @brief Overloading of the ++it operator: Iterator points to the next object in the list. 47 47 @return The Iterator itself 48 48 */ … … 54 54 55 55 /** 56 @brief Overloading of the --it operator: Iterator iterates to the previous object in the list.56 @brief Overloading of the --it operator: Iterator points to the previous object in the list. 57 57 @return The Iterator itself 58 58 */ … … 98 98 bool operator!=(int compare) 99 99 { 100 // Comparing with something except zero makes no sense100 // Comparing with anything except zero makes no sense 101 101 if (compare != 0) 102 102 std::cout << "Warning: Comparing the " << ClassIdentifier<T>::getIdentifier()->getName() << "-List-Iterator with " << compare << " has no effect. Only comparison with 0 works.\n"; … … 106 106 107 107 private: 108 ObjectListElement<T>* element_; //!< The element the Iterator points to108 ObjectListElement<T>* element_; //!< The element the Iterator points at 109 109 }; 110 110 } -
code/branches/objecthierarchy/src/orxonox/core/MetaObjectList.h
r365 r447 4 4 5 5 The MetaObjectList is a single-linked list, containing all list-elements and their 6 lists wherein the object that owns the MetaObjectListis registered.7 This allows much faster deleti ng of objects.6 lists wherein the object, owning the MetaObjectList, is registered. 7 This allows much faster deletion of objects because no iteration is needed. 8 8 */ 9 9 … … 20 20 { 21 21 public: 22 /** @brief Default destructor */22 /** @brief Default destructor */ 23 23 virtual ~BaseMetaObjectListElement() {}; 24 24 … … 83 83 The MetaObjectList is a single-linked list, containing all list-elements and their 84 84 lists wherein the object that owns the MetaObjectList is registered. 85 This allows much faster deleti ng of objects.85 This allows much faster deletion of objects because no iteration is needed. 86 86 */ 87 87 class MetaObjectList -
code/branches/objecthierarchy/src/orxonox/core/ObjectList.h
r365 r447 3 3 @brief Definition of the ObjectList class. 4 4 5 The ObjectList is a double-linked list, used by Identifiers to store all objects of a specific class in it.6 Created objects are added through the RegisterObject-macro in its constructor.5 The ObjectList is a double-linked list, used by Identifiers to store all objects of a given class. 6 Newly created objects are added through the RegisterObject-macro in its constructor. 7 7 Use Iterator<class> to iterate through all objects of the class. 8 8 */ … … 32 32 /** 33 33 @brief Constructor: Creates the list-element with an object. 34 @param Object The object to store34 @param object The object to store 35 35 */ 36 36 template <class T> … … 49 49 class Iterator; // Forward declaration 50 50 51 //! The ObjectList contains all objects of a specificclass.52 /** 53 The ObjectList is used by Identifiers to store all objects of a specific class in it.51 //! The ObjectList contains all objects of a given class. 52 /** 53 The ObjectList is used by Identifiers to store all objects of a given class. 54 54 Use Iterator<class> to iterate through all objects in the list. 55 55 */ … … 82 82 83 83 /** 84 @brief Constructor: Sets first_ and last_ to zero and the static member variable pointer_s to _this_84 @brief Constructor: Sets default values. 85 85 */ 86 86 template <class T> -
code/branches/objecthierarchy/src/orxonox/core/OrxonoxClass.h
r434 r447 3 3 @brief Definition of the OrxonoxClass Class. 4 4 5 All objects and interfaces of the game-logic are derived from OrxonoxClass.6 It stores the Identifier and the MetaObjectList and has all needed functions to create the class-hierarchy.5 All objects and interfaces of the game-logic (not the engine) are derived from OrxonoxClass. 6 It stores the Identifier and the MetaObjectList and has all needed functions to create and use the class-hierarchy. 7 7 */ 8 8 … … 17 17 namespace orxonox 18 18 { 19 //! The class all objects and interfaces of the game-logic are derived from.19 //! The class all objects and interfaces of the game-logic (not the engine) are derived from. 20 20 /** 21 BaseObject and Interaces are derived with 'virtual public OrxonoxClass' from OrxonoxClass.21 The BaseObject and Interaces are derived with 'virtual public OrxonoxClass' from OrxonoxClass. 22 22 OrxonoxClass is needed to create the class-hierarchy at startup and to store the Identifier and the MetaObjectList. 23 23 */ … … 45 45 inline MetaObjectList& getMetaList() { return this->metaList_; } 46 46 47 48 /** @returns true if the objects class is of the given type or a derivative. */ 47 49 inline bool isA(const Identifier* identifier) 48 50 { return this->getIdentifier()->isA(identifier); } 51 /** @returns true if the objects class is exactly of the given type. */ 49 52 inline bool isDirectlyA(const Identifier* identifier) 50 53 { return this->getIdentifier()->isDirectlyA(identifier); } 54 /** @returns true if the objects class is a child of the given type. */ 51 55 inline bool isChildOf(const Identifier* identifier) 52 56 { return this->getIdentifier()->isChildOf(identifier); } 57 /** @returns true if the objects class is a parent of the given type. */ 53 58 inline bool isParentOf(const Identifier* identifier) 54 59 { return this->getIdentifier()->isParentOf(identifier); } 55 60 61 62 /** @returns true if the objects class is of the given type or a derivative. */ 56 63 inline bool isA(const SubclassIdentifier<class B>* identifier) 57 64 { return this->getIdentifier()->isA(identifier->getIdentifier()); } 65 /** @returns true if the objects class is exactly of the given type. */ 58 66 inline bool isDirectlyA(const SubclassIdentifier<class B>* identifier) 59 67 { return this->getIdentifier()->isDirectlyA(identifier->getIdentifier()); } 68 /** @returns true if the objects class is a child of the given type. */ 60 69 inline bool isChildOf(const SubclassIdentifier<class B>* identifier) 61 70 { return this->getIdentifier()->isChildOf(identifier->getIdentifier()); } 71 /** @returns true if the objects class is a parent of the given type. */ 62 72 inline bool isParentOf(const SubclassIdentifier<class B>* identifier) 63 73 { return this->getIdentifier()->isParentOf(identifier->getIdentifier()); } 64 74 75 76 /** @returns true if the objects class is of the given type or a derivative. */ 65 77 inline bool isA(const SubclassIdentifier<class B> identifier) 66 78 { return this->getIdentifier()->isA(identifier.getIdentifier()); } 79 /** @returns true if the objects class is exactly of the given type. */ 67 80 inline bool isDirectlyA(const SubclassIdentifier<class B> identifier) 68 81 { return this->getIdentifier()->isDirectlyA(identifier.getIdentifier()); } 82 /** @returns true if the objects class is a child of the given type. */ 69 83 inline bool isChildOf(const SubclassIdentifier<class B> identifier) 70 84 { return this->getIdentifier()->isChildOf(identifier.getIdentifier()); } 85 /** @returns true if the objects class is a parent of the given type. */ 71 86 inline bool isParentOf(const SubclassIdentifier<class B> identifier) 72 87 { return this->getIdentifier()->isParentOf(identifier.getIdentifier()); } 73 88 89 90 /** @returns true if the objects class is of the given type or a derivative. */ 74 91 inline bool isA(const OrxonoxClass* object) 75 92 { return this->getIdentifier()->isA(object->getIdentifier()); } 93 /** @returns true if the objects class is exactly of the given type. */ 76 94 inline bool isDirectlyA(const OrxonoxClass* object) 77 95 { return this->getIdentifier()->isDirectlyA(object->getIdentifier()); } 96 /** @returns true if the objects class is a child of the given type. */ 78 97 inline bool isChildOf(const OrxonoxClass* object) 79 98 { return this->getIdentifier()->isChildOf(object->getIdentifier()); } 99 /** @returns true if the objects class is a parent of the given type. */ 80 100 inline bool isParentOf(const OrxonoxClass* object) 81 101 { return this->getIdentifier()->isParentOf(object->getIdentifier()); } 82 102 83 103 104 /** @brief Sets the name of the object. @param name The name */ 84 105 inline void setName(const std::string& name) { this->name_ = name; } 106 107 /** @returns the name of the object. */ 85 108 inline const std::string& getName() const { return this->name_; } 86 109 110 /** @brief Sets the state of the objects activity. @param bActive True = active */ 87 111 inline void setActive(bool bActive) { this->bActive_ = bActive; } 112 113 /** @returns the state of the objects activity. */ 88 114 inline const bool isActive() const { return this->bActive_; } 89 115 116 /** @brief Sets the state of the objects visibility. @param bVisible True = visible */ 90 117 inline void setVisible(bool bVisible) { this->bVisible_ = bVisible; } 118 119 /** @returns the state of the objects visibility. */ 91 120 inline const bool isVisible() const { return this->bVisible_; } 92 121 … … 96 125 MetaObjectList metaList_; //!< MetaObjectList, containing all ObjectLists and ObjectListElements the object is registered in 97 126 98 std::string name_; 99 bool bActive_; 100 bool bVisible_; 127 std::string name_; //!< The name of the object 128 bool bActive_; //!< True = the object is active 129 bool bVisible_; //!< True = the object is visible 101 130 }; 102 131 }
Note: See TracChangeset
for help on using the changeset viewer.