Changeset 1052 for code/trunk/src/orxonox/core
- Timestamp:
- Apr 14, 2008, 3:42:49 AM (17 years ago)
- Location:
- code/trunk/src/orxonox/core
- Files:
-
- 2 deleted
- 25 edited
- 14 copied
Legend:
- Unmodified
- Added
- Removed
-
code/trunk/src/orxonox/core/BaseObject.cc
r1021 r1052 52 52 this->bVisible_ = true; 53 53 this->level_ = 0; 54 this->namespace_ = 0; 54 55 } 55 56 … … 78 79 @return The XML-element 79 80 */ 80 void BaseObject::XMLPort(Element& xmlelement, bool loading)81 void BaseObject::XMLPort(Element& xmlelement, XMLPort::Mode mode) 81 82 { 82 XMLPortParam(BaseObject, "name", setName, getName, xmlelement, loading);83 XMLPortParam(BaseObject, "name", setName, getName, xmlelement, mode); 83 84 } 84 85 -
code/trunk/src/orxonox/core/BaseObject.h
r871 r1052 50 50 virtual ~BaseObject(); 51 51 virtual void loadParams(TiXmlElement* xmlElem); 52 virtual void XMLPort(Element& xmlelement, bool loading);52 virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode); 53 53 54 54 /** @brief Sets the name of the object. @param name The name */ … … 79 79 const std::string& getLevelfile() const; 80 80 81 virtual inline void setNamespace(Namespace* ns) { this->namespace_ = ns; } 82 inline Namespace* getNamespace() const { return this->namespace_; } 83 81 84 /** @brief Sets the indentation of the debug output in the Loader. @param indentation The indentation */ 82 85 inline void setLoaderIndentation(const std::string& indentation) { this->loaderIndentation_ = indentation; } … … 90 93 const Level* level_; //!< The level that loaded this object 91 94 std::string loaderIndentation_; //!< Indentation of the debug output in the Loader 95 Namespace* namespace_; 92 96 }; 93 97 } -
code/trunk/src/orxonox/core/CMakeLists.txt
r1048 r1052 9 9 InputEventListener.cc 10 10 MetaObjectList.cc 11 ConfigFileManager.cc 11 12 ConfigValueContainer.cc 12 13 Error.cc 13 14 SignalHandler.cc 14 DebugLevel.cc15 CoreSettings.cc 15 16 OutputHandler.cc 16 17 Language.cc … … 19 20 Executor.cc 20 21 XMLPort.cc 22 Namespace.cc 23 NamespaceNode.cc 24 CommandExecutor.cc 25 InputBuffer.cc 21 26 Tickable.cc 22 27 Script.cc -
code/trunk/src/orxonox/core/ClassTreeMask.cc
r1021 r1052 327 327 { 328 328 // No it's not: Search for classes inheriting from the given class and add the rules for them 329 for (std:: list<const Identifier*>::const_iterator it = subclass->getDirectChildrenBegin(); it != subclass->getDirectChildrenEnd(); ++it)329 for (std::set<const Identifier*>::const_iterator it = subclass->getDirectChildrenBegin(); it != subclass->getDirectChildrenEnd(); ++it) 330 330 if ((*it)->isA(this->root_->getClass())) 331 331 if (overwrite || (!this->nodeExists(*it))) // If we don't want to overwrite, only add nodes that don't already exist … … 422 422 void ClassTreeMask::addSingle(const Identifier* subclass, bool bInclude, bool clean) 423 423 { 424 for (std:: list<const Identifier*>::const_iterator it = subclass->getDirectChildrenBegin(); it != subclass->getDirectChildrenEnd(); ++it)424 for (std::set<const Identifier*>::const_iterator it = subclass->getDirectChildrenBegin(); it != subclass->getDirectChildrenEnd(); ++it) 425 425 this->add(*it, this->isIncluded(*it), false, false); 426 426 … … 561 561 562 562 /** 563 @brief Compares the mask with another mask and returns true if they represent the same logic. 564 @param other The other mask 565 @return True if both masks represent the same logic 566 */ 567 bool ClassTreeMask::operator==(const ClassTreeMask& other) const 568 { 569 ClassTreeMask temp1 = other; 570 ClassTreeMask temp2 = (*this); 571 572 temp1.clean(); 573 temp2.clean(); 574 575 ClassTreeMaskIterator it1 = temp1.root_; 576 ClassTreeMaskIterator it2 = temp2.root_; 577 578 for ( ; it1 && it2; ++it1, ++it2) 579 if (it1->getClass() != it2->getClass()) 580 return false; 581 582 return true; 583 } 584 585 /** 586 @brief Compares the mask with another mask and returns true if they represent different logics. 587 @param other The other mask 588 @return True if the masks represent different logics 589 */ 590 bool ClassTreeMask::operator!=(const ClassTreeMask& other) const 591 { 592 return (!((*this) == other)); 593 } 594 595 /** 563 596 @brief Prefix operator + does nothing. 564 597 @return A reference to the mask itself -
code/trunk/src/orxonox/core/ClassTreeMask.h
r871 r1052 179 179 ClassTreeMask& operator=(const ClassTreeMask& other); 180 180 181 bool operator==(const ClassTreeMask& other) const; 182 bool operator!=(const ClassTreeMask& other) const; 183 181 184 ClassTreeMask& operator+(); 182 185 ClassTreeMask operator-() const; -
code/trunk/src/orxonox/core/ConfigValueContainer.cc
r871 r1052 34 34 35 35 #include "ConfigValueContainer.h" 36 #include "util/Tokenizer.h" 36 #include "Language.h" 37 #include "Identifier.h" 38 #include "util/SubString.h" 37 39 #include "util/Convert.h" 38 #include "Language.h" 39 40 #define CONFIGFILEPATH "orxonox.ini" 40 41 #define MAX_VECTOR_INDEX 255 // to avoid up to 4*10^9 vector entries in the config file after accidentally using a wrong argument 42 41 43 42 44 namespace orxonox … … 44 46 /** 45 47 @brief Constructor: Converts the default-value to a string, checks the config-file for a changed value, sets the intern value variable. 46 @param value This is only needed to determine the right type.47 @param classname The nameof the class the variable belongs to48 @param type The type of the corresponding config-file 49 @param identifier The identifier of the class the variable belongs to 48 50 @param varname The name of the variable 49 51 @param defvalue The default-value 50 52 */ 51 ConfigValueContainer::ConfigValueContainer(const std::string& classname, const std::string& varname, MultiTypeMath defvalue) 52 { 53 ConfigValueContainer::ConfigValueContainer(ConfigFileType type, Identifier* identifier, const std::string& varname, const MultiTypeMath& defvalue) 54 { 55 this->type_ = type; 56 this->identifier_ = identifier; 57 this->sectionname_ = identifier->getName(); 58 this->varname_ = varname; 59 60 this->value_ = defvalue; 53 61 this->bAddedDescription_ = false; 54 this->classname_ = classname; 62 this->bIsVector_ = false; 63 64 this->defvalueString_ = defvalue.toString(); 65 this->update(); 66 } 67 68 /** 69 @brief Constructor: Converts the default-value to a string, checks the config-file for a changed value, sets the intern value variable. 70 @param type The type of the corresponding config-file 71 @param identifier The identifier of the class the variable belongs to 72 @param varname The name of the variable 73 @param defvalue The default-value 74 */ 75 ConfigValueContainer::ConfigValueContainer(ConfigFileType type, Identifier* identifier, const std::string& varname, const std::vector<MultiTypeMath>& defvalue) 76 { 77 this->type_ = type; 78 this->identifier_ = identifier; 79 this->sectionname_ = identifier->getName(); 55 80 this->varname_ = varname; 56 81 57 this->valueToString(&this->defvalueString_, defvalue); // Try to convert the default-value to a string 58 this->searchConfigFileLine(); // Search the entry in the config-file 59 60 std::string valueString = this->parseValueString(!(defvalue.isA(MT_string) || defvalue.isA(MT_constchar))); // Parses the value string from the config-file-entry 61 if (!this->parseString(valueString, defvalue)) // Try to convert the string to a value 62 this->resetConfigFileEntry(); // The conversion failed 63 } 64 65 /** 66 @brief Converts a value to a string. 67 @param output The string to write to 68 @param input The value to convert 69 @return True if the converson was successful 70 */ 71 bool ConfigValueContainer::valueToString(std::string* output, MultiTypeMath& input) 72 { 73 if (input.getType() == MT_int) 74 return ConvertValue(output, input.getInt(), std::string("0")); 75 else if (input.getType() == MT_uint) 76 return ConvertValue(output, input.getUnsignedInt(), std::string("0")); 77 else if (input.getType() == MT_char) 78 return ConvertValue(output, (int)input.getChar(), std::string("0")); 79 else if (input.getType() == MT_uchar) 80 return ConvertValue(output, (unsigned int)input.getUnsignedChar(), std::string("0")); 81 else if (input.getType() == MT_short) 82 return ConvertValue(output, input.getShort(), std::string("0")); 83 else if (input.getType() == MT_ushort) 84 return ConvertValue(output, input.getUnsignedShort(), std::string("0")); 85 else if (input.getType() == MT_long) 86 return ConvertValue(output, input.getLong(), std::string("0")); 87 else if (input.getType() == MT_ulong) 88 return ConvertValue(output, input.getUnsignedLong(), std::string("0")); 89 else if (input.getType() == MT_float) 90 return ConvertValue(output, input.getFloat(), std::string("0.000000")); 91 else if (input.getType() == MT_double) 92 return ConvertValue(output, input.getDouble(), std::string("0.000000")); 93 else if (input.getType() == MT_longdouble) 94 return ConvertValue(output, input.getChar(), std::string("0.000000")); 95 else if (input.getType() == MT_bool) 96 { 97 if (input.getBool()) 98 (*output) = "true"; 82 this->valueVector_ = defvalue; 83 this->bAddedDescription_ = false; 84 this->bIsVector_ = true; 85 86 if (defvalue.size() > 0) 87 this->value_ = defvalue[0]; 88 89 for (unsigned int i = 0; i < defvalue.size(); i++) 90 ConfigFileManager::getSingleton()->getValue(this->type_, this->sectionname_, this->varname_, i, defvalue[i].toString(), this->value_.isA(MT_string)); 91 92 for (unsigned int i = 0; i < defvalue.size(); i++) 93 this->defvalueStringVector_.push_back(defvalue[i].toString()); 94 95 this->update(); 96 } 97 98 /** 99 @brief Adds a new entry to the end of the vector. 100 @param input The new entry 101 @return True if the new entry was successfully added 102 */ 103 bool ConfigValueContainer::add(const std::string& input) 104 { 105 if (this->bIsVector_) 106 return this->set(this->valueVector_.size(), input); 107 108 COUT(1) << "Error: Config-value '" << this->varname_ << "' in " << this->sectionname_ << " is not a vector." << std::endl; 109 return false; 110 } 111 112 /** 113 @brief Removes an existing entry from the vector. 114 @param index The index of the entry 115 @return True if the entry was removed 116 */ 117 bool ConfigValueContainer::remove(unsigned int index) 118 { 119 if (this->bIsVector_) 120 { 121 if (index < this->valueVector_.size()) 122 { 123 this->valueVector_.erase(this->valueVector_.begin() + index); 124 for (unsigned int i = index; i < this->valueVector_.size(); i++) 125 ConfigFileManager::getSingleton()->setValue(this->type_, this->sectionname_, this->varname_, i, this->valueVector_[i], this->value_.isA(MT_string)); 126 ConfigFileManager::getSingleton()->deleteVectorEntries(this->type_, this->sectionname_, this->varname_, this->valueVector_.size()); 127 128 return true; 129 } 130 COUT(1) << "Error: Invalid vector-index." << std::endl; 131 } 132 133 COUT(1) << "Error: Config-value '" << this->varname_ << "' in " << this->sectionname_ << " is not a vector." << std::endl; 134 return false; 135 } 136 137 /** 138 @brief Assigns a new value to the config-value of all objects and writes the change into the config-file. 139 @param input The new value 140 @return True if the new value was successfully assigned 141 */ 142 bool ConfigValueContainer::set(const std::string& input) 143 { 144 if (this->bIsVector_) 145 { 146 SubString token(input, " ", "", true, '"', false, '(', ')', false, '\0'); 147 int index = -1; 148 bool success = false; 149 150 if (token.size() > 0) 151 success = ConvertValue(&index, token[0]); 152 153 if (!success || index < 0 || index > MAX_VECTOR_INDEX) 154 { 155 if (!success) 156 { 157 COUT(1) << "Error: Config-value '" << this->varname_ << "' in " << this->sectionname_ << " is a vector." << std::endl; 158 } 159 else 160 { 161 COUT(1) << "Error: Invalid vector-index." << std::endl; 162 } 163 return false; 164 } 165 166 if (token.size() >= 2) 167 return this->set(index, token.subSet(1).join()); 99 168 else 100 (*output) = "false"; 101 102 return true; 103 } 104 else if (input.getType() == MT_constchar) 105 { 106 (*output) = "\"" + input.getString() + "\""; 107 return true; 108 } 109 else if (input.getType() == MT_string) 110 { 111 (*output) = "\"" + input.getString() + "\""; 112 return true; 113 } 114 else if (input.getType() == MT_vector2) 115 { 116 std::ostringstream ostream; 117 if (ostream << "(" << input.getVector2().x << "," << input.getVector2().y << ")") 118 { 119 (*output) = ostream.str(); 120 return true; 121 } 122 else 123 { 124 (*output) = "(0,0)"; 125 return false; 126 } 127 } 128 else if (input.getType() == MT_vector3) 129 { 130 std::ostringstream ostream; 131 if (ostream << "(" << input.getVector3().x << "," << input.getVector3().y << "," << input.getVector3().z << ")") 132 { 133 (*output) = ostream.str(); 134 return true; 135 } 136 else 137 { 138 (*output) = "(0,0,0)"; 139 return false; 140 } 141 } 142 else if (input.getType() == MT_colourvalue) 143 { 144 std::ostringstream ostream; 145 if (ostream << "(" << input.getColourValue().r << "," << input.getColourValue().g << "," << input.getColourValue().b << "," << input.getColourValue().a << ")") 146 { 147 (*output) = ostream.str(); 148 return true; 149 } 150 else 151 { 152 (*output) = "(0,0,0,0)"; 153 return false; 154 } 155 } 156 else if (input.getType() == MT_quaternion) 157 { 158 std::ostringstream ostream; 159 if (ostream << "(" << input.getQuaternion().w << "," << input.getQuaternion().x << "," << input.getQuaternion().y << "," << input.getQuaternion().z << ")") 160 { 161 (*output) = ostream.str(); 162 return true; 163 } 164 else 165 { 166 (*output) = "(0,0,0,0)"; 167 return false; 168 } 169 } 170 else if (input.getType() == MT_radian) 171 return ConvertValue(output, input.getRadian(), std::string("0.000000")); 172 else if (input.getType() == MT_degree) 173 return ConvertValue(output, input.getDegree(), std::string("0.000000")); 174 175 return false; 169 return this->set(index, ""); 170 } 171 172 bool success = this->tset(input); 173 ConfigFileManager::getSingleton()->setValue(this->type_, this->sectionname_, this->varname_, input, this->value_.isA(MT_string)); 174 return success; 175 } 176 177 /** 178 @brief Assigns a new value to the config-value of all objects and writes the change into the config-file. 179 @param index The index in the vector 180 @param input The new value 181 @return True if the new value was successfully assigned 182 */ 183 bool ConfigValueContainer::set(unsigned int index, const std::string& input) 184 { 185 if (this->bIsVector_) 186 { 187 bool success = this->tset(index, input); 188 ConfigFileManager::getSingleton()->setValue(this->type_, this->sectionname_, this->varname_, index, input, this->value_.isA(MT_string)); 189 return success; 190 } 191 192 COUT(1) << "Error: Config-value '" << this->varname_ << "' in " << this->sectionname_ << " is not a vector." << std::endl; 193 return false; 194 } 195 196 /** 197 @brief Assigns a new value to the config-value of all objects, but doesn't change the config-file (t stands for temporary). 198 @param input The new value 199 @return True if the new value was successfully assigned 200 */ 201 bool ConfigValueContainer::tset(const std::string& input) 202 { 203 bool success = this->parse(input); 204 if (this->identifier_) 205 this->identifier_->updateConfigValues(); 206 return success; 207 } 208 209 /** 210 @brief Assigns a new value to the config-value of all objects, but doesn't change the config-file (t stands for temporary). 211 @param index The index in the vector 212 @param input The new value 213 @return True if the new value was successfully assigned 214 */ 215 bool ConfigValueContainer::tset(unsigned int index, const std::string& input) 216 { 217 if (this->bIsVector_) 218 { 219 bool success = this->parse(index, input); 220 if (this->identifier_) 221 this->identifier_->updateConfigValues(); 222 return success; 223 } 224 225 COUT(1) << "Error: Config-value '" << this->varname_ << "' in " << this->sectionname_ << " is not a vector." << std::endl; 226 return false; 227 } 228 229 /** 230 @brief Sets the value of the variable back to the default value and resets the config-file entry. 231 */ 232 bool ConfigValueContainer::reset() 233 { 234 if (!this->bIsVector_) 235 return this->set(this->defvalueString_); 236 else 237 { 238 bool success = true; 239 for (unsigned int i = 0; i < this->defvalueStringVector_.size(); i++) 240 if (!this->set(i, this->defvalueStringVector_[i])) 241 success = false; 242 ConfigFileManager::getSingleton()->deleteVectorEntries(this->type_, this->sectionname_, this->varname_, this->defvalueStringVector_.size()); 243 return success; 244 } 245 } 246 247 /** 248 @brief Retrieves the configured value from the currently loaded config-file. 249 */ 250 void ConfigValueContainer::update() 251 { 252 if (!this->bIsVector_) 253 this->value_.fromString(ConfigFileManager::getSingleton()->getValue(this->type_, this->sectionname_, this->varname_, this->defvalueString_, this->value_.isA(MT_string))); 254 else 255 { 256 this->valueVector_.clear(); 257 for (unsigned int i = 0; i < ConfigFileManager::getSingleton()->getVectorSize(this->type_, this->sectionname_, this->varname_); i++) 258 { 259 this->value_.fromString(ConfigFileManager::getSingleton()->getValue(this->type_, this->sectionname_, this->varname_, i, this->defvalueStringVector_[i], this->value_.isA(MT_string))); 260 this->valueVector_.push_back(this->value_); 261 } 262 } 176 263 } 177 264 … … 181 268 @return True if the string was successfully parsed 182 269 */ 183 bool ConfigValueContainer::parseString(const std::string& input, MultiTypeMath& defvalue) 184 { 185 if (defvalue.getType() == MT_int) 186 return this->parseString(input, defvalue.getInt()); 187 else if (defvalue.getType() == MT_uint) 188 return this->parseString(input, defvalue.getUnsignedInt()); 189 else if (defvalue.getType() == MT_char) 190 return this->parseString(input, defvalue.getChar()); 191 else if (defvalue.getType() == MT_uchar) 192 return this->parseString(input, defvalue.getUnsignedChar()); 193 else if (defvalue.getType() == MT_short) 194 return this->parseString(input, defvalue.getShort()); 195 else if (defvalue.getType() == MT_ushort) 196 return this->parseString(input, defvalue.getUnsignedShort()); 197 else if (defvalue.getType() == MT_long) 198 return this->parseString(input, defvalue.getLong()); 199 else if (defvalue.getType() == MT_ulong) 200 return this->parseString(input, defvalue.getUnsignedLong()); 201 else if (defvalue.getType() == MT_float) 202 return this->parseString(input, defvalue.getFloat()); 203 else if (defvalue.getType() == MT_double) 204 return this->parseString(input, defvalue.getDouble()); 205 else if (defvalue.getType() == MT_longdouble) 206 return this->parseString(input, defvalue.getLongDouble()); 207 else if (defvalue.getType() == MT_bool) 208 return this->parseString(input, defvalue.getBool()); 209 else if (defvalue.getType() == MT_constchar) 210 return this->parseString(input, defvalue.getString()); 211 else if (defvalue.getType() == MT_string) 212 return this->parseString(input, defvalue.getString()); 213 else if (defvalue.getType() == MT_vector2) 214 return this->parseString(input, defvalue.getVector2()); 215 else if (defvalue.getType() == MT_vector3) 216 return this->parseString(input, defvalue.getVector3()); 217 else if (defvalue.getType() == MT_colourvalue) 218 return this->parseString(input, defvalue.getColourValue()); 219 else if (defvalue.getType() == MT_quaternion) 220 return this->parseString(input, defvalue.getQuaternion()); 221 else if (defvalue.getType() == MT_radian) 222 return this->parseString(input, defvalue.getRadian()); 223 else if (defvalue.getType() == MT_degree) 224 return this->parseString(input, defvalue.getDegree()); 225 226 return false; 227 } 228 229 /** 230 @brief Parses a given std::string into a value of the type int and assigns it to the right variable. If the conversion failed, the default-value gets assigned. 231 @param input The string to convert 232 @param defvalue The default-value 233 @return True if the string was successfully parsed 234 */ 235 bool ConfigValueContainer::parseString(const std::string& input, int defvalue) 236 { 237 int temp; 238 bool success = ConvertValue(&temp, input, defvalue); 239 this->value_.setValue(temp); 240 return success; 241 } 242 243 /** 244 @brief Parses a given std::string into a value of the type unsigned int and assigns it to the right variable. If the conversion failed, the default-value gets assigned. 245 @param input The string to convert 246 @param defvalue The default-value 247 @return True if the string was successfully parsed 248 */ 249 bool ConfigValueContainer::parseString(const std::string& input, unsigned int defvalue) 250 { 251 unsigned int temp; 252 bool success = ConvertValue(&temp, input, defvalue); 253 this->value_.setValue(temp); 254 return success; 255 } 256 257 /** 258 @brief Parses a given std::string into a value of the type char and assigns it to the right variable. If the conversion failed, the default-value gets assigned. 259 @param input The string to convert 260 @param defvalue The default-value 261 @return True if the string was successfully parsed 262 */ 263 bool ConfigValueContainer::parseString(const std::string& input, char defvalue) 264 { 265 // I used value_int_ instead of value_char_ to avoid number <-> char confusion in the config-file 266 int temp; 267 bool success = ConvertValue(&temp, input, (int)defvalue); 268 this->value_.setValue((char)temp); 269 return success; 270 } 271 272 /** 273 @brief Parses a given std::string into a value of the type unsigned char and assigns it to the right variable. If the conversion failed, the default-value gets assigned. 274 @param input The string to convert 275 @param defvalue The default-value 276 @return True if the string was successfully parsed 277 */ 278 bool ConfigValueContainer::parseString(const std::string& input, unsigned char defvalue) 279 { 280 // I used value_uint_ instead of value_uchar_ to avoid number <-> char confusion in the config-file 281 unsigned int temp; 282 bool success = ConvertValue(&temp, input, (unsigned int)defvalue); 283 this->value_.setValue((unsigned char)temp); 284 return success; 285 } 286 287 /** 288 @brief Parses a given std::string into a value of the type short and assigns it to the right variable. If the conversion failed, the default-value gets assigned. 289 @param input The string to convert 290 @param defvalue The default-value 291 @return True if the string was successfully parsed 292 */ 293 bool ConfigValueContainer::parseString(const std::string& input, short defvalue) 294 { 295 short temp; 296 bool success = ConvertValue(&temp, input, defvalue); 297 this->value_.setValue(temp); 298 return success; 299 } 300 301 /** 302 @brief Parses a given std::string into a value of the type unsigned short and assigns it to the right variable. If the conversion failed, the default-value gets assigned. 303 @param input The string to convert 304 @param defvalue The default-value 305 @return True if the string was successfully parsed 306 */ 307 bool ConfigValueContainer::parseString(const std::string& input, unsigned short defvalue) 308 { 309 unsigned short temp; 310 bool success = ConvertValue(&temp, input, defvalue); 311 this->value_.setValue(temp); 312 return success; 313 } 314 315 /** 316 @brief Parses a given std::string into a value of the type long and assigns it to the right variable. If the conversion failed, the default-value gets assigned. 317 @param input The string to convert 318 @param defvalue The default-value 319 @return True if the string was successfully parsed 320 */ 321 bool ConfigValueContainer::parseString(const std::string& input, long defvalue) 322 { 323 long temp; 324 bool success = ConvertValue(&temp, input, defvalue); 325 this->value_.setValue(temp); 326 return success; 327 } 328 329 /** 330 @brief Parses a given std::string into a value of the type unsigned long and assigns it to the right variable. If the conversion failed, the default-value gets assigned. 331 @param input The string to convert 332 @param defvalue The default-value 333 @return True if the string was successfully parsed 334 */ 335 bool ConfigValueContainer::parseString(const std::string& input, unsigned long defvalue) 336 { 337 unsigned long temp; 338 bool success = ConvertValue(&temp, input, defvalue); 339 this->value_.setValue(temp); 340 return success; 341 } 342 343 /** 344 @brief Parses a given std::string into a value of the type float and assigns it to the right variable. If the conversion failed, the default-value gets assigned. 345 @param input The string to convert 346 @param defvalue The default-value 347 @return True if the string was successfully parsed 348 */ 349 bool ConfigValueContainer::parseString(const std::string& input, float defvalue) 350 { 351 float temp; 352 bool success = ConvertValue(&temp, input, defvalue); 353 this->value_.setValue(temp); 354 return success; 355 } 356 357 /** 358 @brief Parses a given std::string into a value of the type double and assigns it to the right variable. If the conversion failed, the default-value gets assigned. 359 @param input The string to convert 360 @param defvalue The default-value 361 @return True if the string was successfully parsed 362 */ 363 bool ConfigValueContainer::parseString(const std::string& input, double defvalue) 364 { 365 double temp; 366 bool success = ConvertValue(&temp, input, defvalue); 367 this->value_.setValue(temp); 368 return success; 369 } 370 371 /** 372 @brief Parses a given std::string into a value of the type long double and assigns it to the right variable. If the conversion failed, the default-value gets assigned. 373 @param input The string to convert 374 @param defvalue The default-value 375 @return True if the string was successfully parsed 376 */ 377 bool ConfigValueContainer::parseString(const std::string& input, long double defvalue) 378 { 379 long double temp; 380 bool success = ConvertValue(&temp, input, defvalue); 381 this->value_.setValue(temp); 382 return success; 383 } 384 385 /** 386 @brief Parses a given std::string into a value of the type bool and assigns it to the right variable. If the conversion failed, the default-value gets assigned. 387 @param input The string to convert 388 @param defvalue The default-value 389 @return True if the string was successfully parsed 390 */ 391 bool ConfigValueContainer::parseString(const std::string& input, bool defvalue) 392 { 393 // Try to parse the value-string - is it a word? 394 if (input.find("true") < input.size() 395 || input.find("True") < input.size() 396 || input.find("yes") < input.size() 397 || input.find("Yes") < input.size()) 398 this->value_.setValue(true); 399 else if (input.find("false") < input.size() 400 || input.find("False") < input.size() 401 || input.find("no") < input.size() 402 || input.find("No") < input.size()) 403 this->value_.setValue(false); 404 else 405 { 406 // Its not a known word - is it a number? 407 bool temp; 408 bool success = ConvertValue(&temp, input, defvalue); 409 this->value_.setValue(temp); 410 return success; 411 } 412 413 return true; 414 } 415 416 /** 417 @brief Parses a given std::string into a value of the type std::string and assigns it to the right variable. If the conversion failed, the default-value gets assigned. 418 @param input The string to convert 419 @param defvalue The default-value 420 @return True if the string was successfully parsed 421 */ 422 bool ConfigValueContainer::parseString(const std::string& input, const std::string& defvalue) 423 { 424 // Strip the quotes 425 unsigned int pos1 = input.find("\"") + 1; 426 unsigned int pos2 = input.find("\"", pos1); 427 428 // Check if the entry was correctly quoted 429 if (pos1 < input.length() && pos2 < input.length() && !(input.find("\"", pos2 + 1) < input.length())) 430 { 431 // It was - get the string between the quotes 432 this->value_.setValue(input.substr(pos1, pos2 - pos1)); 433 return true; 434 } 435 436 // It wasn't - use the default-value and restore the entry in the config-file. 437 this->value_.setValue(defvalue); 438 return false; 439 } 440 441 /** 442 @brief Parses a given std::string into a value of the type const char* and assigns it to the right variable. If the conversion failed, the default-value gets assigned. 443 @param input The string to convert 444 @param defvalue The default-value 445 @return True if the string was successfully parsed 446 */ 447 bool ConfigValueContainer::parseString(const std::string& input, const char* defvalue) 448 { 449 // Strip the quotes 450 unsigned int pos1 = input.find("\"") + 1; 451 unsigned int pos2 = input.find("\"", pos1); 452 453 // Check if the entry was correctly quoted 454 if (pos1 < input.length() && pos2 < input.length() && !(input.find("\"", pos2 + 1) < input.length())) 455 { 456 // It was - get the string between the quotes 457 this->value_.setValue(input.substr(pos1, pos2 - pos1)); 458 return true; 459 } 460 461 // It wasn't - use the default-value and restore the entry in the config-file. 462 this->value_.setValue(defvalue); 463 return false; 464 } 465 466 /** 467 @brief Parses a given std::string into a value of the type _Vector2 and assigns it to the right variable. If the conversion failed, the default-value gets assigned. 468 @param input The string to convert 469 @param defvalue The default-value 470 @return True if the string was successfully parsed 471 */ 472 bool ConfigValueContainer::parseString(const std::string& input, const Vector2& defvalue) 473 { 474 // Strip the value-string 475 unsigned int pos1 = input.find("(") + 1; 476 unsigned int pos2 = input.find(")", pos1); 477 478 // Try to convert the stripped value-string to Vector2 479 if (pos1 < input.length() && pos2 < input.length() && pos1 < pos2) 480 { 481 std::vector<std::string> tokens = tokenize(input.substr(pos1, pos2 - pos1), ","); 482 if (!ConvertValue(&this->value_.getVector2().x, tokens[0])) 483 { 484 this->value_.setValue(defvalue); 485 return false; 486 } 487 if (!ConvertValue(&this->value_.getVector2().y, tokens[1])) 488 { 489 this->value_.setValue(defvalue); 490 return false; 491 } 492 493 return true; 494 } 495 496 this->value_.setValue(defvalue); 497 return false; 498 } 499 500 /** 501 @brief Parses a given std::string into a value of the type Vector3 and assigns it to the right variable. If the conversion failed, the default-value gets assigned. 502 @param input The string to convert 503 @param defvalue The default-value 504 @return True if the string was successfully parsed 505 */ 506 bool ConfigValueContainer::parseString(const std::string& input, const Vector3& defvalue) 507 { 508 // Strip the value-string 509 unsigned int pos1 = input.find("(") + 1; 510 unsigned int pos2 = input.find(")", pos1); 511 512 // Try to convert the stripped value-string to Vector3 513 if (pos1 < input.length() && pos2 < input.length() && pos1 < pos2) 514 { 515 std::vector<std::string> tokens = tokenize(input.substr(pos1, pos2 - pos1), ","); 516 if (!ConvertValue(&this->value_.getVector3().x, tokens[0])) 517 { 518 this->value_.setValue(defvalue); 519 return false; 520 } 521 if (!ConvertValue(&this->value_.getVector3().y, tokens[1])) 522 { 523 this->value_.setValue(defvalue); 524 return false; 525 } 526 if (!ConvertValue(&this->value_.getVector3().z, tokens[2])) 527 { 528 this->value_.setValue(defvalue); 529 return false; 530 } 531 532 return true; 533 } 534 535 this->value_.setValue(defvalue); 536 return false; 537 } 538 539 /** 540 @brief Parses a given std::string into a value of the type ColourValue and assigns it to the right variable. If the conversion failed, the default-value gets assigned. 541 @param input The string to convert 542 @param defvalue The default-value 543 @return True if the string was successfully parsed 544 */ 545 bool ConfigValueContainer::parseString(const std::string& input, const ColourValue& defvalue) 546 { 547 // Strip the value-string 548 unsigned int pos1 = input.find("(") + 1; 549 unsigned int pos2 = input.find(")", pos1); 550 551 // Try to convert the stripped value-string to Vector3 552 if (pos1 < input.length() && pos2 < input.length() && pos1 < pos2) 553 { 554 std::vector<std::string> tokens = tokenize(input.substr(pos1, pos2 - pos1), ","); 555 if (!ConvertValue(&this->value_.getColourValue().r, tokens[0])) 556 { 557 this->value_.setValue(defvalue); 558 return false; 559 } 560 if (!ConvertValue(&this->value_.getColourValue().g, tokens[1])) 561 { 562 this->value_.setValue(defvalue); 563 return false; 564 } 565 if (!ConvertValue(&this->value_.getColourValue().b, tokens[2])) 566 { 567 this->value_.setValue(defvalue); 568 return false; 569 } 570 if (!ConvertValue(&this->value_.getColourValue().a, tokens[3])) 571 { 572 this->value_.setValue(defvalue); 573 return false; 574 } 575 576 return true; 577 } 578 579 this->value_.setValue(defvalue); 580 return false; 581 } 582 583 /** 584 @brief Parses a given std::string into a value of the type Quaternion and assigns it to the right variable. If the conversion failed, the default-value gets assigned. 585 @param input The string to convert 586 @param defvalue The default-value 587 @return True if the string was successfully parsed 588 */ 589 bool ConfigValueContainer::parseString(const std::string& input, const Quaternion& defvalue) 590 { 591 // Strip the value-string 592 unsigned int pos1 = input.find("(") + 1; 593 unsigned int pos2 = input.find(")", pos1); 594 595 // Try to convert the stripped value-string to Vector3 596 if (pos1 < input.length() && pos2 < input.length() && pos1 < pos2) 597 { 598 std::vector<std::string> tokens = tokenize(input.substr(pos1, pos2 - pos1), ","); 599 if (!ConvertValue(&this->value_.getQuaternion().w, tokens[0])) 600 { 601 this->value_.setValue(defvalue); 602 return false; 603 } 604 if (!ConvertValue(&this->value_.getQuaternion().x, tokens[1])) 605 { 606 this->value_.setValue(defvalue); 607 return false; 608 } 609 if (!ConvertValue(&this->value_.getQuaternion().y, tokens[2])) 610 { 611 this->value_.setValue(defvalue); 612 return false; 613 } 614 if (!ConvertValue(&this->value_.getQuaternion().z, tokens[3])) 615 { 616 this->value_.setValue(defvalue); 617 return false; 618 } 619 620 return true; 621 } 622 623 this->value_.setValue(defvalue); 624 return false; 625 } 626 627 /** 628 @brief Parses a given std::string into a value of the type long double and assigns it to the right variable. If the conversion failed, the default-value gets assigned. 629 @param input The string to convert 630 @param defvalue The default-value 631 @return True if the string was successfully parsed 632 */ 633 bool ConfigValueContainer::parseString(const std::string& input, const Radian& defvalue) 634 { 635 return ConvertValue(&this->value_.getRadian(), input, defvalue); 636 } 637 638 /** 639 @brief Parses a given std::string into a value of the type long double and assigns it to the right variable. If the conversion failed, the default-value gets assigned. 640 @param input The string to convert 641 @param defvalue The default-value 642 @return True if the string was successfully parsed 643 */ 644 bool ConfigValueContainer::parseString(const std::string& input, const Degree& defvalue) 645 { 646 return ConvertValue(&this->value_.getDegree(), input, defvalue); 647 } 648 649 /** 650 @brief Sets the corresponding entry in the config-file back to the default value. 651 */ 652 void ConfigValueContainer::resetConfigFileEntry() 653 { 654 (*this->configFileLine_) = this->varname_ + "=" + this->defvalueString_; 655 ConfigValueContainer::writeConfigFile(CONFIGFILEPATH); 656 } 657 658 /** 659 @brief Sets the value of the variable back to the default value and resets the config-file entry. 660 */ 661 void ConfigValueContainer::resetConfigValue() 662 { 663 this->parseString(this->defvalueString_, this->value_); 664 this->resetConfigFileEntry(); 665 } 666 667 /** 668 @brief Searches the corresponding entry in the config-file and creates it, if there is no entry. 669 */ 670 void ConfigValueContainer::searchConfigFileLine() 671 { 672 // Read the file if needed 673 if (!ConfigValueContainer::finishedReadingConfigFile()) 674 ConfigValueContainer::readConfigFile(CONFIGFILEPATH); 675 676 // The string of the section we're searching 677 std::string section = ""; 678 section.append("["); 679 section.append(this->classname_); 680 section.append("]"); 681 682 // Iterate through all config-file-lines 683 bool success = false; 684 std::list<std::string>::iterator it1; 685 for(it1 = ConfigValueContainer::getConfigFileLines().begin(); it1 != ConfigValueContainer::getConfigFileLines().end(); ++it1) 686 { 687 // Don't try to parse comments 688 if (this->isComment(*it1)) 689 continue; 690 691 if ((*it1).find(section) < (*it1).length()) 692 { 693 // We found the right section 694 bool bLineIsEmpty = false; 695 std::list<std::string>::iterator positionToPutNewLineAt; 696 697 // Iterate through all lines in the section 698 std::list<std::string>::iterator it2; 699 for(it2 = ++it1; it2 != ConfigValueContainer::getConfigFileLines().end(); ++it2) 700 { 701 // Don't try to parse comments 702 if (this->isComment(*it2)) 703 continue; 704 705 // This if-else block is used to write a new line right after the last line of the 706 // section but in front of the following empty lines before the next section. 707 // (So this helps to keep a nice formatting with empty-lines between sections in the config-file) 708 if (this->isEmpty(*it2)) 709 { 710 if (!bLineIsEmpty) 711 { 712 bLineIsEmpty = true; 713 positionToPutNewLineAt = it2; 714 } 715 } 716 else 717 { 718 if (!bLineIsEmpty) 719 positionToPutNewLineAt = it2; 720 721 bLineIsEmpty = false; 722 } 723 724 // Look out for the beginning of the next section 725 unsigned int open = (*it2).find("["); 726 unsigned int close = (*it2).find("]"); 727 if ((open < (*it2).length()) && (close < (*it2).length()) && (open < close)) 728 { 729 // The next section startet, so our line isn't yet in the file - now we add it and safe the file 730 this->configFileLine_ = this->getConfigFileLines().insert(positionToPutNewLineAt, this->varname_ + "=" + this->defvalueString_); 731 ConfigValueContainer::writeConfigFile(CONFIGFILEPATH); 732 success = true; 733 break; 734 } 735 736 // Look out for the variable-name 737 if ((*it2).find(this->varname_) < (*it2).length()) 738 { 739 // We found the right line - safe it and return 740 this->configFileLine_ = it2; 741 success = true; 742 break; 743 } 744 } 745 746 // Check if we succeeded 270 bool ConfigValueContainer::parse(const std::string& input) 271 { 272 if (this->bIsVector_) 273 { 274 SubString token(input, " ", "", true, '"', false, '(', ')', false, '\0'); 275 int index = -1; 276 bool success = false; 277 278 if (token.size() > 0) 279 success = ConvertValue(&index, token[0]); 280 281 if (!success || index < 0 || index > MAX_VECTOR_INDEX) 282 { 747 283 if (!success) 748 284 { 749 // Looks like we found the right section, but the file ended without containing our variable - so we add it and safe the file 750 this->configFileLine_ = this->getConfigFileLines().insert(positionToPutNewLineAt, this->varname_ + "=" + this->defvalueString_); 751 ConfigValueContainer::writeConfigFile(CONFIGFILEPATH); 752 success = true; 285 COUT(1) << "Error: Config-value '" << this->varname_ << "' in " << this->sectionname_ << " is a vector." << std::endl; 753 286 } 754 break; 755 } 756 } 757 758 // Check if we succeeded 759 if (!success) 760 { 761 // We obviously didn't found the right section, so we'll create it 762 this->getConfigFileLines().push_back("[" + this->classname_ + "]"); // Create the section 763 this->getConfigFileLines().push_back(this->varname_ + "=" + this->defvalueString_); // Create the line 764 this->configFileLine_ = --this->getConfigFileLines().end(); // Set the pointer to the last element 765 success = true; 766 this->getConfigFileLines().push_back(""); // Add an empty line - this is needed for the algorithm in the searchConfigFileLine-function 767 ConfigValueContainer::writeConfigFile(CONFIGFILEPATH); // Save the changed config-file 768 } 769 } 770 771 /** 772 @brief Determines if a line in the config-file is a comment. 773 @param line The line to check 774 @return True = it's a comment 775 */ 776 bool ConfigValueContainer::isComment(const std::string& line) 777 { 778 // Strip the line, whitespaces are disturbing 779 std::string teststring = getStrippedLine(line); 780 781 // There are four possible comment-symbols: 782 // 1) #comment in script-language style 783 // 2) %comment in matlab style 784 // 3) ;comment in unreal tournament config-file style 785 // 4) //comment in code style 786 if (teststring[0] == '#' || teststring[0] == '%' || teststring[0] == ';' || (teststring[0] == '/' && teststring[0] == '/')) 287 else 288 { 289 COUT(1) << "Error: Invalid vector-index." << std::endl; 290 } 291 return false; 292 } 293 294 if (token.size() >= 2) 295 return this->parse(index, token.subSet(1).join()); 296 else 297 return this->parse(index, ""); 298 } 299 300 MultiTypeMath temp = this->value_; 301 if (temp.fromString(input)) 302 { 303 this->value_ = temp; 787 304 return true; 788 789 return false; 790 } 791 792 /** 793 @brief Determines if a line in the config-file is empty (contains only whitespaces). 794 @param line The line to check 795 @return True = it's empty 796 */ 797 bool ConfigValueContainer::isEmpty(const std::string& line) 798 { 799 return getStrippedLine(line) == ""; 800 } 801 802 /** 803 @brief Removes all whitespaces from a line. 804 @param line The line to strip 805 @return The stripped line 806 */ 807 std::string ConfigValueContainer::getStrippedLine(const std::string& line) 808 { 809 std::string output = line; 810 unsigned int pos; 811 while ((pos = output.find(" ")) < output.length()) 812 output.erase(pos, 1); 813 while ((pos = output.find("\t")) < output.length()) 814 output.erase(pos, 1); 815 816 return output; 817 } 818 819 /** 820 @brief Returns the part in the corresponding config-file-entry of the container that defines the value. 821 @param bStripped True = strip the value-string 822 @return The value-string 823 */ 824 std::string ConfigValueContainer::parseValueString(bool bStripped) 825 { 826 std::string output; 827 if (bStripped) 828 output = this->getStrippedLine(*this->configFileLine_); 829 else 830 output = *this->configFileLine_; 831 832 return output.substr(output.find("=") + 1); 833 } 834 835 /** 836 @brief Rreturns a list, containing all entrys in the config-file. 837 @return The list 838 */ 839 std::list<std::string>& ConfigValueContainer::getConfigFileLines() 840 { 841 // This is done to avoid problems while executing this code before main() 842 static std::list<std::string> configFileLinesStaticReference = std::list<std::string>(); 843 return configFileLinesStaticReference; 844 } 845 846 /** 847 @brief Returns true if the ConfigFile is read and stored into the ConfigFile-lines-list. 848 @param finished This is used to change the state 849 @return True if the ConfigFile is read and stored into the ConfigFile-lines-list 850 */ 851 bool ConfigValueContainer::finishedReadingConfigFile(bool finished) 852 { 853 // This is done to avoid problems while executing this code before main() 854 static bool finishedReadingConfigFileStaticVariable = false; 855 856 if (finished) 857 finishedReadingConfigFileStaticVariable = true; 858 859 return finishedReadingConfigFileStaticVariable; 860 } 861 862 /** 863 @brief Reads the config-file and stores the lines in a list. 864 @param filename The name of the config-file 865 */ 866 void ConfigValueContainer::readConfigFile(const std::string& filename) 867 { 868 // This creates the file if it's not existing 869 std::ofstream createFile; 870 createFile.open(filename.c_str(), std::fstream::app); 871 createFile.close(); 872 873 // Open the file 874 std::ifstream file; 875 file.open(filename.c_str(), std::fstream::in); 876 877 if (!file.is_open()) 878 { 879 COUT(1) << "An error occurred in ConfigValueContainer.cc:" << std::endl; 880 COUT(1) << "Error: Couldn't open config-file " << filename << " to read the config values!" << std::endl; 881 return; 882 } 883 884 char line[1024]; 885 886 // Iterate through the file and add the lines into the list 887 while (file.good() && !file.eof()) 888 { 889 file.getline(line, 1024); 890 ConfigValueContainer::getConfigFileLines().push_back(line); 891 // std::cout << "### ->" << line << "<- : empty: " << isEmpty(line) << " comment: " << isComment(line) << std::endl; 892 } 893 894 // The last line is useless 895 ConfigValueContainer::getConfigFileLines().pop_back(); 896 897 // Add an empty line to the end of the file if needed 898 // this is needed for the algorithm in the searchConfigFileLine-function 899 if ((ConfigValueContainer::getConfigFileLines().size() > 0) && !isEmpty(*ConfigValueContainer::getConfigFileLines().rbegin())) 900 { 901 // std::cout << "### newline added" << std::endl; 902 ConfigValueContainer::getConfigFileLines().push_back(""); 903 } 904 905 file.close(); 906 907 ConfigValueContainer::finishedReadingConfigFile(true); 908 } 909 910 /** 911 @brief Writes the content of the list, containing all lines of the config-file, into the config-file. 912 @param filename The name of the config-file 913 */ 914 void ConfigValueContainer::writeConfigFile(const std::string& filename) 915 { 916 // Make sure we stored the config-file in the list 917 if (!ConfigValueContainer::finishedReadingConfigFile()) 918 ConfigValueContainer::readConfigFile(filename); 919 920 // Open the file 921 std::ofstream file; 922 file.open(filename.c_str(), std::fstream::out); 923 924 if (!file.is_open()) 925 { 926 COUT(1) << "An error occurred in ConfigValueContainer.cc:" << std::endl; 927 COUT(1) << "Error: Couldn't open config-file " << filename << " to write the config values!" << std::endl; 928 return; 929 } 930 931 // Iterate through the list an write the lines into the file 932 std::list<std::string>::iterator it; 933 for (it = ConfigValueContainer::getConfigFileLines().begin(); it != ConfigValueContainer::getConfigFileLines().end(); ++it) 934 { 935 file << (*it) << std::endl; 936 } 937 938 file.close(); 305 } 306 return false; 307 } 308 309 /** 310 @brief Parses a given std::string into a value of the type of the associated variable and assigns it. 311 @param index The index in the vector 312 @param input The string to convert 313 @return True if the string was successfully parsed 314 */ 315 bool ConfigValueContainer::parse(unsigned int index, const std::string& input) 316 { 317 if (this->bIsVector_) 318 { 319 if (index >= this->valueVector_.size()) 320 { 321 for (unsigned int i = this->valueVector_.size(); i <= index; i++) 322 { 323 this->valueVector_.push_back(MultiTypeMath()); 324 ConfigFileManager::getSingleton()->setValue(this->type_, this->sectionname_, this->varname_, i, this->valueVector_[i], this->value_.isA(MT_string)); 325 } 326 } 327 328 MultiTypeMath temp = this->value_; 329 if (temp.fromString(input)) 330 { 331 this->valueVector_[index] = temp; 332 return true; 333 } 334 return false; 335 } 336 337 COUT(1) << "Error: Config-value '" << this->varname_ << "' in " << this->sectionname_ << " is not a vector." << std::endl; 338 return false; 339 } 340 341 /** 342 @brief Parses a given std::string into a value of the type of the associated variable and assigns it. 343 @param input The string to convert 344 @param defvalue The default value to assign if the parsing fails 345 @return True if the string was successfully parsed 346 */ 347 bool ConfigValueContainer::parse(const std::string& input, const MultiTypeMath& defvalue) 348 { 349 if (this->parse(input)) 350 return true; 351 352 this->value_ = defvalue; 353 return false; 354 } 355 356 /** 357 @brief Parses a given std::string into a value of the type of the associated variable and assigns it. 358 @param index The index in the vector 359 @param input The string to convert 360 @param defvalue The default value to assign if the parsing fails 361 @return True if the string was successfully parsed 362 */ 363 bool ConfigValueContainer::parse(unsigned int index, const std::string& input, const MultiTypeMath& defvalue) 364 { 365 if (this->bIsVector_) 366 { 367 if (this->parse(index, input)) 368 return true; 369 370 this->valueVector_[index] = defvalue; 371 return false; 372 } 373 374 COUT(1) << "Error: Config-value '" << this->varname_ << "' in " << this->sectionname_ << " is not a vector." << std::endl; 375 return false; 939 376 } 940 377 … … 947 384 if (!this->bAddedDescription_) 948 385 { 949 this->description_ = std::string("ConfigValueDescription::" + this-> classname_+ "::" + this->varname_);386 this->description_ = std::string("ConfigValueDescription::" + this->identifier_->getName() + "::" + this->varname_); 950 387 AddLanguageEntry(this->description_, description); 951 388 this->bAddedDescription_ = true; -
code/trunk/src/orxonox/core/ConfigValueContainer.h
r871 r1052 43 43 #define _ConfigValueContainer_H__ 44 44 45 #include <list>46 45 #include <string> 46 #include <vector> 47 47 48 48 #include "CorePrereqs.h" … … 50 50 #include "util/Math.h" 51 51 #include "util/MultiTypeMath.h" 52 #include "ConfigFileManager.h" 52 53 53 54 namespace orxonox … … 72 73 { 73 74 public: 74 ConfigValueContainer(const std::string& classname, const std::string& varname, MultiTypeMath defvalue); 75 ConfigValueContainer(ConfigFileType type, Identifier* identifier, const std::string& varname, const MultiTypeMath& defvalue); 76 ConfigValueContainer(ConfigFileType type, Identifier* identifier, const std::string& varname, const std::vector<MultiTypeMath>& defvalue); 75 77 76 78 /** @brief Returns the configured value. @param value This is only needed to determine the right type. @return The value */ 77 /* template <typename T> 78 inline ConfigValueContainer& getValue(T& value) { this->value_.getValue(value); return *this; } 79 */ 80 inline ConfigValueContainer& getValue(int* value) { this->value_.getValue(value); return *this; } 81 inline ConfigValueContainer& getValue(unsigned int* value) { this->value_.getValue(value); return *this; } 82 inline ConfigValueContainer& getValue(char* value) { this->value_.getValue(value); return *this; } 83 inline ConfigValueContainer& getValue(unsigned char* value) { this->value_.getValue(value); return *this; } 84 inline ConfigValueContainer& getValue(short* value) { this->value_.getValue(value); return *this; } 85 inline ConfigValueContainer& getValue(unsigned short* value) { this->value_.getValue(value); return *this; } 86 inline ConfigValueContainer& getValue(long* value) { this->value_.getValue(value); return *this; } 87 inline ConfigValueContainer& getValue(unsigned long* value) { this->value_.getValue(value); return *this; } 88 inline ConfigValueContainer& getValue(float* value) { this->value_.getValue(value); return *this; } 89 inline ConfigValueContainer& getValue(double* value) { this->value_.getValue(value); return *this; } 90 inline ConfigValueContainer& getValue(long double* value) { this->value_.getValue(value); return *this; } 91 inline ConfigValueContainer& getValue(bool* value) { this->value_.getValue(value); return *this; } 92 inline ConfigValueContainer& getValue(std::string* value) { this->value_.getValue(value); return *this; } 93 inline ConfigValueContainer& getValue(const char** value) { this->value_.getValue(value); return *this; } 94 inline ConfigValueContainer& getValue(Vector2* value) { this->value_.getValue(value); return *this; } 95 inline ConfigValueContainer& getValue(Vector3* value) { this->value_.getValue(value); return *this; } 96 inline ConfigValueContainer& getValue(ColourValue* value) { this->value_.getValue(value); return *this; } 97 inline ConfigValueContainer& getValue(Quaternion* value) { this->value_.getValue(value); return *this; } 98 inline ConfigValueContainer& getValue(Radian* value) { this->value_.getValue(value); return *this; } 99 inline ConfigValueContainer& getValue(Degree* value) { this->value_.getValue(value); return *this; } 79 template <typename T> 80 inline ConfigValueContainer& getValue(T* value) 81 { this->value_.getValue(value); return *this; } 82 template <typename T> 83 inline ConfigValueContainer& getValue(std::vector<T>* value) 84 { 85 value->clear(); 86 for (unsigned int i = 0; i < this->valueVector_.size(); i++) 87 value->push_back(this->valueVector_[i]); 88 return *this; 89 } 90 91 inline const std::string& getName() const 92 { return this->varname_; } 93 inline bool isVector() const 94 { return this->bIsVector_; } 95 inline unsigned int getVectorSize() const 96 { return this->valueVector_.size(); } 100 97 101 98 void description(const std::string& description); 102 99 const std::string& getDescription() const; 103 100 104 bool parseString(const std::string& input, MultiTypeMath& defvalue); 105 bool valueToString(std::string* output, MultiTypeMath& input); 106 void resetConfigFileEntry(); 107 void resetConfigValue(); 101 bool add(const std::string& input); 102 bool remove(unsigned int index); 103 bool set(const std::string& input); 104 bool tset(const std::string& input); 105 bool reset(); 106 void update(); 108 107 109 static std::string getStrippedLine(const std::string& line); 110 static bool isEmpty(const std::string& line); 111 static bool isComment(const std::string& line); 108 /** @brief Converts the config-value to a string. @return The string */ 109 inline std::string toString() const 110 { return this->value_.toString(); } 111 /** @brief Returns the typename of the assigned config-value. @return The typename */ 112 inline std::string getTypename() const 113 { return this->value_.getTypename(); } 112 114 113 115 private: 114 bool parseString(const std::string& input, int defvalue); 115 bool parseString(const std::string& input, unsigned int defvalue); 116 bool parseString(const std::string& input, char defvalue); 117 bool parseString(const std::string& input, unsigned char defvalue); 118 bool parseString(const std::string& input, short defvalue); 119 bool parseString(const std::string& input, unsigned short defvalue); 120 bool parseString(const std::string& input, long defvalue); 121 bool parseString(const std::string& input, unsigned long defvalue); 122 bool parseString(const std::string& input, float defvalue); 123 bool parseString(const std::string& input, double defvalue); 124 bool parseString(const std::string& input, long double defvalue); 125 bool parseString(const std::string& input, bool defvalue); 126 bool parseString(const std::string& input, const std::string& defvalue); 127 bool parseString(const std::string& input, const char* defvalue); 128 bool parseString(const std::string& input, const Vector2& defvalue); 129 bool parseString(const std::string& input, const Vector3& defvalue); 130 bool parseString(const std::string& input, const ColourValue& defvalue); 131 bool parseString(const std::string& input, const Quaternion& defvalue); 132 bool parseString(const std::string& input, const Radian& defvalue); 133 bool parseString(const std::string& input, const Degree& defvalue); 116 bool parse(const std::string& input); 117 bool parse(const std::string& input, const MultiTypeMath& defvalue); 134 118 135 static std::list<std::string>& getConfigFileLines();136 static bool finishedReadingConfigFile(bool finished = false);137 void searchConfigFileLine();138 std::string parseValueString(bool bStripped = true);119 bool set(unsigned int index, const std::string& input); 120 bool tset(unsigned int index, const std::string& input); 121 bool parse(unsigned int index, const std::string& input); 122 bool parse(unsigned int index, const std::string& input, const MultiTypeMath& defvalue); 139 123 140 static void readConfigFile(const std::string& filename); 141 static void writeConfigFile(const std::string& filename); 124 bool bIsVector_; //!< True if the container contains a std::vector 142 125 143 std::string classname_; //!< The name of the class the variable belongs to 144 std::string varname_; //!< The name of the variable 145 std::string defvalueString_; //!< The string of the default-variable 126 ConfigFileType type_; //!< The type of the corresponding config-file 127 Identifier* identifier_; //!< The identifier of the class 128 std::string sectionname_; //!< The name of the class the variable belongs to 129 std::string varname_; //!< The name of the variable 130 std::string defvalueString_; //!< The string of the default-value 131 std::vector<std::string> defvalueStringVector_; //!< A vector, containg the strings of the default-values in case we're storing a vector 146 132 147 MultiTypeMath value_; //!< The value 133 MultiTypeMath value_; //!< The value 134 std::vector<MultiTypeMath> valueVector_; //!< A vector, containg the values in case we're storing a vector 148 135 149 std::list<std::string>::iterator configFileLine_; //!< An iterator, pointing to the entry of the variable in the config-file 150 151 bool bAddedDescription_; //!< True if a description was added 152 LanguageEntryLabel description_; //!< The description 136 bool bAddedDescription_; //!< True if a description was added 137 LanguageEntryLabel description_; //!< The description 153 138 }; 154 139 } -
code/trunk/src/orxonox/core/CoreIncludes.h
r871 r1052 28 28 /** 29 29 @file CoreIncludes.h 30 @brief Definition of macros and typedefs.30 @brief Definition of macros for Identifier and Factory. 31 31 32 32 Every class needs the RegisterObject(class) macro in its constructor. If the class is an interface … … 40 40 #define _CoreIncludes_H__ 41 41 42 #include "CorePrereqs.h"43 44 // All needed header-files45 42 #include "Identifier.h" 46 43 #include "ClassManager.h" 47 44 #include "Factory.h" 48 45 #include "ClassFactory.h" 49 #include "Iterator.h"50 #include "OrxonoxClass.h"51 #include "ConfigValueContainer.h"52 46 #include "Debug.h" 53 47 54 48 55 // All needed macros56 49 /** 57 50 @brief Intern macro, containing the common parts of RegisterObject and RegisterRootObject. … … 111 104 orxonox::Factory::getIdentifier(StringOrInt) 112 105 113 /**114 @brief Assigns the value, defined in the config-file, to the variable (or the default-value, if there is no entry in the file).115 @param varname The name of the variable116 @param defvalue The default-value of the variable117 */118 #define SetConfigValue(varname, defvalue) \119 orxonox::ConfigValueContainer* container##varname = this->getIdentifier()->getConfigValueContainer(#varname); \120 if (!container##varname) \121 { \122 container##varname = new orxonox::ConfigValueContainer(this->getIdentifier()->getName(), #varname, varname = defvalue); \123 this->getIdentifier()->addConfigValueContainer(#varname, container##varname); \124 } \125 container##varname->getValue(&varname)126 127 /**128 @brief Sets the variable and the config-file entry back to the previously defined default-value.129 @param varname The name of the variable130 */131 #define ResetConfigValue(varname) \132 orxonox::ConfigValueContainer* container##varname##reset = this->getIdentifier()->getConfigValueContainer(#varname); \133 if (container##varname##reset) \134 { \135 container##varname##reset->resetConfigValue(); \136 container##varname##reset->getValue(&varname); \137 } \138 else \139 COUT(2) << "Warning: Couldn't reset variable " << #varname << ", corresponding container doesn't exist." << std::endl140 141 106 #endif /* _CoreIncludes_H__ */ -
code/trunk/src/orxonox/core/CorePrereqs.h
r1024 r1052 65 65 namespace orxonox 66 66 { 67 #ifndef _XMLPort_Mode__ 68 #define _XMLPort_Mode__ 69 namespace XMLPort 70 { 71 enum Mode 72 { 73 LoadObject, 74 SaveObject 75 }; 76 } 77 #endif 78 67 79 typedef std::string LanguageEntryLabel; 68 80 … … 79 91 class ClassTreeMaskIterator; 80 92 class ClassTreeMaskNode; 93 class CommandEvaluation; 94 class CommandExecutor; 95 class ConfigFile; 96 class ConfigFileEntry; 97 class ConfigFileEntryComment; 98 class ConfigFileEntryValue; 99 class ConfigFileManager; 100 class ConfigFileSection; 81 101 class ConfigValueContainer; 82 class DebugLevel;102 class CoreSettings; 83 103 class Error; 84 104 class Executor; 105 template <class T> 106 class ExecutorMember; 107 class ExecutorStatic; 85 108 class Factory; 109 class Functor; 110 template <class T> 111 class FunctorMember; 112 class FunctorStatic; 86 113 class Identifier; 87 114 class IdentifierDistributor; 115 class InputBuffer; 116 class InputBufferListener; 88 117 class InputHandlerGame; 89 118 class InputHandlerGUI; … … 98 127 template <class T> 99 128 class MetaObjectListElement; 129 class Namespace; 130 class NamespaceNode; 100 131 template <class T> 101 132 class ObjectList; … … 104 135 class OrxonoxClass; 105 136 class OutputHandler; 137 class Shell; 106 138 template <class T> 107 139 class SubclassIdentifier; -
code/trunk/src/orxonox/core/Executor.cc
r871 r1052 29 29 #include "Executor.h" 30 30 #include "Language.h" 31 #include "util/ String.h"31 #include "util/Math.h" 32 32 33 33 namespace orxonox 34 34 { 35 Executor::Executor(Functor* functor, const std::string& name )35 Executor::Executor(Functor* functor, const std::string& name, AccessLevel::Level level) 36 36 { 37 37 this->functor_ = functor; 38 38 this->name_ = name; 39 this->accessLevel_ = level; 40 39 41 this->bAddedDescription_ = false; 40 42 this->bAddedDescriptionReturnvalue_ = false; 43 41 44 this->bAddedDescriptionParam_[0] = false; 42 45 this->bAddedDescriptionParam_[1] = false; … … 44 47 this->bAddedDescriptionParam_[3] = false; 45 48 this->bAddedDescriptionParam_[4] = false; 49 50 this->bAddedDefaultValue_[0] = false; 51 this->bAddedDefaultValue_[1] = false; 52 this->bAddedDefaultValue_[2] = false; 53 this->bAddedDefaultValue_[3] = false; 54 this->bAddedDefaultValue_[4] = false; 46 55 } 47 56 48 57 Executor::~Executor() 49 58 { 50 } 51 52 void Executor::setName(const std::string name) 53 { 54 this->name_ = name; 55 } 56 57 const std::string& Executor::getName() const 58 { 59 return this->name_; 60 } 61 62 void Executor::description(const std::string& description) 59 delete this->functor_; 60 } 61 62 bool Executor::parse(const std::string& params, const std::string& delimiter) const 63 { 64 EXECUTOR_PARSE(normal); 65 } 66 67 bool Executor::evaluate(const std::string& params, MultiTypeMath param[5], const std::string& delimiter) const 68 { 69 unsigned int paramCount = this->functor_->getParamCount(); 70 71 if (paramCount == 1) 72 { 73 // only one param: check if there are params given, otherwise try to use default values 74 std::string temp = getStripped(params); 75 if ((temp != "") && (temp.size() != 0)) 76 { 77 param[0] = params; 78 this->functor_->evaluateParam(0, param[0]); 79 return true; 80 } 81 else if (this->bAddedDefaultValue_[0]) 82 { 83 param[0] = this->defaultValue_[0]; 84 this->functor_->evaluateParam(0, param[0]); 85 return true; 86 } 87 return false; 88 } 89 else 90 { 91 // more than one param 92 SubString tokens(params, delimiter, SubString::WhiteSpaces, false, '\\', true, '"', true, '(', ')', true, '\0'); 93 94 // if there are not enough params given, check if there are default values 95 for (unsigned int i = tokens.size(); i < this->functor_->getParamCount(); i++) 96 if (!this->bAddedDefaultValue_[i]) 97 return false; 98 99 // assign all given arguments to the multitypes 100 for (unsigned int i = 0; i < min(tokens.size(), (unsigned int)MAX_FUNCTOR_ARGUMENTS); i++) 101 param[i] = tokens[i]; 102 103 // fill the remaining multitypes with default values 104 for (unsigned int i = tokens.size(); i < min(paramCount, (unsigned int)MAX_FUNCTOR_ARGUMENTS); i++) 105 param[i] = this->defaultValue_[i]; 106 107 // evaluate the param types through the functor 108 for (unsigned int i = 0; i < min(paramCount, (unsigned int)MAX_FUNCTOR_ARGUMENTS); i++) 109 this->functor_->evaluateParam(i, param[i]); 110 111 return true; 112 } 113 } 114 115 Executor& Executor::setDescription(const std::string& description) 63 116 { 64 117 if (!this->bAddedDescription_) … … 68 121 this->bAddedDescription_ = true; 69 122 } 123 return (*this); 70 124 } 71 125 … … 75 129 } 76 130 77 void Executor::descriptionParam(int param, const std::string& description)78 { 79 if (param > 0 && param <= 5)131 Executor& Executor::setDescriptionParam(int param, const std::string& description) 132 { 133 if (param >= 0 && param < MAX_FUNCTOR_ARGUMENTS) 80 134 { 81 135 if (!this->bAddedDescriptionParam_[param]) … … 83 137 std::string paramnumber; 84 138 if (!Convert::ToString(¶mnumber, param)) 85 return ;139 return (*this); 86 140 87 141 this->descriptionParam_[param] = std::string("ExecutorDescription::" + this->name_ + "::param" + paramnumber); … … 90 144 } 91 145 } 146 return (*this); 92 147 } 93 148 94 149 const std::string& Executor::getDescriptionParam(int param) const 95 150 { 96 if (param > 0 && param <= 5) 97 { 151 if (param >= 0 && param < MAX_FUNCTOR_ARGUMENTS) 98 152 return GetLocalisation(this->descriptionParam_[param]); 99 }100 153 101 154 return this->descriptionParam_[0]; 102 155 } 103 156 104 void Executor::descriptionReturnvalue(const std::string& description)157 Executor& Executor::setDescriptionReturnvalue(const std::string& description) 105 158 { 106 159 if (!this->bAddedDescriptionReturnvalue_) … … 110 163 this->bAddedDescriptionReturnvalue_ = true; 111 164 } 165 return (*this); 112 166 } 113 167 … … 116 170 return GetLocalisation(this->descriptionReturnvalue_); 117 171 } 172 173 Executor& Executor::setDefaultValues(const MultiTypeMath& param1) 174 { 175 this->defaultValue_[0] = param1; 176 this->bAddedDefaultValue_[0] = true; 177 178 return (*this); 179 } 180 181 Executor& Executor::setDefaultValues(const MultiTypeMath& param1, const MultiTypeMath& param2) 182 { 183 this->defaultValue_[0] = param1; 184 this->bAddedDefaultValue_[0] = true; 185 this->defaultValue_[1] = param2; 186 this->bAddedDefaultValue_[1] = true; 187 188 return (*this); 189 } 190 191 Executor& Executor::setDefaultValues(const MultiTypeMath& param1, const MultiTypeMath& param2, const MultiTypeMath& param3) 192 { 193 this->defaultValue_[0] = param1; 194 this->bAddedDefaultValue_[0] = true; 195 this->defaultValue_[1] = param2; 196 this->bAddedDefaultValue_[1] = true; 197 this->defaultValue_[2] = param3; 198 this->bAddedDefaultValue_[2] = true; 199 200 return (*this); 201 } 202 203 Executor& Executor::setDefaultValues(const MultiTypeMath& param1, const MultiTypeMath& param2, const MultiTypeMath& param3, const MultiTypeMath& param4) 204 { 205 this->defaultValue_[0] = param1; 206 this->bAddedDefaultValue_[0] = true; 207 this->defaultValue_[1] = param2; 208 this->bAddedDefaultValue_[1] = true; 209 this->defaultValue_[2] = param3; 210 this->bAddedDefaultValue_[2] = true; 211 this->defaultValue_[3] = param4; 212 this->bAddedDefaultValue_[3] = true; 213 214 return (*this); 215 } 216 217 Executor& Executor::setDefaultValues(const MultiTypeMath& param1, const MultiTypeMath& param2, const MultiTypeMath& param3, const MultiTypeMath& param4, const MultiTypeMath& param5) 218 { 219 this->defaultValue_[0] = param1; 220 this->bAddedDefaultValue_[0] = true; 221 this->defaultValue_[1] = param2; 222 this->bAddedDefaultValue_[1] = true; 223 this->defaultValue_[2] = param3; 224 this->bAddedDefaultValue_[2] = true; 225 this->defaultValue_[3] = param4; 226 this->bAddedDefaultValue_[3] = true; 227 this->defaultValue_[4] = param5; 228 this->bAddedDefaultValue_[4] = true; 229 230 return (*this); 231 } 232 233 Executor& Executor::setDefaultValue(unsigned int index, const MultiTypeMath& param) 234 { 235 if (index >= 0 && index < MAX_FUNCTOR_ARGUMENTS) 236 { 237 this->defaultValue_[index] = param; 238 this->bAddedDefaultValue_[index] = true; 239 } 240 return (*this); 241 } 242 243 bool Executor::allDefaultValuesSet() const 244 { 245 for (unsigned int i = 0; i < this->functor_->getParamCount(); i++) 246 if (!this->bAddedDefaultValue_[i]) 247 return false; 248 249 return true; 250 } 118 251 } -
code/trunk/src/orxonox/core/Executor.h
r871 r1052 32 32 #include "CorePrereqs.h" 33 33 #include "Functor.h" 34 #include "Debug.h" 35 #include "util/SubString.h" 36 #include "util/String.h" 37 38 39 #define EXECUTOR_PARSE_FUNCTORCALL(mode) EXECUTOR_PARSE_FUNCTORCALL##mode 40 #define EXECUTOR_PARSE_FUNCTORCALLnormal (*this->functor_) 41 #define EXECUTOR_PARSE_FUNCTORCALLobject (*((FunctorMember<T>*)this->functor_)) 42 43 #define EXECUTOR_PARSE_OBJECT(mode, comma) EXECUTOR_PARSE_OBJECT##mode##comma 44 #define EXECUTOR_PARSE_OBJECTnormal0 45 #define EXECUTOR_PARSE_OBJECTnormal1 46 #define EXECUTOR_PARSE_OBJECTobject0 object 47 #define EXECUTOR_PARSE_OBJECTobject1 object, 48 49 #define EXECUTOR_PARSE(mode) \ 50 unsigned int paramCount = this->functor_->getParamCount(); \ 51 \ 52 if (paramCount == 0) \ 53 { \ 54 COUT(5) << "Calling Executor " << this->name_ << " through parser without parameters." << std::endl; \ 55 EXECUTOR_PARSE_FUNCTORCALL(mode)(EXECUTOR_PARSE_OBJECT(mode, 0)); \ 56 } \ 57 else if (paramCount == 1) \ 58 { \ 59 std::string temp = getStripped(params); \ 60 if ((temp != "") && (temp.size() != 0)) \ 61 { \ 62 COUT(5) << "Calling Executor " << this->name_ << " through parser with one parameter, using whole string: " << params << std::endl; \ 63 EXECUTOR_PARSE_FUNCTORCALL(mode)(EXECUTOR_PARSE_OBJECT(mode, 1) MultiTypeMath(params)); \ 64 } \ 65 else if (this->bAddedDefaultValue_[0]) \ 66 { \ 67 COUT(5) << "Calling Executor " << this->name_ << " through parser with one parameter, using default value: " << this->defaultValue_[0] << std::endl; \ 68 EXECUTOR_PARSE_FUNCTORCALL(mode)(EXECUTOR_PARSE_OBJECT(mode, 1) this->defaultValue_[0]); \ 69 } \ 70 else \ 71 { \ 72 COUT(2) << "Warning: Can't call executor " << this->name_ << " through parser: Not enough parameters or default values given (input: " << temp << ")." << std::endl; \ 73 return false; \ 74 } \ 75 } \ 76 else \ 77 { \ 78 SubString tokens(params, delimiter, SubString::WhiteSpaces, false, '\\', true, '"', true, '(', ')', true, '\0'); \ 79 \ 80 for (unsigned int i = tokens.size(); i < this->functor_->getParamCount(); i++) \ 81 { \ 82 if (!this->bAddedDefaultValue_[i]) \ 83 { \ 84 COUT(2) << "Warning: Can't call executor " << this->name_ << " through parser: Not enough parameters or default values given (input:" << params << ")." << std::endl; \ 85 return false; \ 86 } \ 87 } \ 88 \ 89 MultiTypeMath param[MAX_FUNCTOR_ARGUMENTS]; \ 90 COUT(5) << "Calling Executor " << this->name_ << " through parser with " << paramCount << " parameters, using " << tokens.size() << " tokens ("; \ 91 for (unsigned int i = 0; i < tokens.size() && i < MAX_FUNCTOR_ARGUMENTS; i++) \ 92 { \ 93 param[i] = tokens[i]; \ 94 if (i != 0) \ 95 { \ 96 COUT(5) << ", "; \ 97 } \ 98 COUT(5) << tokens[i]; \ 99 } \ 100 COUT(5) << ") and " << (paramCount - tokens.size()) << " default values ("; \ 101 for (unsigned int i = tokens.size(); i < paramCount; i++) \ 102 { \ 103 param[i] = this->defaultValue_[i]; \ 104 if (i != 0) \ 105 { \ 106 COUT(5) << ", "; \ 107 } \ 108 COUT(5) << this->defaultValue_[i]; \ 109 } \ 110 COUT(5) << ")." << std::endl; \ 111 \ 112 if ((tokens.size() > paramCount) && (this->functor_->getTypenameParam(paramCount - 1) == "string")) \ 113 param[paramCount - 1] = tokens.subSet(paramCount - 1).join(); \ 114 \ 115 switch(paramCount) \ 116 { \ 117 case 2: \ 118 EXECUTOR_PARSE_FUNCTORCALL(mode)(EXECUTOR_PARSE_OBJECT(mode, 1) param[0], param[1]); \ 119 break; \ 120 case 3: \ 121 EXECUTOR_PARSE_FUNCTORCALL(mode)(EXECUTOR_PARSE_OBJECT(mode, 1) param[0], param[1], param[2]); \ 122 break; \ 123 case 4: \ 124 EXECUTOR_PARSE_FUNCTORCALL(mode)(EXECUTOR_PARSE_OBJECT(mode, 1) param[0], param[1], param[2], param[3]); \ 125 break; \ 126 case 5: \ 127 EXECUTOR_PARSE_FUNCTORCALL(mode)(EXECUTOR_PARSE_OBJECT(mode, 1) param[0], param[1], param[2], param[3], param[4]); \ 128 break; \ 129 } \ 130 } \ 131 \ 132 return true 133 134 namespace AccessLevel 135 { 136 enum Level 137 { 138 None, 139 User, 140 Admin, 141 Offline, 142 Debug, 143 Disabled 144 }; 145 } 34 146 35 147 namespace orxonox … … 38 150 { 39 151 public: 40 Executor(Functor* functor, const std::string& name = "" );152 Executor(Functor* functor, const std::string& name = "", AccessLevel::Level level = AccessLevel::None); 41 153 virtual ~Executor(); 42 154 43 inline virtual void operator()(const MultiTypeMath& param1 = MT_null, const MultiTypeMath& param2 = MT_null, const MultiTypeMath& param3 = MT_null, const MultiTypeMath& param4 = MT_null, const MultiTypeMath& param5 = MT_null) 155 inline void operator()() const 156 { (*this->functor_)(this->defaultValue_[0], this->defaultValue_[1], this->defaultValue_[2], this->defaultValue_[3], this->defaultValue_[4]); } 157 inline void operator()(const MultiTypeMath& param1) const 158 { (*this->functor_)(param1, this->defaultValue_[1], this->defaultValue_[2], this->defaultValue_[3], this->defaultValue_[4]); } 159 inline void operator()(const MultiTypeMath& param1, const MultiTypeMath& param2) const 160 { (*this->functor_)(param1, param2, this->defaultValue_[2], this->defaultValue_[3], this->defaultValue_[4]); } 161 inline void operator()(const MultiTypeMath& param1, const MultiTypeMath& param2, const MultiTypeMath& param3) const 162 { (*this->functor_)(param1, param2, param3, this->defaultValue_[3], this->defaultValue_[4]); } 163 inline void operator()(const MultiTypeMath& param1, const MultiTypeMath& param2, const MultiTypeMath& param3, const MultiTypeMath& param4) const 164 { (*this->functor_)(param1, param2, param3, param4, this->defaultValue_[4]); } 165 inline void operator()(const MultiTypeMath& param1, const MultiTypeMath& param2, const MultiTypeMath& param3, const MultiTypeMath& param4, const MultiTypeMath& param5) const 44 166 { (*this->functor_)(param1, param2, param3, param4, param5); } 45 167 46 void setName(const std::string name); 47 const std::string& getName() const; 48 49 void description(const std::string& description); 168 bool parse(const std::string& params, const std::string& delimiter = " ") const; 169 170 bool evaluate(const std::string& params, MultiTypeMath param[5], const std::string& delimiter = " ") const; 171 172 Executor& setDescription(const std::string& description); 50 173 const std::string& getDescription() const; 51 174 52 void descriptionParam(int param, const std::string& description);175 Executor& setDescriptionParam(int param, const std::string& description); 53 176 const std::string& getDescriptionParam(int param) const; 54 177 55 void descriptionReturnvalue(const std::string& description);178 Executor& setDescriptionReturnvalue(const std::string& description); 56 179 const std::string& getDescriptionReturnvalue(int param) const; 57 180 58 inline int getParamCount() const181 inline unsigned int getParamCount() const 59 182 { return this->functor_->getParamCount(); } 60 183 inline bool hasReturnvalue() const … … 64 187 inline MultiTypeMath getReturnvalue() const 65 188 { return this->functor_->getReturnvalue(); } 66 inline std::string getTypenameParam( int param) const189 inline std::string getTypenameParam(unsigned int param) const 67 190 { return this->functor_->getTypenameParam(param); } 68 191 inline std::string getTypenameReturnvalue() const 69 192 { return this->functor_->getTypenameReturnvalue(); } 70 193 194 inline void setName(const std::string name) 195 { this->name_ = name; } 196 inline const std::string& getName() const 197 { return this->name_; } 198 199 inline void setAccessLevel(AccessLevel::Level level) 200 { this->accessLevel_ = level; } 201 inline AccessLevel::Level getAccessLevel() const 202 { return this->accessLevel_; } 203 204 Executor& setDefaultValues(const MultiTypeMath& param1); 205 Executor& setDefaultValues(const MultiTypeMath& param1, const MultiTypeMath& param2); 206 Executor& setDefaultValues(const MultiTypeMath& param1, const MultiTypeMath& param2, const MultiTypeMath& param3); 207 Executor& setDefaultValues(const MultiTypeMath& param1, const MultiTypeMath& param2, const MultiTypeMath& param3, const MultiTypeMath& param4); 208 Executor& setDefaultValues(const MultiTypeMath& param1, const MultiTypeMath& param2, const MultiTypeMath& param3, const MultiTypeMath& param4, const MultiTypeMath& param5); 209 Executor& setDefaultValue(unsigned int index, const MultiTypeMath& param); 210 211 inline MultiTypeMath getDefaultValue(unsigned int index) const 212 { 213 if (index >= 0 && index < MAX_FUNCTOR_ARGUMENTS) 214 return this->defaultValue_[index]; 215 216 return MT_null; 217 } 218 219 bool allDefaultValuesSet() const; 220 inline bool defaultValueSet(unsigned int index) const 221 { 222 if (index >= 0 && index < MAX_FUNCTOR_ARGUMENTS) 223 return this->bAddedDefaultValue_[index]; 224 225 return false; 226 } 227 71 228 protected: 72 229 Functor* functor_; 230 std::string name_; 231 MultiTypeMath defaultValue_[MAX_FUNCTOR_ARGUMENTS]; 232 bool bAddedDefaultValue_[MAX_FUNCTOR_ARGUMENTS]; 73 233 74 234 private: 75 std::string name_;76 77 235 LanguageEntryLabel description_; 78 236 LanguageEntryLabel descriptionReturnvalue_; 79 LanguageEntryLabel descriptionParam_[ 5];237 LanguageEntryLabel descriptionParam_[MAX_FUNCTOR_ARGUMENTS]; 80 238 81 239 bool bAddedDescription_; 82 240 bool bAddedDescriptionReturnvalue_; 83 bool bAddedDescriptionParam_[5]; 241 bool bAddedDescriptionParam_[MAX_FUNCTOR_ARGUMENTS]; 242 243 AccessLevel::Level accessLevel_; 84 244 }; 85 245 … … 87 247 { 88 248 public: 89 ExecutorStatic(FunctorStatic* functor, const std::string& name = "" ) : Executor(functor, name) {}249 ExecutorStatic(FunctorStatic* functor, const std::string& name = "", AccessLevel::Level level = AccessLevel::None) : Executor(functor, name, level) {} 90 250 virtual ~ExecutorStatic() {} 91 92 inline virtual void operator()(const MultiTypeMath& param1 = MT_null, const MultiTypeMath& param2 = MT_null, const MultiTypeMath& param3 = MT_null, const MultiTypeMath& param4 = MT_null, const MultiTypeMath& param5 = MT_null)93 { (*this->functor_)(param1, param2, param3, param4, param5); }94 251 }; 95 252 … … 98 255 { 99 256 public: 100 ExecutorMember(FunctorMember<T>* functor, const std::string& name = "" ) : Executor(functor, name) {}257 ExecutorMember(FunctorMember<T>* functor, const std::string& name = "", AccessLevel::Level level = AccessLevel::None) : Executor(functor, name, level) {} 101 258 virtual ~ExecutorMember() {} 102 259 103 inline virtual void operator()(T* object, const MultiTypeMath& param1 = MT_null, const MultiTypeMath& param2 = MT_null, const MultiTypeMath& param3 = MT_null, const MultiTypeMath& param4 = MT_null, const MultiTypeMath& param5 = MT_null) 104 { (*this->functor_)(object, param1, param2, param3, param4, param5); } 105 inline virtual void operator()(const T* object, const MultiTypeMath param1 = MT_null, const MultiTypeMath& param2 = MT_null, const MultiTypeMath& param3 = MT_null, const MultiTypeMath& param4 = MT_null, const MultiTypeMath& param5 = MT_null) 106 { (*this->functor_)(object, param1, param2, param3, param4, param5); } 107 inline virtual void operator()(const MultiTypeMath& param1 = MT_null, const MultiTypeMath& param2 = MT_null, const MultiTypeMath& param3 = MT_null, const MultiTypeMath& param4 = MT_null, const MultiTypeMath& param5 = MT_null) 108 { (*this->functor_)(param1, param2, param3, param4, param5); } 109 110 inline void setObject(T* object) 111 { this->functor_->setObject(object); } 112 inline void setObject(const T* object) 113 { this->functor_->setObject(object); } 260 inline void operator()(T* object) const 261 { (*((FunctorMember<T>*)this->functor_))(object, this->defaultValue_[0], this->defaultValue_[1], this->defaultValue_[2], this->defaultValue_[3], this->defaultValue_[4]); } 262 inline void operator()(T* object, const MultiTypeMath& param1) const 263 { (*((FunctorMember<T>*)this->functor_))(object, param1, this->defaultValue_[1], this->defaultValue_[2], this->defaultValue_[3], this->defaultValue_[4]); } 264 inline void operator()(T* object, const MultiTypeMath& param1, const MultiTypeMath& param2) const 265 { (*((FunctorMember<T>*)this->functor_))(object, param1, param2, this->defaultValue_[2], this->defaultValue_[3], this->defaultValue_[4]); } 266 inline void operator()(T* object, const MultiTypeMath& param1, const MultiTypeMath& param2, const MultiTypeMath& param3) const 267 { (*((FunctorMember<T>*)this->functor_))(object, param1, param2, param3, this->defaultValue_[3], this->defaultValue_[4]); } 268 inline void operator()(T* object, const MultiTypeMath& param1, const MultiTypeMath& param2, const MultiTypeMath& param3, const MultiTypeMath& param4) const 269 { (*((FunctorMember<T>*)this->functor_))(object, param1, param2, param3, param4, this->defaultValue_[4]); } 270 inline void operator()(T* object, const MultiTypeMath& param1, const MultiTypeMath& param2, const MultiTypeMath& param3, const MultiTypeMath& param4, const MultiTypeMath& param5) const 271 { (*((FunctorMember<T>*)this->functor_))(object, param1, param2, param3, param4, param5); } 272 273 274 inline void operator()(const T* object) const 275 { (*((FunctorMember<T>*)this->functor_))(object, this->defaultValue_[0], this->defaultValue_[1], this->defaultValue_[2], this->defaultValue_[3], this->defaultValue_[4]); } 276 inline void operator()(const T* object, const MultiTypeMath& param1) const 277 { (*((FunctorMember<T>*)this->functor_))(object, param1, this->defaultValue_[1], this->defaultValue_[2], this->defaultValue_[3], this->defaultValue_[4]); } 278 inline void operator()(const T* object, const MultiTypeMath& param1, const MultiTypeMath& param2) const 279 { (*((FunctorMember<T>*)this->functor_))(object, param1, param2, this->defaultValue_[2], this->defaultValue_[3], this->defaultValue_[4]); } 280 inline void operator()(const T* object, const MultiTypeMath& param1, const MultiTypeMath& param2, const MultiTypeMath& param3) const 281 { (*((FunctorMember<T>*)this->functor_))(object, param1, param2, param3, this->defaultValue_[3], this->defaultValue_[4]); } 282 inline void operator()(const T* object, const MultiTypeMath& param1, const MultiTypeMath& param2, const MultiTypeMath& param3, const MultiTypeMath& param4) const 283 { (*((FunctorMember<T>*)this->functor_))(object, param1, param2, param3, param4, this->defaultValue_[4]); } 284 inline void operator()(const T* object, const MultiTypeMath& param1, const MultiTypeMath& param2, const MultiTypeMath& param3, const MultiTypeMath& param4, const MultiTypeMath& param5) const 285 { (*((FunctorMember<T>*)this->functor_))(object, param1, param2, param3, param4, param5); } 286 287 inline void setObject(T* object) const 288 { ((FunctorMember<T>*)this->functor_)->setObject(object); } 289 inline void setObject(const T* object) const 290 { ((FunctorMember<T>*)this->functor_)->setObject(object); } 291 292 bool parse(T* object, const std::string& params, const std::string& delimiter = " ") const 293 { 294 EXECUTOR_PARSE(object); 295 } 296 297 bool parse(const T* object, const std::string& params, const std::string& delimiter = " ") const 298 { 299 EXECUTOR_PARSE(object); 300 } 114 301 }; 302 303 inline Executor* createExecutor(Functor* functor, const std::string& name = "", AccessLevel::Level level = AccessLevel::None) 304 { 305 return new Executor(functor, name, level); 306 } 307 308 template <class T> 309 inline ExecutorMember<T>* createExecutor(FunctorMember<T>* functor, const std::string& name = "", AccessLevel::Level level = AccessLevel::None) 310 { 311 return new ExecutorMember<T>(functor, name, level); 312 } 313 314 inline ExecutorStatic* createExecutor(FunctorStatic* functor, const std::string& name = "", AccessLevel::Level level = AccessLevel::None) 315 { 316 return new ExecutorStatic(functor, name, level); 317 } 115 318 } 116 319 -
code/trunk/src/orxonox/core/Functor.h
r871 r1052 35 35 #include "CorePrereqs.h" 36 36 37 38 enum FunctionType 37 #define MAX_FUNCTOR_ARGUMENTS 5 38 39 namespace orxonox 39 40 { 40 FT_MEMBER, 41 FT_CONSTMEMBER, 42 FT_STATIC 43 }; 44 45 46 template <class T> 47 inline std::string typeToString(); 41 enum FunctionType 42 { 43 FT_MEMBER, 44 FT_CONSTMEMBER, 45 FT_STATIC 46 }; 47 48 49 template <class T> 50 inline std::string typeToString() { return "unknown"; } 48 51 49 52 #define CreateTypeToStringTemplate(type) \ 50 53 template <> \ 51 inline std::string typeToString<type>() { return #type; } 52 53 CreateTypeToStringTemplate(int); 54 CreateTypeToStringTemplate(unsigned int); 55 CreateTypeToStringTemplate(char); 56 CreateTypeToStringTemplate(unsigned char); 57 CreateTypeToStringTemplate(short); 58 CreateTypeToStringTemplate(unsigned short); 59 CreateTypeToStringTemplate(long); 60 CreateTypeToStringTemplate(unsigned long); 61 CreateTypeToStringTemplate(float); 62 CreateTypeToStringTemplate(double); 63 CreateTypeToStringTemplate(long double); 64 CreateTypeToStringTemplate(bool); 65 CreateTypeToStringTemplate(std::string); 66 CreateTypeToStringTemplate(orxonox::Vector2); 67 CreateTypeToStringTemplate(orxonox::Vector3); 68 CreateTypeToStringTemplate(orxonox::Quaternion); 69 CreateTypeToStringTemplate(orxonox::ColourValue); 70 CreateTypeToStringTemplate(orxonox::Radian); 71 CreateTypeToStringTemplate(orxonox::Degree); 72 73 74 class _CoreExport Functor 75 { 76 public: 77 Functor() {} 78 virtual ~Functor() {} 79 80 virtual void operator()(const MultiTypeMath& param1 = MT_null, const MultiTypeMath& param2 = MT_null, const MultiTypeMath& param3 = MT_null, const MultiTypeMath& param4 = MT_null, const MultiTypeMath& param5 = MT_null) = 0; 81 82 inline int getParamCount() const { return this->numParams_; } 83 inline bool hasReturnvalue() const { return this->hasReturnValue_; } 84 inline FunctionType getType() const { return this->type_; } 85 inline MultiTypeMath getReturnvalue() const { return this->returnedValue_; } 86 87 std::string getTypenameParam(int param) const { return (param > 0 && param <= 5) ? this->typeParam_[param-1] : ""; } 88 std::string getTypenameReturnvalue() const { return this->typeReturnvalue_; } 89 90 protected: 91 int numParams_; 92 bool hasReturnValue_; 93 FunctionType type_; 94 MultiTypeMath returnedValue_; 95 96 std::string typeReturnvalue_; 97 std::string typeParam_[5]; 98 }; 99 100 class _CoreExport FunctorStatic : public Functor 101 { 102 public: 103 virtual ~FunctorStatic() {} 104 virtual void operator()(const MultiTypeMath& param1 = MT_null, const MultiTypeMath& param2 = MT_null, const MultiTypeMath& param3 = MT_null, const MultiTypeMath& param4 = MT_null, const MultiTypeMath& param5 = MT_null) = 0; 105 }; 106 107 template <class T> 108 class FunctorMember : public Functor 109 { 110 public: 111 FunctorMember() 112 { 113 constObject_ = 0; 114 object_ = 0; 115 bConstObject_ = false; 116 } 117 virtual ~FunctorMember() {} 118 119 virtual void operator()(T* object, const MultiTypeMath& param1 = MT_null, const MultiTypeMath& param2 = MT_null, const MultiTypeMath& param3 = MT_null, const MultiTypeMath& param4 = MT_null, const MultiTypeMath& param5 = MT_null) = 0; 120 virtual void operator()(const T* object, const MultiTypeMath& param1 = MT_null, const MultiTypeMath& param2 = MT_null, const MultiTypeMath& param3 = MT_null, const MultiTypeMath& param4 = MT_null, const MultiTypeMath& param5 = MT_null) = 0; 121 122 virtual void operator()(const MultiTypeMath& param1 = MT_null, const MultiTypeMath& param2 = MT_null, const MultiTypeMath& param3 = MT_null, const MultiTypeMath& param4 = MT_null, const MultiTypeMath& param5 = MT_null) 123 { 124 if (this->bConstObject_) 54 inline std::string typeToString<type>() { return #type; } \ 55 template <> \ 56 inline std::string typeToString<type&>() { return #type; } \ 57 template <> \ 58 inline std::string typeToString<const type>() { return #type; } \ 59 template <> \ 60 inline std::string typeToString<const type&>() { return #type; } 61 62 CreateTypeToStringTemplate(int); 63 CreateTypeToStringTemplate(unsigned int); 64 CreateTypeToStringTemplate(char); 65 CreateTypeToStringTemplate(unsigned char); 66 CreateTypeToStringTemplate(short); 67 CreateTypeToStringTemplate(unsigned short); 68 CreateTypeToStringTemplate(long); 69 CreateTypeToStringTemplate(unsigned long); 70 CreateTypeToStringTemplate(float); 71 CreateTypeToStringTemplate(double); 72 CreateTypeToStringTemplate(long double); 73 CreateTypeToStringTemplate(bool); 74 CreateTypeToStringTemplate(Vector2); 75 CreateTypeToStringTemplate(Vector3); 76 CreateTypeToStringTemplate(Quaternion); 77 CreateTypeToStringTemplate(ColourValue); 78 CreateTypeToStringTemplate(Radian); 79 CreateTypeToStringTemplate(Degree); 80 81 template <> \ 82 inline std::string typeToString<std::string>() { return "string"; } \ 83 template <> \ 84 inline std::string typeToString<std::string&>() { return "string"; } \ 85 template <> \ 86 inline std::string typeToString<const std::string>() { return "string"; } \ 87 template <> \ 88 inline std::string typeToString<const std::string&>() { return "string"; } 89 90 class _CoreExport Functor 91 { 92 public: 93 Functor() {} 94 virtual ~Functor() {} 95 96 virtual void operator()(const MultiTypeMath& param1 = MT_null, const MultiTypeMath& param2 = MT_null, const MultiTypeMath& param3 = MT_null, const MultiTypeMath& param4 = MT_null, const MultiTypeMath& param5 = MT_null) = 0; 97 98 inline unsigned int getParamCount() const { return this->numParams_; } 99 inline bool hasReturnvalue() const { return this->hasReturnValue_; } 100 inline FunctionType getType() const { return this->type_; } 101 inline MultiTypeMath getReturnvalue() const { return this->returnedValue_; } 102 103 std::string getTypenameParam(unsigned int param) const { return (param >= 0 && param < 5) ? this->typeParam_[param] : ""; } 104 std::string getTypenameReturnvalue() const { return this->typeReturnvalue_; } 105 106 virtual void evaluateParam(unsigned int index, MultiTypeMath& param) const = 0; 107 108 protected: 109 unsigned int numParams_; 110 bool hasReturnValue_; 111 FunctionType type_; 112 MultiTypeMath returnedValue_; 113 114 std::string typeReturnvalue_; 115 std::string typeParam_[MAX_FUNCTOR_ARGUMENTS]; 116 }; 117 118 class _CoreExport FunctorStatic : public Functor 119 { 120 public: 121 virtual ~FunctorStatic() {} 122 virtual void operator()(const MultiTypeMath& param1 = MT_null, const MultiTypeMath& param2 = MT_null, const MultiTypeMath& param3 = MT_null, const MultiTypeMath& param4 = MT_null, const MultiTypeMath& param5 = MT_null) = 0; 123 }; 124 125 template <class T> 126 class FunctorMember : public Functor 127 { 128 public: 129 FunctorMember() 125 130 { 126 if (this->constObject_) 127 (*this)(this->constObject_, param1, param2, param3, param4, param5); 131 constObject_ = 0; 132 object_ = 0; 133 bConstObject_ = false; 134 } 135 virtual ~FunctorMember() {} 136 137 virtual void operator()(T* object, const MultiTypeMath& param1 = MT_null, const MultiTypeMath& param2 = MT_null, const MultiTypeMath& param3 = MT_null, const MultiTypeMath& param4 = MT_null, const MultiTypeMath& param5 = MT_null) = 0; 138 virtual void operator()(const T* object, const MultiTypeMath& param1 = MT_null, const MultiTypeMath& param2 = MT_null, const MultiTypeMath& param3 = MT_null, const MultiTypeMath& param4 = MT_null, const MultiTypeMath& param5 = MT_null) = 0; 139 140 virtual void operator()(const MultiTypeMath& param1 = MT_null, const MultiTypeMath& param2 = MT_null, const MultiTypeMath& param3 = MT_null, const MultiTypeMath& param4 = MT_null, const MultiTypeMath& param5 = MT_null) 141 { 142 if (this->bConstObject_) 143 { 144 if (this->constObject_) 145 (*this)(this->constObject_, param1, param2, param3, param4, param5); 146 else 147 { 148 COUT(1) << "An error occurred in Functor.h:" << std::endl; 149 COUT(1) << "Error: No const object set." << std::endl; 150 } 151 } 128 152 else 129 153 { 130 COUT(1) << "An error occurred in Functor.h:" << std::endl; 131 COUT(1) << "Error: No const object set." << std::endl; 154 if (this->object_) 155 (*this)(this->object_, param1, param2, param3, param4, param5); 156 else 157 { 158 COUT(1) << "An error occurred in Functor.h:" << std::endl; 159 COUT(1) << "Error: No object set." << std::endl; 160 } 132 161 } 133 162 } 134 else 163 164 void setObject(T* object) 135 165 { 136 if (this->object_) 137 (*this)(this->object_, param1, param2, param3, param4, param5); 138 else 139 { 140 COUT(1) << "An error occurred in Functor.h:" << std::endl; 141 COUT(1) << "Error: No object set." << std::endl; 142 } 166 this->bConstObject_ = false; 167 this->object_ = object; 143 168 } 144 } 145 146 void setObject(T* object) 147 { 148 this->bConstObject_ = false; 149 this->object_ = object; 150 } 151 152 void setObject(const T* object) 153 { 154 this->bConstObject_ = true; 155 this->constObject_ = object; 156 } 157 158 private: 159 const T* constObject_; 160 T* object_; 161 bool bConstObject_; 162 }; 163 164 165 166 #define MAKE_COMMA(x) MAKE_COMMA##x 167 #define MAKE_COMMA0 168 #define MAKE_COMMA1 , 169 #define MAKE_COMMA2 , 170 #define MAKE_COMMA3 , 171 #define MAKE_COMMA4 , 172 #define MAKE_COMMA5 , 169 170 void setObject(const T* object) 171 { 172 this->bConstObject_ = true; 173 this->constObject_ = object; 174 } 175 176 private: 177 const T* constObject_; 178 T* object_; 179 bool bConstObject_; 180 }; 173 181 174 182 … … 272 280 273 281 282 #define FUNCTOR_EVALUATE_PARAM(numparams) FUNCTOR_EVALUATE_PARAM##numparams 283 #define FUNCTOR_EVALUATE_PARAM0 284 #define FUNCTOR_EVALUATE_PARAM1 \ 285 if (index == 0) param = (P1)param 286 #define FUNCTOR_EVALUATE_PARAM2 \ 287 if (index == 0) param = (P1)param; \ 288 else if (index == 1) param = (P2)param 289 #define FUNCTOR_EVALUATE_PARAM3 \ 290 if (index == 0) param = (P1)param; \ 291 else if (index == 1) param = (P2)param; \ 292 else if (index == 2) param = (P3)param 293 #define FUNCTOR_EVALUATE_PARAM4 \ 294 if (index == 0) param = (P1)param; \ 295 else if (index == 1) param = (P2)param; \ 296 else if (index == 2) param = (P3)param; \ 297 else if (index == 3) param = (P4)param 298 #define FUNCTOR_EVALUATE_PARAM5 \ 299 if (index == 0) param = (P1)param; \ 300 else if (index == 1) param = (P2)param; \ 301 else if (index == 2) param = (P3)param; \ 302 else if (index == 3) param = (P4)param; \ 303 else if (index == 4) param = (P5)param 304 305 306 274 307 275 308 … … 295 328 } \ 296 329 \ 330 virtual void evaluateParam(unsigned int index, MultiTypeMath& param) const \ 331 { \ 332 FUNCTOR_EVALUATE_PARAM(numparams); \ 333 } \ 334 \ 297 335 private: \ 298 336 FUNCTOR_FUNCTION_RETURNVALUE(returnvalue) (*functionPointer_)(FUNCTOR_FUNCTION_PARAMS(numparams)); \ … … 334 372 } \ 335 373 \ 374 virtual void evaluateParam(unsigned int index, MultiTypeMath& param) const \ 375 { \ 376 FUNCTOR_EVALUATE_PARAM(numparams); \ 377 } \ 378 \ 336 379 private: \ 337 380 FUNCTOR_FUNCTION_RETURNVALUE(returnvalue) (T::*functionPointer_)(FUNCTOR_FUNCTION_PARAMS(numparams)); \ … … 359 402 { \ 360 403 FUNCTOR_STORE_RETURNVALUE(returnvalue, (*object.*this->functionPointer_)(FUNCTOR_FUNCTION_CALL(numparams))); \ 404 } \ 405 \ 406 virtual void evaluateParam(unsigned int index, MultiTypeMath& param) const \ 407 { \ 408 FUNCTOR_EVALUATE_PARAM(numparams); \ 361 409 } \ 362 410 \ … … 412 460 413 461 414 CREATE_ALL_STATIC_FUNCTORS(); 415 CREATE_ALL_MEMBER_FUNCTORS(); 462 CREATE_ALL_STATIC_FUNCTORS(); 463 CREATE_ALL_MEMBER_FUNCTORS(); 464 } 416 465 417 466 #endif /* _Functor_H__ */ -
code/trunk/src/orxonox/core/Identifier.cc
r871 r1052 35 35 #include "Identifier.h" 36 36 #include "Factory.h" 37 #include "Executor.h" 38 #include "CommandExecutor.h" 37 39 38 40 namespace orxonox … … 51 53 this->factory_ = 0; 52 54 53 this->children_ = new std::list<const Identifier*>(); 54 this->directChildren_ = new std::list<const Identifier*>(); 55 this->bHasConfigValues_ = false; 56 this->bHasConsoleCommands_ = false; 57 58 this->children_ = new std::set<const Identifier*>(); 59 this->directChildren_ = new std::set<const Identifier*>(); 55 60 56 61 // Use a static variable because the classID gets created before main() and that's why we should avoid static member variables … … 72 77 @param parents A list containing all parents 73 78 */ 74 void Identifier::initialize(std:: list<const Identifier*>* parents)79 void Identifier::initialize(std::set<const Identifier*>* parents) 75 80 { 76 81 COUT(4) << "*** Identifier: Initialize " << this->name_ << "-Singleton." << std::endl; … … 83 88 84 89 // Iterate through all parents 85 for (std:: list<const Identifier*>::iterator it = parents->begin(); it != parents->end(); ++it)90 for (std::set<const Identifier*>::iterator it = parents->begin(); it != parents->end(); ++it) 86 91 { 87 92 // Tell the parent we're one of it's children … … 89 94 90 95 // Erase all parents of our parent from our direct-parent-list 91 for (std:: list<const Identifier*>::const_iterator it1 = (*it)->getParents().begin(); it1 != (*it)->getParents().end(); ++it1)96 for (std::set<const Identifier*>::const_iterator it1 = (*it)->getParents().begin(); it1 != (*it)->getParents().end(); ++it1) 92 97 { 93 98 // Search for the parent's parent in our direct-parent-list 94 for (std:: list<const Identifier*>::iterator it2 = this->directParents_.begin(); it2 != this->directParents_.end(); ++it2)99 for (std::set<const Identifier*>::iterator it2 = this->directParents_.begin(); it2 != this->directParents_.end(); ++it2) 95 100 { 96 101 if ((*it1) == (*it2)) … … 105 110 106 111 // Now iterate through all direct parents 107 for (std:: list<const Identifier*>::iterator it = this->directParents_.begin(); it != this->directParents_.end(); ++it)112 for (std::set<const Identifier*>::iterator it = this->directParents_.begin(); it != this->directParents_.end(); ++it) 108 113 { 109 114 // Tell the parent we're one of it's direct children … … 149 154 bool Identifier::isA(const Identifier* identifier) const 150 155 { 151 return (identifier == this || this->identifierIsInList(identifier, this->parents_));156 return (identifier == this || (this->parents_.find(identifier) != this->children_->end())); 152 157 } 153 158 … … 167 172 bool Identifier::isChildOf(const Identifier* identifier) const 168 173 { 169 return this->identifierIsInList(identifier, this->parents_);174 return (this->parents_.find(identifier) != this->children_->end()); 170 175 } 171 176 … … 176 181 bool Identifier::isDirectChildOf(const Identifier* identifier) const 177 182 { 178 return this->identifierIsInList(identifier, this->directParents_);183 return (this->directParents_.find(identifier) != this->children_->end()); 179 184 } 180 185 … … 185 190 bool Identifier::isParentOf(const Identifier* identifier) const 186 191 { 187 return this->identifierIsInList(identifier, *this->children_);192 return (this->children_->find(identifier) != this->children_->end()); 188 193 } 189 194 … … 194 199 bool Identifier::isDirectParentOf(const Identifier* identifier) const 195 200 { 196 return this->identifierIsInList(identifier, *this->directChildren_); 201 return (this->directChildren_->find(identifier) != this->children_->end()); 202 } 203 204 /** 205 @brief Returns the map that stores all Identifiers. 206 @return The map 207 */ 208 std::map<std::string, Identifier*>& Identifier::getIdentifierMapIntern() 209 { 210 static std::map<std::string, Identifier*> identifierMap; 211 return identifierMap; 212 } 213 214 /** 215 @brief Returns the map that stores all Identifiers. 216 @return The map 217 */ 218 std::map<std::string, Identifier*>& Identifier::getLowercaseIdentifierMapIntern() 219 { 220 static std::map<std::string, Identifier*> lowercaseIdentifierMap; 221 return lowercaseIdentifierMap; 222 } 223 224 /** 225 @brief Adds the ConfigValueContainer of a variable, given by the string of its name. 226 @param varname The name of the variablee 227 @param container The container 228 */ 229 void Identifier::addConfigValueContainer(const std::string& varname, ConfigValueContainer* container) 230 { 231 this->bHasConfigValues_ = true; 232 this->configValues_[varname] = container; 233 this->configValues_LC_[getLowercase(varname)] = container; 197 234 } 198 235 … … 212 249 213 250 /** 214 @brief Adds the ConfigValueContainer of a variable, given by the string of its name. 215 @param varname The name of the variablee 216 @param container The container 217 */ 218 void Identifier::addConfigValueContainer(const std::string& varname, ConfigValueContainer* container) 219 { 220 this->configValues_[varname] = container; 221 } 222 223 /** 224 @brief Searches for a given identifier in a list and returns whether the identifier is in the list or not. 225 @param identifier The identifier to look for 226 @param list The list 227 @return True = the identifier is in the list 228 */ 229 bool Identifier::identifierIsInList(const Identifier* identifier, const std::list<const Identifier*>& list) 230 { 231 for (std::list<const Identifier*>::const_iterator it = list.begin(); it != list.end(); ++it) 232 if (identifier == (*it)) 233 return true; 234 235 return false; 236 } 237 238 std::ostream& operator<<(std::ostream& out, const std::list<const Identifier*>& list) 239 { 240 for (std::list<const Identifier*>::const_iterator it = list.begin(); it != list.end(); ++it) 251 @brief Returns the ConfigValueContainer of a variable, given by the string of its name in lowercase. 252 @param varname The name of the variable in lowercase 253 @return The ConfigValueContainer 254 */ 255 ConfigValueContainer* Identifier::getLowercaseConfigValueContainer(const std::string& varname) 256 { 257 std::map<std::string, ConfigValueContainer*>::const_iterator it = configValues_LC_.find(varname); 258 if (it != configValues_LC_.end()) 259 return ((*it).second); 260 else 261 return 0; 262 } 263 264 /** 265 @brief Adds a new console command of this class. 266 @param executor The executor of the command 267 @param bCreateShortcut If this is true a shortcut gets created so you don't have to add the classname to access this command 268 @return The executor of the command 269 */ 270 ExecutorStatic& Identifier::addConsoleCommand(ExecutorStatic* executor, bool bCreateShortcut) 271 { 272 this->bHasConsoleCommands_ = true; 273 this->consoleCommands_[executor->getName()] = executor; 274 this->consoleCommands_LC_[getLowercase(executor->getName())] = executor; 275 276 if (bCreateShortcut) 277 CommandExecutor::addConsoleCommandShortcut(executor); 278 279 return (*executor); 280 } 281 282 /** 283 @brief Returns the executor of a console command with given name. 284 @brief name The name of the requested console command 285 @return The executor of the requested console command 286 */ 287 ExecutorStatic* Identifier::getConsoleCommand(const std::string& name) const 288 { 289 std::map<std::string, ExecutorStatic*>::const_iterator it = this->consoleCommands_.find(name); 290 if (it != this->consoleCommands_.end()) 291 return (*it).second; 292 else 293 return 0; 294 } 295 296 /** 297 @brief Returns the executor of a console command with given name in lowercase. 298 @brief name The name of the requested console command in lowercae 299 @return The executor of the requested console command 300 */ 301 ExecutorStatic* Identifier::getLowercaseConsoleCommand(const std::string& name) const 302 { 303 std::map<std::string, ExecutorStatic*>::const_iterator it = this->consoleCommands_LC_.find(name); 304 if (it != this->consoleCommands_LC_.end()) 305 return (*it).second; 306 else 307 return 0; 308 } 309 310 /** 311 @brief Lists the names of all Identifiers in a std::set<const Identifier*>. 312 @param out The outstream 313 @param list The list (or set) of Identifiers 314 @return The outstream 315 */ 316 std::ostream& operator<<(std::ostream& out, const std::set<const Identifier*>& list) 317 { 318 for (std::set<const Identifier*>::const_iterator it = list.begin(); it != list.end(); ++it) 241 319 out << (*it)->getName() << " "; 242 320 -
code/trunk/src/orxonox/core/Identifier.h
r1024 r1052 52 52 #define _Identifier_H__ 53 53 54 #include < list>54 #include <set> 55 55 #include <map> 56 56 #include <string> … … 62 62 #include "Debug.h" 63 63 #include "Iterator.h" 64 #include "util/String.h" 64 65 65 66 namespace orxonox … … 105 106 bool isDirectParentOf(const Identifier* identifier) const; 106 107 107 /** @brief Removes all objects of the corresponding class. */ 108 virtual void removeObjects() const = 0; 108 virtual const ObjectList<BaseObject>* getObjectList() const = 0; 109 110 virtual void updateConfigValues() const = 0; 109 111 110 112 /** @brief Returns the name of the class the Identifier belongs to. @return The name */ 111 113 inline const std::string& getName() const { return this->name_; } 112 114 115 113 116 /** @brief Returns the parents of the class the Identifier belongs to. @return The list of all parents */ 114 inline const std:: list<const Identifier*>& getParents() const { return this->parents_; }117 inline const std::set<const Identifier*>& getParents() const { return this->parents_; } 115 118 /** @brief Returns the begin-iterator of the parents-list. @return The begin-iterator */ 116 inline std:: list<const Identifier*>::const_iterator getParentsBegin() const { return this->parents_.begin(); }119 inline std::set<const Identifier*>::const_iterator getParentsBegin() const { return this->parents_.begin(); } 117 120 /** @brief Returns the end-iterator of the parents-list. @return The end-iterator */ 118 inline std:: list<const Identifier*>::const_iterator getParentsEnd() const { return this->parents_.end(); }121 inline std::set<const Identifier*>::const_iterator getParentsEnd() const { return this->parents_.end(); } 119 122 120 123 /** @brief Returns the children of the class the Identifier belongs to. @return The list of all children */ 121 inline const std:: list<const Identifier*>& getChildren() const { return (*this->children_); }124 inline const std::set<const Identifier*>& getChildren() const { return (*this->children_); } 122 125 /** @brief Returns the begin-iterator of the children-list. @return The begin-iterator */ 123 inline std:: list<const Identifier*>::const_iterator getChildrenBegin() const { return this->children_->begin(); }126 inline std::set<const Identifier*>::const_iterator getChildrenBegin() const { return this->children_->begin(); } 124 127 /** @brief Returns the end-iterator of the children-list. @return The end-iterator */ 125 inline std:: list<const Identifier*>::const_iterator getChildrenEnd() const { return this->children_->end(); }128 inline std::set<const Identifier*>::const_iterator getChildrenEnd() const { return this->children_->end(); } 126 129 127 130 /** @brief Returns the direct parents of the class the Identifier belongs to. @return The list of all direct parents */ 128 inline const std:: list<const Identifier*>& getDirectParents() const { return this->directParents_; }131 inline const std::set<const Identifier*>& getDirectParents() const { return this->directParents_; } 129 132 /** @brief Returns the begin-iterator of the direct-parents-list. @return The begin-iterator */ 130 inline std:: list<const Identifier*>::const_iterator getDirectParentsBegin() const { return this->directParents_.begin(); }133 inline std::set<const Identifier*>::const_iterator getDirectParentsBegin() const { return this->directParents_.begin(); } 131 134 /** @brief Returns the end-iterator of the direct-parents-list. @return The end-iterator */ 132 inline std:: list<const Identifier*>::const_iterator getDirectParentsEnd() const { return this->directParents_.end(); }135 inline std::set<const Identifier*>::const_iterator getDirectParentsEnd() const { return this->directParents_.end(); } 133 136 134 137 /** @brief Returns the direct children the class the Identifier belongs to. @return The list of all direct children */ 135 inline const std:: list<const Identifier*>& getDirectChildren() const { return (*this->directChildren_); }138 inline const std::set<const Identifier*>& getDirectChildren() const { return (*this->directChildren_); } 136 139 /** @brief Returns the begin-iterator of the direct-children-list. @return The begin-iterator */ 137 inline std:: list<const Identifier*>::const_iterator getDirectChildrenBegin() const { return this->directChildren_->begin(); }140 inline std::set<const Identifier*>::const_iterator getDirectChildrenBegin() const { return this->directChildren_->begin(); } 138 141 /** @brief Returns the end-iterator of the direct-children-list. @return The end-iterator */ 139 inline std::list<const Identifier*>::const_iterator getDirectChildrenEnd() const { return this->directChildren_->end(); } 142 inline std::set<const Identifier*>::const_iterator getDirectChildrenEnd() const { return this->directChildren_->end(); } 143 144 145 /** @brief Returns the map that stores all Identifiers. @return The map */ 146 static inline const std::map<std::string, Identifier*>& getIdentifierMap() { return Identifier::getIdentifierMapIntern(); } 147 /** @brief Returns a const_iterator to the beginning of the map that stores all Identifiers. @return The const_iterator */ 148 static inline std::map<std::string, Identifier*>::const_iterator getIdentifierMapBegin() { return Identifier::getIdentifierMap().begin(); } 149 /** @brief Returns a const_iterator to the end of the map that stores all Identifiers. @return The const_iterator */ 150 static inline std::map<std::string, Identifier*>::const_iterator getIdentifierMapEnd() { return Identifier::getIdentifierMap().end(); } 151 152 /** @brief Returns the map that stores all Identifiers with their names in lowercase. @return The map */ 153 static inline const std::map<std::string, Identifier*>& getLowercaseIdentifierMap() { return Identifier::getLowercaseIdentifierMapIntern(); } 154 /** @brief Returns a const_iterator to the beginning of the map that stores all Identifiers with their names in lowercase. @return The const_iterator */ 155 static inline std::map<std::string, Identifier*>::const_iterator getLowercaseIdentifierMapBegin() { return Identifier::getLowercaseIdentifierMap().begin(); } 156 /** @brief Returns a const_iterator to the end of the map that stores all Identifiers with their names in lowercase. @return The const_iterator */ 157 static inline std::map<std::string, Identifier*>::const_iterator getLowercaseIdentifierMapEnd() { return Identifier::getLowercaseIdentifierMap().end(); } 158 159 160 /** @brief Returns the map that stores all config values. @return The const_iterator */ 161 inline const std::map<std::string, ConfigValueContainer*>& getConfigValueMap() const { return this->configValues_; } 162 /** @brief Returns a const_iterator to the beginning of the map that stores all config values. @return The const_iterator */ 163 inline std::map<std::string, ConfigValueContainer*>::const_iterator getConfigValueMapBegin() const { return this->configValues_.begin(); } 164 /** @brief Returns a const_iterator to the end of the map that stores all config values. @return The const_iterator */ 165 inline std::map<std::string, ConfigValueContainer*>::const_iterator getConfigValueMapEnd() const { return this->configValues_.end(); } 166 167 /** @brief Returns the map that stores all config values with their names in lowercase. @return The const_iterator */ 168 inline const std::map<std::string, ConfigValueContainer*>& getLowercaseConfigValueMap() const { return this->configValues_LC_; } 169 /** @brief Returns a const_iterator to the beginning of the map that stores all config values with their names in lowercase. @return The const_iterator */ 170 inline std::map<std::string, ConfigValueContainer*>::const_iterator getLowercaseConfigValueMapBegin() const { return this->configValues_LC_.begin(); } 171 /** @brief Returns a const_iterator to the end of the map that stores all config values with their names in lowercase. @return The const_iterator */ 172 inline std::map<std::string, ConfigValueContainer*>::const_iterator getLowercaseConfigValueMapEnd() const { return this->configValues_LC_.end(); } 173 174 175 /** @brief Returns the map that stores all console commands. @return The const_iterator */ 176 inline const std::map<std::string, ExecutorStatic*>& getConsoleCommandMap() const { return this->consoleCommands_; } 177 /** @brief Returns a const_iterator to the beginning of the map that stores all console commands. @return The const_iterator */ 178 inline std::map<std::string, ExecutorStatic*>::const_iterator getConsoleCommandMapBegin() const { return this->consoleCommands_.begin(); } 179 /** @brief Returns a const_iterator to the end of the map that stores all console commands. @return The const_iterator */ 180 inline std::map<std::string, ExecutorStatic*>::const_iterator getConsoleCommandMapEnd() const { return this->consoleCommands_.end(); } 181 182 /** @brief Returns the map that stores all console commands with their names in lowercase. @return The const_iterator */ 183 inline const std::map<std::string, ExecutorStatic*>& getLowercaseConsoleCommandMap() const { return this->consoleCommands_LC_; } 184 /** @brief Returns a const_iterator to the beginning of the map that stores all console commands with their names in lowercase. @return The const_iterator */ 185 inline std::map<std::string, ExecutorStatic*>::const_iterator getLowercaseConsoleCommandMapBegin() const { return this->consoleCommands_LC_.begin(); } 186 /** @brief Returns a const_iterator to the end of the map that stores all console commands with their names in lowercase. @return The const_iterator */ 187 inline std::map<std::string, ExecutorStatic*>::const_iterator getLowercaseConsoleCommandMapEnd() const { return this->consoleCommands_LC_.end(); } 188 189 190 /** @brief Returns true if this class has at least one config value. @return True if this class has at least one config value */ 191 inline bool hasConfigValues() const { return this->bHasConfigValues_; } 192 /** @brief Returns true if this class has at least one console command. @return True if this class has at least one console command */ 193 inline bool hasConsoleCommands() const { return this->bHasConsoleCommands_; } 140 194 141 195 /** @brief Returns true, if a branch of the class-hierarchy is being created, causing all new objects to store their parents. @return The status of the class-hierarchy creation */ … … 148 202 void setNetworkID(unsigned int id); 149 203 204 void addConfigValueContainer(const std::string& varname, ConfigValueContainer* container); 150 205 ConfigValueContainer* getConfigValueContainer(const std::string& varname); 151 void addConfigValueContainer(const std::string& varname, ConfigValueContainer* container); 152 206 ConfigValueContainer* getLowercaseConfigValueContainer(const std::string& varname); 207 208 virtual void addXMLPortParamContainer(const std::string& paramname, XMLPortParamContainer* container) = 0; 153 209 virtual XMLPortParamContainer* getXMLPortParamContainer(const std::string& paramname) = 0; 154 virtual void addXMLPortParamContainer(const std::string& paramname, XMLPortParamContainer* container) = 0; 155 210 211 virtual void addXMLPortObjectContainer(const std::string& sectionname, XMLPortObjectContainer* container) = 0; 156 212 virtual XMLPortObjectContainer* getXMLPortObjectContainer(const std::string& sectionname) = 0; 157 virtual void addXMLPortObjectContainer(const std::string& sectionname, XMLPortObjectContainer* container) = 0; 158 159 static bool identifierIsInList(const Identifier* identifier, const std::list<const Identifier*>& list); 213 214 ExecutorStatic& addConsoleCommand(ExecutorStatic* executor, bool bCreateShortcut); 215 ExecutorStatic* getConsoleCommand(const std::string& name) const; 216 ExecutorStatic* getLowercaseConsoleCommand(const std::string& name) const; 217 218 protected: 219 /** @brief Returns the map that stores all Identifiers. @return The map */ 220 static std::map<std::string, Identifier*>& getIdentifierMapIntern(); 221 /** @brief Returns the map that stores all Identifiers with their names in lowercase. @return The map */ 222 static std::map<std::string, Identifier*>& getLowercaseIdentifierMapIntern(); 160 223 161 224 private: … … 163 226 Identifier(const Identifier& identifier) {} // don't copy 164 227 virtual ~Identifier(); 165 void initialize(std:: list<const Identifier*>* parents);228 void initialize(std::set<const Identifier*>* parents); 166 229 167 230 /** @brief Returns the children of the class the Identifier belongs to. @return The list of all children */ 168 inline std:: list<const Identifier*>& getChildrenIntern() const { return (*this->children_); }231 inline std::set<const Identifier*>& getChildrenIntern() const { return (*this->children_); } 169 232 /** @brief Returns the direct children of the class the Identifier belongs to. @return The list of all direct children */ 170 inline std:: list<const Identifier*>& getDirectChildrenIntern() const { return (*this->directChildren_); }233 inline std::set<const Identifier*>& getDirectChildrenIntern() const { return (*this->directChildren_); } 171 234 172 235 /** … … 188 251 } 189 252 190 std::list<const Identifier*> parents_; //!< The parents of the class the Identifier belongs to 191 std::list<const Identifier*>* children_; //!< The children of the class the Identifier belongs to 192 193 std::list<const Identifier*> directParents_; //!< The direct parents of the class the Identifier belongs to 194 std::list<const Identifier*>* directChildren_; //!< The direct children of the class the Identifier belongs to 195 196 std::string name_; //!< The name of the class the Identifier belongs to 197 198 BaseFactory* factory_; //!< The Factory, able to create new objects of the given class (if available) 199 bool bCreatedOneObject_; //!< True if at least one object of the given type was created (used to determine the need of storing the parents) 200 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) 201 unsigned int classID_; //!< The network ID to identify a class through the network 202 std::map<std::string, ConfigValueContainer*> configValues_; //!< A map to link the string of configurable variables with their ConfigValueContainer 253 std::set<const Identifier*> parents_; //!< The parents of the class the Identifier belongs to 254 std::set<const Identifier*>* children_; //!< The children of the class the Identifier belongs to 255 256 std::set<const Identifier*> directParents_; //!< The direct parents of the class the Identifier belongs to 257 std::set<const Identifier*>* directChildren_; //!< The direct children of the class the Identifier belongs to 258 259 std::string name_; //!< The name of the class the Identifier belongs to 260 261 BaseFactory* factory_; //!< The Factory, able to create new objects of the given class (if available) 262 bool bCreatedOneObject_; //!< True if at least one object of the given type was created (used to determine the need of storing the parents) 263 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) 264 unsigned int classID_; //!< The network ID to identify a class through the network 265 266 bool bHasConfigValues_; //!< True if this class has at least one assigned config value 267 std::map<std::string, ConfigValueContainer*> configValues_; //!< A map to link the string of configurable variables with their ConfigValueContainer 268 std::map<std::string, ConfigValueContainer*> configValues_LC_; //!< A map to link the string of configurable variables with their ConfigValueContainer 269 270 bool bHasConsoleCommands_; //!< True if this class has at least one assigned console command 271 std::map<std::string, ExecutorStatic*> consoleCommands_; //!< All console commands of this class 272 std::map<std::string, ExecutorStatic*> consoleCommands_LC_; //!< All console commands of this class with their names in lowercase 203 273 }; 204 274 205 _CoreExport std::ostream& operator<<(std::ostream& out, const std:: list<const Identifier*>& list);275 _CoreExport std::ostream& operator<<(std::ostream& out, const std::set<const Identifier*>& list); 206 276 207 277 … … 228 298 229 299 public: 230 ClassIdentifier<T>* registerClass(std:: list<const Identifier*>* parents, const std::string& name, bool bRootClass);300 ClassIdentifier<T>* registerClass(std::set<const Identifier*>* parents, const std::string& name, bool bRootClass); 231 301 void addObject(T* object); 232 void removeObjects() const;233 302 void setName(const std::string& name); 303 /** @brief Returns the list of all existing objects of this class. @return The list */ 234 304 inline const ObjectList<T>* getObjects() const { return this->objects_; } 305 /** @brief Returns a list of all existing objects of this class. @return The list */ 306 inline const ObjectList<BaseObject>* getObjectList() const { return (ObjectList<BaseObject>*)this->objects_; } 307 308 void updateConfigValues() const; 235 309 236 310 XMLPortParamContainer* getXMLPortParamContainer(const std::string& paramname); … … 245 319 ~ClassIdentifier() {} // don't delete 246 320 247 ObjectList<T>* objects_; //!< The ObjectList, containing all objects of type T248 bool bSetName_; //!< True if the name is set249 std::map<std::string, XMLPortClassParamContainer<T>*> xmlportParamContainers_; 250 std::map<std::string, XMLPortClassObjectContainer<T, class O>*> xmlportObjectContainers_; 321 ObjectList<T>* objects_; //!< The ObjectList, containing all objects of type T 322 bool bSetName_; //!< True if the name is set 323 std::map<std::string, XMLPortClassParamContainer<T>*> xmlportParamContainers_; //!< All loadable parameters 324 std::map<std::string, XMLPortClassObjectContainer<T, class O>*> xmlportObjectContainers_; //!< All attachable objects 251 325 }; 252 326 … … 270 344 */ 271 345 template <class T> 272 ClassIdentifier<T>* ClassIdentifier<T>::registerClass(std:: list<const Identifier*>* parents, const std::string& name, bool bRootClass)273 { 274 COUT(5) << "*** ClassIdentifier: Register Class in " << name << "-Singleton." << std::endl;346 ClassIdentifier<T>* ClassIdentifier<T>::registerClass(std::set<const Identifier*>* parents, const std::string& name, bool bRootClass) 347 { 348 this->setName(name); 275 349 276 350 // Check if at least one object of the given type was created 277 if (!this->bCreatedOneObject_ )351 if (!this->bCreatedOneObject_ && Identifier::isCreatingHierarchy()) 278 352 { 279 353 // If no: We have to store the informations and initialize the Identifier 280 this->setName(name);281 282 354 COUT(4) << "*** ClassIdentifier: Register Class in " << name << "-Singleton -> Initialize Singleton." << std::endl; 283 355 if (bRootClass) … … 301 373 this->name_ = name; 302 374 this->bSetName_ = true; 375 Identifier::getIdentifierMapIntern()[name] = this; 376 Identifier::getLowercaseIdentifierMapIntern()[getLowercase(name)] = this; 303 377 } 304 378 } … … 316 390 317 391 /** 318 @brief Removes all objects of the corresponding class. 319 */ 320 template <class T> 321 void ClassIdentifier<T>::removeObjects() const 322 { 323 for (Iterator<T> it = this->objects_->start(); it;) 324 delete *(it++); 325 } 326 392 @brief Updates the config-values of all existing objects of this class by calling their setConfigValues() function. 393 */ 394 template <class T> 395 void ClassIdentifier<T>::updateConfigValues() const 396 { 397 for (Iterator<T> it = this->objects_->start(); it; ++it) 398 ((T*)*it)->setConfigValues(); 399 } 400 401 /** 402 @brief Returns a XMLPortParamContainer that loads a parameter of this class. 403 @param paramname The name of the parameter 404 @return The container 405 */ 327 406 template <class T> 328 407 XMLPortParamContainer* ClassIdentifier<T>::getXMLPortParamContainer(const std::string& paramname) … … 335 414 } 336 415 416 /** 417 @brief Adds a new XMLPortParamContainer that loads a parameter of this class. 418 @param paramname The name of the parameter 419 @param container The container 420 */ 337 421 template <class T> 338 422 void ClassIdentifier<T>::addXMLPortParamContainer(const std::string& paramname, XMLPortParamContainer* container) … … 341 425 } 342 426 427 /** 428 @brief Returns a XMLPortObjectContainer that attaches an object to this class. 429 @param sectionname The name of the section that contains the attachable objects 430 @return The container 431 */ 343 432 template <class T> 344 433 XMLPortObjectContainer* ClassIdentifier<T>::getXMLPortObjectContainer(const std::string& sectionname) … … 351 440 } 352 441 442 /** 443 @brief Adds a new XMLPortObjectContainer that attaches an object to this class. 444 @param sectionname The name of the section that contains the attachable objects 445 @param container The container 446 */ 353 447 template <class T> 354 448 void ClassIdentifier<T>::addXMLPortObjectContainer(const std::string& sectionname, XMLPortObjectContainer* container) -
code/trunk/src/orxonox/core/InputBuffer.cc
r1051 r1052 29 29 30 30 #include "InputBuffer.h" 31 #include "InputManager.h" 31 32 #include "util/Clipboard.h" 32 33 33 34 namespace orxonox 34 35 { 35 InputBuffer::InputBuffer( OIS::Keyboard* keyboard)36 InputBuffer::InputBuffer() 36 37 { 37 38 this->bActivated_ = false; 38 39 this->allowedChars_ = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZäöüÄÖÜ0123456789 \\\"().:,;_-+*/=!?<>[|]"; 39 this->keyboard_ = keyboard;40 this->keyboard_ = InputManager::getSingleton().getKeyboard(); 40 41 this->buffer_ = ""; 41 42 -
code/trunk/src/orxonox/core/InputBuffer.h
r1051 r1052 58 58 59 59 public: 60 InputBuffer( OIS::Keyboard* keyboard);60 InputBuffer(); 61 61 62 62 template <class T> -
code/trunk/src/orxonox/core/InputHandler.cc
r1024 r1052 66 66 { 67 67 // simply write the key number (i) in the string 68 this->bindingsKeyPressed_[i] = ConvertValueAndReturn<int, std::string>(i);69 this->bindingsKeyReleased_[i] = ConvertValueAndReturn<int, std::string>(i);68 this->bindingsKeyPressed_[i] = getConvertedValue<int, std::string>(i); 69 this->bindingsKeyReleased_[i] = getConvertedValue<int, std::string>(i); 70 70 } 71 71 return true; -
code/trunk/src/orxonox/core/Language.cc
r871 r1052 28 28 /** 29 29 @file Language.cc 30 @brief Implementation of the Language and the LanguageEntry class .30 @brief Implementation of the Language and the LanguageEntry classes. 31 31 */ 32 32 33 33 #include <fstream> 34 34 35 #include "CoreIncludes.h"36 35 #include "Language.h" 36 #include "CoreSettings.h" 37 37 38 38 namespace orxonox … … 47 47 LanguageEntry::LanguageEntry(const std::string& fallbackEntry) 48 48 { 49 RegisterRootObject(LanguageEntry);50 51 49 this->fallbackEntry_ = fallbackEntry; 52 50 this->localisedEntry_ = fallbackEntry; // Set the localisation to the fallback entry, for the case that no translation gets assigned … … 61 59 { 62 60 // Check if the translation is more than just an empty string 63 if ( localisation.compare("") != 0)61 if ((localisation != "") && (localisation.size() > 0)) 64 62 { 65 63 this->localisedEntry_ = localisation; … … 91 89 Language::Language() 92 90 { 93 RegisterRootObject(Language);94 95 91 this->defaultLanguage_ = "default"; 96 92 this->defaultLocalisation_ = "ERROR: LANGUAGE ENTRY DOESN'T EXIST!"; … … 101 97 102 98 /** 103 @brief Function to collect the SetConfigValue-macro calls.104 */105 void Language::setConfigValues()106 {107 SetConfigValue(language_, this->defaultLanguage_).description("The language of the ingame text");108 109 // Read the translation file after the language was configured110 this->readTranslatedLanguageFile();111 }112 113 /**114 99 @brief Returns a reference to the only existing instance of the Language class and calls the setConfigValues() function. 115 100 @return The reference to the only existing instance … … 117 102 Language& Language::getLanguage() 118 103 { 119 // Use static variables to avoid conflicts while executing this code before main() 120 static Language theOnlyLanguageObject = Language(); 121 static bool bCreatingTheOnlyLanguageObject = true; 122 123 // This workaround is used to set a description of the own config value without creating an infinite recursion 124 if (bCreatingTheOnlyLanguageObject) 125 { 126 bCreatingTheOnlyLanguageObject = false; 127 theOnlyLanguageObject.setConfigValues(); 128 } 129 130 return theOnlyLanguageObject; 104 static Language instance = Language(); 105 return instance; 131 106 } 132 107 … … 244 219 245 220 // Check if the line is empty 246 if ( lineString.compare("") != 0)221 if ((lineString != "") && (lineString.size() > 0)) 247 222 { 248 223 unsigned int pos = lineString.find('='); … … 252 227 this->createEntry(lineString.substr(0, pos), lineString.substr(pos + 1)); 253 228 else 229 { 254 230 COUT(2) << "Warning: Invalid language entry \"" << lineString << "\" in " << getFileName(this->defaultLanguage_) << std::endl; 231 } 255 232 } 256 233 } … … 264 241 void Language::readTranslatedLanguageFile() 265 242 { 266 COUT(4) << "Read translated language file (" << this->language_<< ")." << std::endl;243 COUT(4) << "Read translated language file (" << CoreSettings::getLanguage() << ")." << std::endl; 267 244 268 245 // Open the file 269 246 std::ifstream file; 270 file.open(getFileName( this->language_).c_str(), std::fstream::in);247 file.open(getFileName(CoreSettings::getLanguage()).c_str(), std::fstream::in); 271 248 272 249 if (!file.is_open()) 273 250 { 274 251 COUT(1) << "An error occurred in Language.cc:" << std::endl; 275 COUT(1) << "Error: Couldn't open file " << getFileName( this->language_) << " to read the translated language entries!" << std::endl;276 ResetConfigValue(language_);252 COUT(1) << "Error: Couldn't open file " << getFileName(CoreSettings::getLanguage()) << " to read the translated language entries!" << std::endl; 253 CoreSettings::resetLanguage(); 277 254 COUT(3) << "Info: Reset language to " << this->defaultLanguage_ << "." << std::endl; 278 255 return; … … 288 265 289 266 // Check if the line is empty 290 if ( lineString.compare("") != 0)267 if ((lineString != "") && (lineString.size() > 0)) 291 268 { 292 269 unsigned int pos = lineString.find('='); … … 304 281 } 305 282 else 306 COUT(2) << "Warning: Invalid language entry \"" << lineString << "\" in " << getFileName(this->language_) << std::endl; 283 { 284 COUT(2) << "Warning: Invalid language entry \"" << lineString << "\" in " << getFileName(CoreSettings::getLanguage()) << std::endl; 285 } 307 286 } 308 287 } … … 330 309 331 310 // Iterate through the list an write the lines into the file 332 for ( Iterator<LanguageEntry> it = ObjectList<LanguageEntry>::start(); it; ++it)333 { 334 file << it->getLabel() << "=" << it->getDefault() << std::endl;311 for (std::map<std::string, LanguageEntry*>::const_iterator it = this->languageEntries_.begin(); it != this->languageEntries_.end(); ++it) 312 { 313 file << (*it).second->getLabel() << "=" << (*it).second->getDefault() << std::endl; 335 314 } 336 315 -
code/trunk/src/orxonox/core/Language.h
r871 r1052 49 49 50 50 #include "CorePrereqs.h" 51 #include "OrxonoxClass.h"52 51 53 52 … … 65 64 // ############################### 66 65 //! The LanguageEntry class stores the default- and the translated string of a given entry in the language file. 67 class _CoreExport LanguageEntry : public OrxonoxClass66 class _CoreExport LanguageEntry 68 67 { 69 68 public: … … 112 111 // ############################### 113 112 //! The Language class manges the language files and entries and stores the LanguageEntry objects in a map. 114 class _CoreExport Language : public OrxonoxClass113 class _CoreExport Language 115 114 { 116 template <class T> 117 friend class ClassIdentifier; // forward declaration because of the private destructor 115 friend class CoreSettings; 118 116 119 117 public: 120 118 static Language& getLanguage(); 121 void setConfigValues();122 119 void addEntry(const LanguageEntryLabel& label, const std::string& entry); 123 120 const std::string& getLocalisation(const LanguageEntryLabel& label) const; … … 134 131 LanguageEntry* createEntry(const LanguageEntryLabel& label, const std::string& entry); 135 132 136 std::string language_; //!< The configured language137 133 std::string defaultLanguage_; //!< The default language 138 134 std::string defaultLocalisation_; //!< The returned string, if an entry unavailable entry is requested -
code/trunk/src/orxonox/core/Loader.cc
r1021 r1052 34 34 #include "CoreIncludes.h" 35 35 #include "Script.h" 36 #include "Namespace.h" 36 37 37 38 #include "util/tinyxml/ticpp.h" … … 129 130 xmlfile.Parse(lua->getLuaOutput(), true); 130 131 131 for ( ticpp::Iterator<ticpp::Element> child = xmlfile.FirstChildElement(false); child != child.end(); child++ ) 132 { 133 Identifier* identifier = ID(child->Value()); 134 if (identifier) 135 { 136 if (Loader::currentMask_s.isIncluded(identifier)) 137 { 138 COUT(4) << " fabricating " << child->Value() << "..." << std::endl; 139 BaseObject* newObject = identifier->fabricate(); 140 newObject->setLoaderIndentation(" "); 141 newObject->setLevel(level); 142 newObject->XMLPort(*child, true); 143 COUT(5) << " ...fabricated " << child->Value() << " (objectname " << newObject->getName() << ")." << std::endl; 144 } 145 } 146 else 147 { 148 COUT(2) << " Warning: '" << child->Value() << "' is not a valid classname." << std::endl; 149 } 150 } 132 ticpp::Element rootElement; 133 rootElement.SetAttribute("name", "root"); 134 rootElement.SetAttribute("bAutogenerated", true); 135 136 for (ticpp::Iterator<ticpp::Element> child = xmlfile.FirstChildElement(false); child != child.end(); child++) 137 rootElement.InsertEndChild(*child); 138 139 COUT(4) << " creating root-namespace..." << std::endl; 140 Namespace* rootNamespace = new Namespace(); 141 rootNamespace->setLoaderIndentation(" "); 142 rootNamespace->setLevel(level); 143 rootNamespace->setNamespace(rootNamespace); 144 rootNamespace->setRoot(true); 145 rootNamespace->XMLPort(rootElement, XMLPort::LoadObject); 151 146 152 147 COUT(0) << "Finished loading " << level->getFile() << "." << std::endl; 148 149 COUT(4) << "Namespace-tree:" << std::endl << rootNamespace->toString(" ") << std::endl; 153 150 154 151 return true; -
code/trunk/src/orxonox/core/MetaObjectList.h
r1024 r1052 99 99 100 100 101 COUT(5) << "*** MetaObjectList: Removing Object from " << this->element_->object_->getIdentifier()->getName() << "-list." << std::endl;101 COUT(5) << "*** MetaObjectList: Removing Object from " << ClassManager<T>::getIdentifier()->getName() << "-list." << std::endl; 102 102 delete this->element_; 103 103 } -
code/trunk/src/orxonox/core/OrxonoxClass.h
r871 r1052 37 37 #define _OrxonoxClass_H__ 38 38 39 #include < list>39 #include <set> 40 40 #include <string> 41 41 … … 67 67 68 68 /** @brief Returns the list of all parents of the object. @return The list */ 69 inline std:: list<const Identifier*>* getParents() const { return this->parents_; }69 inline std::set<const Identifier*>* getParents() const { return this->parents_; } 70 70 71 71 /** @brief Creates the parents-list. */ 72 inline void createParents() { this->parents_ = new std:: list<const Identifier*>(); }72 inline void createParents() { this->parents_ = new std::set<const Identifier*>(); } 73 73 74 74 /** @brief Returns the MetaObjectList of the object, containing a link to all ObjectLists and ObjectListElements the object is registered in. @return The list */ … … 157 157 private: 158 158 Identifier* identifier_; //!< The Identifier of the object 159 std:: list<const Identifier*>* parents_; //!< List of all parents of the object159 std::set<const Identifier*>* parents_; //!< List of all parents of the object 160 160 MetaObjectList metaList_; //!< MetaObjectList, containing all ObjectLists and ObjectListElements the object is registered in 161 161 }; -
code/trunk/src/orxonox/core/OutputHandler.cc
r871 r1052 31 31 */ 32 32 33 #include " DebugLevel.h"33 #include "CoreSettings.h" 34 34 #include "OutputHandler.h" 35 #include "ConsoleCommand.h" 35 36 36 37 namespace orxonox 37 38 { 39 ConsoleCommandShortcutGeneric(log, createExecutor(createFunctor(&OutputHandler::log), "log", AccessLevel::None)); 40 38 41 /** 39 42 @brief Constructor: Opens the logfile and writes the first line. … … 44 47 this->logfilename_ = logfilename; 45 48 this->logfile_.open(this->logfilename_.c_str(), std::fstream::out); 46 this->logfile_ << "Started log " << std::endl;49 this->logfile_ << "Started log at yyyy/mm/dd hh:mm:ss" << std::endl; 47 50 this->logfile_.flush(); 48 51 } … … 74 77 int OutputHandler::getSoftDebugLevel(OutputHandler::OutputDevice device) 75 78 { 76 return DebugLevel::getSoftDebugLevel(device);79 return CoreSettings::getSoftDebugLevel(device); 77 80 } 78 81 -
code/trunk/src/orxonox/core/OutputHandler.h
r871 r1052 58 58 59 59 static OutputHandler& getOutStream(); 60 61 /** @brief Puts some text on the outstream. @param text The text */ 62 static inline std::string log(const std::string& text) 63 { OutputHandler::getOutStream().setOutputLevel(0); OutputHandler::getOutStream().output(text + "\n"); return text; } 60 64 61 65 /** @brief Returns a reference to the logfile. @return The logfile */ -
code/trunk/src/orxonox/core/Tickable.cc
r1021 r1052 27 27 28 28 #include "core/CoreIncludes.h" 29 #include "core/ConsoleCommand.h" 29 30 #include "Tickable.h" 30 31 -
code/trunk/src/orxonox/core/XMLPort.cc
r871 r1052 29 29 #include "Language.h" 30 30 #include "Loader.h" 31 #include "Namespace.h" 32 #include "CoreIncludes.h" 31 33 32 34 namespace orxonox 33 35 { 34 // ###############################35 // ### XMLPortParamContainer ###36 // ###############################37 XMLPortParamContainer::XMLPortParamContainer()38 {39 this->bAddedDescription_ = false;40 this->bAddedDefaultValues_ = false;41 }42 43 XMLPortParamContainer& XMLPortParamContainer::description(const std::string description)44 {45 if (!this->bAddedDescription_)46 {47 this->description_ = std::string("XMLPortParamContainer::" + this->classname_ + "::" + this->paramname_);48 AddLanguageEntry(this->description_, description);49 this->bAddedDescription_ = true;50 }51 52 return (*this);53 }54 55 const std::string& XMLPortParamContainer::getDescription()56 {57 return GetLocalisation(this->description_);58 }59 60 61 36 // ################################ 62 37 // ### XMLPortObjectContainer ### 63 38 // ################################ 64 XMLPortObjectContainer::XMLPortObjectContainer()65 {66 this->bAddedDescription_ = false;67 }68 69 XMLPortObjectContainer& XMLPortObjectContainer::description(const std::string description)70 {71 if (!this->bAddedDescription_)72 {73 this->description_ = std::string("XMLPortObjectContainer::" + this->classname_ + "::" + this->sectionname_);74 AddLanguageEntry(this->description_, description);75 this->bAddedDescription_ = true;76 }77 78 return (*this);79 }80 81 const std::string& XMLPortObjectContainer::getDescription()82 {83 return GetLocalisation(this->description_);84 }85 86 39 bool XMLPortObjectContainer::identifierIsIncludedInLoaderMask(const Identifier* identifier) 87 40 { 88 return Loader::currentMask_s.isIncluded(identifier);41 return ((!this->bApplyLoaderMask_) || identifier->isA(Class(Namespace)) || Loader::currentMask_s.isIncluded(identifier)); 89 42 } 90 43 } -
code/trunk/src/orxonox/core/XMLPort.h
r871 r1052 32 32 #include "util/MultiTypeMath.h" 33 33 #include "util/tinyxml/ticpp.h" 34 #include "util/SubString.h" 35 #include "Functor.h" 34 #include "Executor.h" 36 35 #include "Debug.h" 37 36 #include "CoreIncludes.h" … … 41 40 42 41 43 #define XMLPortParam(classname, paramname, loadfunction, savefunction, xmlelement, loading) \ 44 orxonox::XMLPortClassParamContainer<classname>* xmlcontainer##loadfunction##savefunction = (orxonox::XMLPortClassParamContainer<classname>*)(this->getIdentifier()->getXMLPortParamContainer(paramname)); \ 45 if (!xmlcontainer##loadfunction##savefunction) \ 42 #define XMLPortParam(classname, paramname, loadfunction, savefunction, xmlelement, mode) \ 43 XMLPortParamGeneric(xmlcontainer##loadfunction##savefunction, classname, paramname, orxonox::createExecutor(orxonox::createFunctor(&classname::loadfunction), #loadfunction), orxonox::createExecutor(orxonox::createFunctor(&classname::savefunction), #savefunction), xmlelement, mode) 44 #define XMLPortParam_Template(classname, paramname, loadtemplate, loadfunction, savetemplate, savefunction, xmlelement, mode) \ 45 XMLPortParamGeneric(xmlcontainer##loadfunction##savefunction, classname, paramname, orxonox::createExecutor(orxonox::createFunctor loadtemplate (&classname::loadfunction), #loadfunction), orxonox::createExecutor(orxonox::createFunctor savetemplate (&classname::savefunction), #savefunction), xmlelement, mode) 46 47 #define XMLPortParamLoadOnly(classname, paramname, loadfunction, xmlelement, mode) \ 48 XMLPortParamGeneric(xmlcontainer##loadfunction##0, classname, paramname, orxonox::createExecutor(orxonox::createFunctor(&classname::loadfunction), #loadfunction), 0, xmlelement, mode) 49 #define XMLPortParamLoadOnly_Template(classname, paramname, loadtemplate, loadfunction, xmlelement, mode) \ 50 XMLPortParamGeneric(xmlcontainer##loadfunction##0, classname, paramname, orxonox::createExecutor(orxonox::createFunctor loadtemplate (&classname::loadfunction), #loadfunction), 0, xmlelement, mode) 51 52 #define XMLPortParamGeneric(containername, classname, paramname, loadexecutor, saveexecutor, xmlelement, mode) \ 53 orxonox::XMLPortClassParamContainer<classname>* containername = (orxonox::XMLPortClassParamContainer<classname>*)(this->getIdentifier()->getXMLPortParamContainer(paramname)); \ 54 if (!containername) \ 46 55 { \ 47 xmlcontainer##loadfunction##savefunction = new orxonox::XMLPortClassParamContainer<classname>(this->getIdentifier()->getName(), std::string(paramname), createFunctor(&classname::loadfunction), createFunctor(&classname::savefunction)); \48 this->getIdentifier()->addXMLPortParamContainer(paramname, xmlcontainer##loadfunction##savefunction); \56 containername = new orxonox::XMLPortClassParamContainer<classname>(std::string(paramname), loadexecutor, saveexecutor); \ 57 this->getIdentifier()->addXMLPortParamContainer(paramname, containername); \ 49 58 } \ 50 xmlcontainer##loadfunction##savefunction->port(this, xmlelement, loading) 51 52 #define XMLPortParamLoadOnly(classname, paramname, loadfunction, xmlelement, loading) \ 53 orxonox::XMLPortClassParamContainer<classname>* xmlcontainer##loadfunction##savefunction = (orxonox::XMLPortClassParamContainer<classname>*)(this->getIdentifier()->getXMLPortParamContainer(paramname)); \ 54 if (!xmlcontainer##loadfunction##savefunction) \ 59 containername->port(this, xmlelement, mode) 60 61 62 #define XMLPortObject(classname, objectclass, sectionname, loadfunction, savefunction, xmlelement, mode, bApplyLoaderMask, bLoadBefore) \ 63 XMLPortObjectGeneric(xmlcontainer##loadfunction##savefunction, classname, objectclass, sectionname, orxonox::createExecutor(orxonox::createFunctor(&classname::loadfunction), #loadfunction), orxonox::createExecutor(orxonox::createFunctor(&classname::savefunction), #savefunction), xmlelement, mode, bApplyLoaderMask, bLoadBefore) 64 #define XMLPortObject_Template(classname, objectclass, sectionname, loadtemplate, loadfunction, savetemplate, savefunction, xmlelement, mode, bApplyLoaderMask, bLoadBefore) \ 65 XMLPortObjectGeneric(xmlcontainer##loadfunction##savefunction, classname, objectclass, sectionname, orxonox::createExecutor(orxonox::createFunctor loadtemplate (&classname::loadfunction), #loadfunction), orxonox::createExecutor(orxonox::createFunctor savetemplate (&classname::savefunction), #savefunction), xmlelement, mode, bApplyLoaderMask, bLoadBefore) 66 67 #define XMLPortObjectGeneric(containername, classname, objectclass, sectionname, loadexecutor, saveexecutor, xmlelement, mode, bApplyLoaderMask, bLoadBefore) \ 68 orxonox::XMLPortClassObjectContainer<classname, objectclass>* containername = (orxonox::XMLPortClassObjectContainer<classname, objectclass>*)(this->getIdentifier()->getXMLPortObjectContainer(sectionname)); \ 69 if (!containername) \ 55 70 { \ 56 xmlcontainer##loadfunction##savefunction = new orxonox::XMLPortClassParamContainer<classname>(this->getIdentifier()->getName(), std::string(paramname), createFunctor(&classname::loadfunction), 0); \57 this->getIdentifier()->addXMLPort ParamContainer(paramname, xmlcontainer##loadfunction##savefunction); \71 containername = new orxonox::XMLPortClassObjectContainer<classname, objectclass>(std::string(sectionname), loadexecutor, saveexecutor, bApplyLoaderMask, bLoadBefore); \ 72 this->getIdentifier()->addXMLPortObjectContainer(sectionname, containername); \ 58 73 } \ 59 xmlcontainer##loadfunction##savefunction->port(this, xmlelement, loading) 60 61 #define XMLPortObject(classname, objectclass, sectionname, loadfunction, savefunction, xmlelement, loading) \ 62 orxonox::XMLPortClassObjectContainer<classname, objectclass>* xmlcontainer##loadfunction##savefunction = (orxonox::XMLPortClassObjectContainer<classname, objectclass>*)(this->getIdentifier()->getXMLPortObjectContainer(sectionname)); \ 63 if (!xmlcontainer##loadfunction##savefunction) \ 64 { \ 65 xmlcontainer##loadfunction##savefunction = new orxonox::XMLPortClassObjectContainer<classname, objectclass>(this->getIdentifier()->getName(), std::string(sectionname), &classname::loadfunction, &classname::savefunction); \ 66 this->getIdentifier()->addXMLPortObjectContainer(sectionname, xmlcontainer##loadfunction##savefunction); \ 67 } \ 68 xmlcontainer##loadfunction##savefunction->port(this, xmlelement, loading) 74 containername->port(this, xmlelement, mode) 69 75 70 76 71 77 namespace orxonox 72 78 { 79 80 #ifndef _XMLPort_Mode__ 81 #define _XMLPort_Mode__ 82 namespace XMLPort 83 { 84 enum Mode 85 { 86 LoadObject, 87 SaveObject 88 }; 89 } 90 #endif 91 73 92 // ############################### 74 93 // ### XMLPortParamContainer ### … … 76 95 class _CoreExport XMLPortParamContainer 77 96 { 97 enum ParseResult 98 { 99 PR_not_started, 100 PR_finished, 101 PR_waiting_for_default_values 102 }; 103 78 104 public: 79 XMLPortParamContainer(); 105 XMLPortParamContainer() 106 { this->parseResult_ = PR_not_started; } 107 virtual ~XMLPortParamContainer() {} 80 108 81 109 inline const std::string& getName() const 82 110 { return this->paramname_; } 83 111 84 XMLPortParamContainer& description(const std::string description); 85 const std::string& getDescription(); 86 87 XMLPortParamContainer& defaultValues(const MultiTypeMath& param1 = MT_null, const MultiTypeMath& param2 = MT_null, const MultiTypeMath& param3 = MT_null, const MultiTypeMath& param4 = MT_null, const MultiTypeMath& param5 = MT_null) 88 { 89 this->defaultValues_[0] = param1; 90 this->defaultValues_[1] = param2; 91 this->defaultValues_[2] = param3; 92 this->defaultValues_[3] = param4; 93 this->defaultValues_[4] = param5; 94 95 return (*this); 96 } 112 virtual XMLPortParamContainer& description(const std::string description) = 0; 113 virtual const std::string& getDescription() = 0; 114 115 virtual XMLPortParamContainer& defaultValue(unsigned int index, const MultiTypeMath& param) = 0; 116 virtual XMLPortParamContainer& defaultValues(const MultiTypeMath& param1) = 0; 117 virtual XMLPortParamContainer& defaultValues(const MultiTypeMath& param1, const MultiTypeMath& param2) = 0; 118 virtual XMLPortParamContainer& defaultValues(const MultiTypeMath& param1, const MultiTypeMath& param2, const MultiTypeMath& param3) = 0; 119 virtual XMLPortParamContainer& defaultValues(const MultiTypeMath& param1, const MultiTypeMath& param2, const MultiTypeMath& param3, const MultiTypeMath& param4) = 0; 120 virtual XMLPortParamContainer& defaultValues(const MultiTypeMath& param1, const MultiTypeMath& param2, const MultiTypeMath& param3, const MultiTypeMath& param4, const MultiTypeMath& param5) = 0; 97 121 98 122 protected: 99 std::string classname_;100 123 std::string paramname_; 101 MultiTypeMath defaultValues_[5]; 102 103 private: 104 LanguageEntryLabel description_; 105 bool bAddedDescription_; 106 bool bAddedDefaultValues_; 124 ParseResult parseResult_; 125 107 126 }; 108 127 … … 110 129 class XMLPortClassParamContainer : public XMLPortParamContainer 111 130 { 131 struct ParseParams 132 { 133 T* object; 134 Element* xmlelement; 135 XMLPort::Mode mode; 136 }; 137 112 138 public: 113 XMLPortClassParamContainer(const std::string classname, const std::string paramname, FunctorMember<T>* loadfunction, FunctorMember<T>* savefunction) 114 { 115 this->classname_ = classname; 139 XMLPortClassParamContainer(const std::string paramname, ExecutorMember<T>* loadexecutor, ExecutorMember<T>* saveexecutor) 140 { 116 141 this->paramname_ = paramname; 117 this->loadfunction_ = loadfunction; 118 this->savefunction_ = savefunction; 119 } 120 121 XMLPortParamContainer& port(T* object, Element& xmlelement, bool loading) 122 { 123 if (loading) 142 this->loadexecutor_ = loadexecutor; 143 this->saveexecutor_ = saveexecutor; 144 } 145 146 XMLPortParamContainer& port(T* object, Element& xmlelement, XMLPort::Mode mode) 147 { 148 this->parseParams_.object = object; 149 this->parseParams_.xmlelement = &xmlelement; 150 this->parseParams_.mode = mode; 151 152 if (mode == XMLPort::LoadObject) 124 153 { 125 154 try 126 155 { 127 156 std::string attribute = xmlelement.GetAttribute(this->paramname_); 128 if ( attribute.size() > 0)157 if ((attribute.size() > 0) || (this->loadexecutor_->allDefaultValuesSet())) 129 158 { 130 SubString tokens(attribute, ",", SubString::WhiteSpaces, false, '\\', '"', '(', ')', '\0'); 131 if ((unsigned int)tokens.size() >= (unsigned int)this->loadfunction_->getParamCount()) 132 { 133 COUT(5) << object->getLoaderIndentation() << "Loading parameter " << this->paramname_ << " in " << this->classname_ << " (objectname " << object->getName() << ") with "; 134 if (this->loadfunction_->getParamCount() == 1) 135 { 136 COUT(5) << "1 parameter (using whole string):" << std::endl; 137 COUT(5) << object->getLoaderIndentation() << " " << attribute << std::endl; 138 (*this->loadfunction_)(object, MultiTypeMath(attribute)); 139 } 140 else 141 { 142 COUT(5) << tokens.size() << " parameter (using MultiTypeMath)." << std::endl; 143 MultiTypeMath param1 = MT_null, param2 = MT_null, param3 = MT_null, param4 = MT_null, param5 = MT_null; 144 if (tokens.size() >= 1) param1 = tokens[0]; 145 if (tokens.size() >= 2) param2 = tokens[1]; 146 if (tokens.size() >= 3) param3 = tokens[2]; 147 if (tokens.size() >= 4) param4 = tokens[3]; 148 if (tokens.size() >= 5) param5 = tokens[4]; 149 COUT(5) << object->getLoaderIndentation() << " " << attribute << std::endl; 150 COUT(5) << object->getLoaderIndentation() << " " << param1 << ", " << param2 << ", " << param3 << ", " << param4 << ", " << param5 << std::endl; 151 152 (*this->loadfunction_)(object, param1, param2, param3, param4, param5); 153 } 154 } 159 COUT(5) << object->getLoaderIndentation() << "Loading parameter " << this->paramname_ << " in " << object->getIdentifier()->getName() << " (objectname " << object->getName() << ")." << std::endl << object->getLoaderIndentation(); 160 if (this->loadexecutor_->parse(object, attribute, ",")) 161 this->parseResult_ = PR_finished; 155 162 else 156 { 157 COUT(2) << object->getLoaderIndentation() << "Warning: Parameter \"" << this->paramname_ << "\" in \"" << this->classname_ << "\" (objectname: " << object->getName() << ") is incomplete and couln't be loaded." << std::endl; 158 } 163 this->parseResult_ = PR_waiting_for_default_values; 159 164 } 160 165 } … … 162 167 { 163 168 COUT(1) << std::endl; 164 COUT(1) << "An error occurred in XMLPort.h while loading attribute '" << this->paramname_ << "' of '" << this->classname_<< "' (objectname: " << object->getName() << ") in " << object->getLevelfile() << ":" << std::endl;169 COUT(1) << "An error occurred in XMLPort.h while loading attribute '" << this->paramname_ << "' of '" << object->getIdentifier()->getName() << "' (objectname: " << object->getName() << ") in " << object->getLevelfile() << ":" << std::endl; 165 170 COUT(1) << ex.what() << std::endl; 166 171 } … … 168 173 else 169 174 { 170 if (this->save function_)175 if (this->saveexecutor_) 171 176 { 172 177 // xmlelement.SetAttribute(this->paramname_, "..."); … … 177 182 } 178 183 184 XMLPortParamContainer& port(const ParseParams& parseParams) 185 { 186 return this->port(parseParams.object, *parseParams.xmlelement, parseParams.mode); 187 } 188 189 XMLPortParamContainer& portIfWaitingForDefaultValues(const ParseResult& result, const ParseParams& params) 190 { 191 if (result == PR_waiting_for_default_values) 192 return this->port(params); 193 else 194 return (*this); 195 } 196 197 virtual XMLPortParamContainer& description(const std::string description) 198 { this->loadexecutor_->setDescription(description); return (*this); } 199 virtual const std::string& getDescription() 200 { return this->loadexecutor_->getDescription(); } 201 202 virtual XMLPortParamContainer& defaultValue(unsigned int index, const MultiTypeMath& param) 203 { 204 if (!this->loadexecutor_->defaultValueSet(index)) 205 this->loadexecutor_->setDefaultValue(index, param); 206 return this->portIfWaitingForDefaultValues(this->parseResult_, this->parseParams_); 207 } 208 virtual XMLPortParamContainer& defaultValues(const MultiTypeMath& param1) 209 { 210 if (!this->loadexecutor_->defaultValueSet(0)) 211 this->loadexecutor_->setDefaultValues(param1); 212 return this->portIfWaitingForDefaultValues(this->parseResult_, this->parseParams_); 213 } 214 virtual XMLPortParamContainer& defaultValues(const MultiTypeMath& param1, const MultiTypeMath& param2) 215 { 216 if ((!this->loadexecutor_->defaultValueSet(0)) || (!this->loadexecutor_->defaultValueSet(1))) 217 this->loadexecutor_->setDefaultValues(param1, param2); 218 return this->portIfWaitingForDefaultValues(this->parseResult_, this->parseParams_); 219 } 220 virtual XMLPortParamContainer& defaultValues(const MultiTypeMath& param1, const MultiTypeMath& param2, const MultiTypeMath& param3) 221 { 222 if ((!this->loadexecutor_->defaultValueSet(0)) || (!this->loadexecutor_->defaultValueSet(1)) || (!this->loadexecutor_->defaultValueSet(2))) 223 this->loadexecutor_->setDefaultValues(param1, param2, param3); 224 return this->portIfWaitingForDefaultValues(this->parseResult_, this->parseParams_); 225 } 226 virtual XMLPortParamContainer& defaultValues(const MultiTypeMath& param1, const MultiTypeMath& param2, const MultiTypeMath& param3, const MultiTypeMath& param4) 227 { 228 if ((!this->loadexecutor_->defaultValueSet(0)) || (!this->loadexecutor_->defaultValueSet(1)) || (!this->loadexecutor_->defaultValueSet(2)) || (!this->loadexecutor_->defaultValueSet(3))) 229 this->loadexecutor_->setDefaultValues(param1, param2, param3, param4); 230 return this->portIfWaitingForDefaultValues(this->parseResult_, this->parseParams_); 231 } 232 virtual XMLPortParamContainer& defaultValues(const MultiTypeMath& param1, const MultiTypeMath& param2, const MultiTypeMath& param3, const MultiTypeMath& param4, const MultiTypeMath& param5) 233 { 234 if ((!this->loadexecutor_->defaultValueSet(0)) || (!this->loadexecutor_->defaultValueSet(1)) || (!this->loadexecutor_->defaultValueSet(2)) || (!this->loadexecutor_->defaultValueSet(3)) || (!this->loadexecutor_->defaultValueSet(4))) 235 this->loadexecutor_->setDefaultValues(param1, param2, param3, param4, param5); 236 return this->portIfWaitingForDefaultValues(this->parseResult_, this->parseParams_); 237 } 238 179 239 private: 180 FunctorMember<T>* loadfunction_; 181 FunctorMember<T>* savefunction_; 240 ExecutorMember<T>* loadexecutor_; 241 ExecutorMember<T>* saveexecutor_; 242 ParseParams parseParams_; 182 243 }; 183 244 … … 189 250 { 190 251 public: 191 XMLPortObjectContainer(); 252 XMLPortObjectContainer() 253 { this->bApplyLoaderMask_ = false; } 254 virtual ~XMLPortObjectContainer() {} 192 255 193 256 inline const std::string& getName() const 194 257 { return this->sectionname_; } 195 258 196 XMLPortObjectContainer& description(const std::string description); 197 const std::string& getDescription(); 198 static bool identifierIsIncludedInLoaderMask(const Identifier* identifier); 259 virtual XMLPortObjectContainer& description(const std::string description) = 0; 260 virtual const std::string& getDescription() = 0; 261 262 bool identifierIsIncludedInLoaderMask(const Identifier* identifier); 199 263 200 264 protected: 201 std::string classname_;202 265 std::string sectionname_; 203 204 private: 205 LanguageEntryLabel description_; 206 bool bAddedDescription_; 266 bool bApplyLoaderMask_; 267 bool bLoadBefore_; 207 268 }; 208 269 … … 211 272 { 212 273 public: 213 XMLPortClassObjectContainer(const std::string classname, const std::string sectionname, void (T::*loadfunction)(O*), const O* (T::*savefunction)(unsigned int)) 214 { 215 this->classname_ = classname; 274 XMLPortClassObjectContainer(const std::string sectionname, ExecutorMember<T>* loadexecutor, ExecutorMember<T>* saveexecutor, bool bApplyLoaderMask, bool bLoadBefore) 275 { 216 276 this->sectionname_ = sectionname; 217 this->loadfunction_ = loadfunction; 218 this->savefunction_ = savefunction; 219 } 220 221 XMLPortObjectContainer& port(T* object, Element& xmlelement, bool loading) 222 { 223 if (loading) 277 this->loadexecutor_ = loadexecutor; 278 this->saveexecutor_ = saveexecutor; 279 this->bApplyLoaderMask_ = bApplyLoaderMask; 280 this->bLoadBefore_ = bLoadBefore; 281 } 282 283 XMLPortObjectContainer& port(T* object, Element& xmlelement, XMLPort::Mode mode) 284 { 285 if (mode == XMLPort::LoadObject) 224 286 { 225 287 try 226 288 { 227 Element* xmlsubelement = xmlelement.FirstChildElement(this->sectionname_, false); 289 Element* xmlsubelement; 290 if ((this->sectionname_ != "") && (this->sectionname_.size() > 0)) 291 xmlsubelement = xmlelement.FirstChildElement(this->sectionname_, false); 292 else 293 xmlsubelement = &xmlelement; 228 294 229 295 if (xmlsubelement) 230 296 { 231 for ( ticpp::Iterator<ticpp::Element> child = xmlsubelement->FirstChildElement(false); child != child.end(); child++)297 for (ticpp::Iterator<ticpp::Element> child = xmlsubelement->FirstChildElement(false); child != child.end(); child++) 232 298 { 233 299 Identifier* identifier = ID(child->Value()); … … 239 305 { 240 306 COUT(4) << object->getLoaderIndentation() << "fabricating " << child->Value() << "..." << std::endl; 307 241 308 O* newObject = (O*)identifier->fabricate(); 242 309 newObject->setLoaderIndentation(object->getLoaderIndentation() + " "); 243 310 newObject->setLevel(object->getLevel()); 244 newObject->XMLPort(*child, true); 245 COUT(4) << object->getLoaderIndentation() << "assigning " << child->Value() << " (objectname " << newObject->getName() << ") to " << this->classname_ << " (objectname " << object->getName() << ")" << std::endl; 246 (*object.*this->loadfunction_)(newObject); 247 COUT(5) << " ...fabricated " << child->Value() << " (objectname " << newObject->getName() << ")." << std::endl; 311 newObject->setNamespace(object->getNamespace()); 312 313 if (this->bLoadBefore_) 314 { 315 newObject->XMLPort(*child, XMLPort::LoadObject); 316 COUT(4) << object->getLoaderIndentation() << "assigning " << child->Value() << " (objectname " << newObject->getName() << ") to " << object->getIdentifier()->getName() << " (objectname " << object->getName() << ")" << std::endl; 317 } 318 else 319 { 320 COUT(4) << object->getLoaderIndentation() << "assigning " << child->Value() << " (object not yet loaded) to " << object->getIdentifier()->getName() << " (objectname " << object->getName() << ")" << std::endl; 321 } 322 323 COUT(5) << object->getLoaderIndentation(); 324 (*this->loadexecutor_)(object, newObject); 325 326 if (!this->bLoadBefore_) 327 newObject->XMLPort(*child, XMLPort::LoadObject); 328 329 COUT(5) << object->getLoaderIndentation() << "...fabricated " << child->Value() << " (objectname " << newObject->getName() << ")." << std::endl; 248 330 } 249 331 } … … 263 345 { 264 346 COUT(1) << std::endl; 265 COUT(1) << "An error occurred in XMLPort.h while loading a '" << Class(O)->getName() << "' in '" << this->sectionname_ << "' of '" << this->classname_<< "' (objectname: " << object->getName() << ") in " << object->getLevelfile() << ":" << std::endl;347 COUT(1) << "An error occurred in XMLPort.h while loading a '" << Class(O)->getName() << "' in '" << this->sectionname_ << "' of '" << object->getIdentifier()->getName() << "' (objectname: " << object->getName() << ") in " << object->getLevelfile() << ":" << std::endl; 266 348 COUT(1) << ex.what() << std::endl; 267 349 } … … 274 356 } 275 357 358 virtual XMLPortObjectContainer& description(const std::string description) 359 { this->loadexecutor_->setDescription(description); return (*this); } 360 virtual const std::string& getDescription() 361 { return this->loadexecutor_->getDescription(); } 362 276 363 private: 277 void (T::*loadfunction_)(O*);278 const O* (T::*savefunction_)(unsigned int);364 ExecutorMember<T>* loadexecutor_; 365 ExecutorMember<T>* saveexecutor_; 279 366 }; 280 367 }
Note: See TracChangeset
for help on using the changeset viewer.