Changeset 7401 for code/trunk/src/libraries
- Timestamp:
- Sep 11, 2010, 12:34:00 AM (14 years ago)
- Location:
- code/trunk
- Files:
-
- 144 edited
Legend:
- Unmodified
- Added
- Removed
-
code/trunk
- Property svn:mergeinfo changed
/code/branches/doc (added) merged: 7290-7292,7296-7300,7302-7304,7306-7312,7315-7318,7323,7325,7327,7331-7332,7334-7335,7345-7347,7352-7353,7356-7357,7361,7363-7367,7371-7375,7388
- Property svn:mergeinfo changed
-
code/trunk/src/libraries/CMakeLists.txt
r5929 r7401 18 18 # 19 19 20 INCLUDE_DIRECTORIES( 21 ${CMAKE_SOURCE_DIR}/src/external 22 ${CMAKE_CURRENT_SOURCE_DIR} 23 ) 20 INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}) 24 21 25 22 ################ Sub Directories ################ -
code/trunk/src/libraries/core/BaseObject.cc
r7284 r7401 116 116 @brief XML loading and saving. 117 117 @param xmlelement The XML-element 118 @param loading Loading (true) or saving (false)118 @param mode The mode defines the operation that is being executed: loading or saving the object (from or to XML respectively) 119 119 */ 120 120 void BaseObject::XMLPort(Element& xmlelement, XMLPort::Mode mode) … … 141 141 @brief Defines the possible event states of this object and parses eventsources from an XML file. 142 142 @param xmlelement The XML-element 143 @param loading Loading (true) or saving (false)143 @param mode The mode defines the operation that is being executed: loading or saving the object (from or to XML respectively) 144 144 */ 145 145 void BaseObject::XMLEventPort(Element& xmlelement, XMLPort::Mode mode) -
code/trunk/src/libraries/core/BaseObject.h
r7284 r7401 28 28 29 29 /** 30 @defgroup BaseObject BaseObject 31 @ingroup Core 32 */ 33 34 /** 30 35 @file 31 @brief Definition of the BaseObject class. 36 @ingroup BaseObject 37 @brief Declaration of BaseObject, the base class of all objects in Orxonox. 32 38 33 39 The BaseObject is the parent of all classes representing an instance in the game. … … 53 59 class Level; 54 60 55 // !The BaseObject is the parent of all classes representing an instance in the game.61 /// The BaseObject is the parent of all classes representing an instance in the game. 56 62 class _CoreExport BaseObject : virtual public OrxonoxClass 57 63 { -
code/trunk/src/libraries/core/ClassFactory.h
r5929 r7401 29 29 /** 30 30 @file 31 @ingroup Object Factory 31 32 @brief Definition and implementation of the ClassFactory class 32 33 33 The ClassFactory is able to create new objects of a specific class .34 The ClassFactory is able to create new objects of a specific class which creates objects. 34 35 */ 35 36 … … 49 50 // ### Factory ### 50 51 // ########################### 51 // !Base-class of ClassFactory.52 /// Base-class of ClassFactory. 52 53 class _CoreExport Factory 53 54 { … … 60 61 // ### ClassFactory ### 61 62 // ############################### 62 // !The ClassFactory is able to create new objects of a specific class.63 /// The ClassFactory is able to create new objects of a specific class. 63 64 template <class T> 64 65 class ClassFactory : public Factory -
code/trunk/src/libraries/core/ClassTreeMask.cc
r7268 r7401 29 29 /** 30 30 @file 31 @brief Implementation of the ClassTreeMask, ClassTreeMaskNode and ClassTreeMaskIterator classes.31 @brief Implementation of the ClassTreeMask, ClassTreeMaskNode, and ClassTreeMaskIterator classes. 32 32 */ 33 33 … … 93 93 /** 94 94 @brief Adds a new subnode to the list of subnodes. 95 @param subnode The new subnode96 95 */ 97 96 void ClassTreeMaskNode::addSubnode(ClassTreeMaskNode* subnode) … … 178 177 /** 179 178 @brief Returns a pointer to the ClassTreeMaskNode whereon the iterator points. 180 @return The pointer to the node181 179 */ 182 180 ClassTreeMaskNode* ClassTreeMaskIterator::operator*() const … … 187 185 /** 188 186 @brief Returns a pointer to the ClassTreeMaskNode whereon the iterator points. 189 @return The pointer to the node190 187 */ 191 188 ClassTreeMaskNode* ClassTreeMaskIterator::operator->() const … … 196 193 /** 197 194 @brief Returns true if the stack is empty, meaning we've reached the end of the tree. 198 @return True if we've reached the end of the tree199 195 */ 200 196 ClassTreeMaskIterator::operator bool() const … … 205 201 /** 206 202 @brief Compares the current node with the given one and returns true if they match. 207 @param compare The node to compare with208 @return The result of the comparison (true if they match)209 203 */ 210 204 bool ClassTreeMaskIterator::operator==(ClassTreeMaskNode* compare) const … … 218 212 /** 219 213 @brief Compares the current node with the given one and returns true if they don't match. 220 @param compare The node to compare with221 @return The result of the comparison (true if they don't match)222 214 */ 223 215 bool ClassTreeMaskIterator::operator!=(ClassTreeMaskNode* compare) const … … 242 234 243 235 /** 244 @brief Copyconstructor: Adds the root-node of the tree with the first rule ("include everything") and adds all rules from the other mask. 245 @param other The other mask 236 @brief Copy-constructor: Adds the root-node of the tree with the first rule ("include everything") and adds all rules from the other mask. 246 237 */ 247 238 ClassTreeMask::ClassTreeMask(const ClassTreeMask& other) -
code/trunk/src/libraries/core/ClassTreeMask.h
r7268 r7401 29 29 /** 30 30 @file 31 @brief Definition of the ClassTreeMask, ClassTreeMaskNode and ClassTreeMaskIterator classes. 32 33 ClassTreeMask is a class to define a mask of the class-tree beginning with BaseObject. 31 @ingroup Class 32 @brief Declaration of the ClassTreeMask, ClassTreeMaskNode, and ClassTreeMaskIterator classes. 33 34 ClassTreeMask is a class to define a mask of the class-tree beginning with orxonox::BaseObject. 34 35 You can include or exclude classes by calling the corresponding functions with the 35 Identifier of the class. 36 orxonox::Identifier of the class. This mask can then be used to filter out objects that 37 are instances of classes which aren't included in the tree, for example when Loading a 38 level file or if a Trigger should be triggered by only a few classes. 39 40 See the description of orxonox::ClassTreeMask for a short example. 36 41 37 42 You can work with a ClassTreeMask in the sense of the set-theory, meaning that you can create 38 43 unions, intersections, complements and differences by using overloaded operators. 39 44 40 45 @par Tree structure 41 46 42 47 The ClassTreeMask is internally represented by a tree. The nodes in the tree are … … 45 50 nodes changing the mask. By adding new rules, the tree gets reordered dynamically. 46 51 47 Adding a new rule overwrites all rules assigned to inherited classes. Use overwrite = false52 Adding a new rule overwrites all rules assigned to inherited classes. Use <tt>overwrite = false</tt> 48 53 if you don't like this feature. Useless rules that don't change the information of the mask 49 aren't saved in the internal tree. Use clean = false if you wan't to save them. 50 51 With overwrite = false and clean = false it doesn't matter in which way you create the mask. 52 You can manually drop useless rules from the tree by calling clean(). 53 54 55 56 Because of the complicated shape of the internal tree, there is an iterator to iterate 57 through all ClassTreeMaskNodes of a mask. It starts with the BaseObject and moves on to 58 the first subclass until it reaches a leaf of the tree. Then the iterator moves one step 59 back and iterates to the second subclass. If there are no more subclasses, it steps another 60 step back, and so on. 61 62 Example: A and B are children of BaseObject, A1 and A2 are children of A, B1 and B2 are children of B. 63 The ClassTreeMaskIterator would move trough the tree in the following order: 64 BaseObject, A, A1, A2, B, B1, B2. 65 66 Note that the iterator doesn't move trough the whole class-tree, but only through the 67 internal tree of the mask, containing the minimal needed set of nodes to describe the mask. 54 aren't saved in the internal tree. Use <tt>clean = false</tt> if you still want to save them. 55 56 With <tt>overwrite = false</tt> and <tt>clean = false</tt> it doesn't matter in which order 57 you create the mask. You can manually drop useless rules from the tree by calling 58 @ref orxonox::ClassTreeMask::clean() "clean()". 59 60 @par Objects 61 62 To iterate through all objects of the classes that were included by a ClassTreeMask, 63 use orxonox::ClassTreeMaskObjectIterator. The description of this class also contains 64 a short example of how to use it. 68 65 */ 69 66 … … 83 80 // ### ClassTreeMaskNode ### 84 81 // ################################### 85 //! The ClassTreeMaskNode is a node in the internal tree of the ClassTreeMask, containing the rules of the mask.86 82 /** 83 @brief The ClassTreeMaskNode is a node in the internal tree of the ClassTreeMask, containing the rules of the mask. 84 87 85 The ClassTreeMaskNode is used to store the rule (included or excluded) for a given 88 86 class (described by the corresponding Identifier). The nodes are used in the internal … … 105 103 void addSubnode(ClassTreeMaskNode* subnode); 106 104 107 / ** @brief Tells if the rule is "included" or not. @return The rule: true = included, false = excluded */105 /// Tells if the rule is "included" or not. 108 106 inline bool isIncluded() const { return this->bIncluded_; } 109 / ** @brief Tells if the rule is "excluded" or not. @return The inverted rule: true = excluded, false = included */107 /// Tells if the rule is "excluded" or not. 110 108 inline bool isExcluded() const { return (!this->bIncluded_); } 111 109 112 / ** @brief Returns the Identifier of the class the rule refers to. @return The Identifier representing the class */110 /// Returns the Identifier of the class the rule refers to. 113 111 inline const Identifier* getClass() const { return this->subclass_; } 114 112 115 / ** @brief Returns true if the Node has some subnodes. */113 /// Returns true if the node has some subnodes. 116 114 inline bool hasSubnodes() const { return !this->subnodes_.empty(); } 117 115 … … 119 117 void deleteAllSubnodes(); 120 118 121 const Identifier* subclass_; // !< The Identifier of the subclass the rule refers to122 bool bIncluded_; // !< The rule: included or excluded123 std::list<ClassTreeMaskNode*> subnodes_; // !< A list containing all subnodes in the tree119 const Identifier* subclass_; ///< The Identifier of the subclass the rule refers to 120 bool bIncluded_; ///< The rule: included or excluded 121 std::list<ClassTreeMaskNode*> subnodes_; ///< A list containing all subnodes of this node 124 122 }; 125 123 … … 128 126 // ### ClassTreeMaskIterator ### 129 127 // ################################### 130 //! The ClassTreeMaskIterator moves through all ClassTreeMaskNodes of the internal tree of a ClassTreeMask, containing the rules.131 128 /** 129 @brief The ClassTreeMaskIterator moves through all ClassTreeMaskNodes of the internal tree of a ClassTreeMask which contains the rules. 130 132 131 Because of the complicated shape of the internal rule-tree of ClassTreeMask, an 133 132 iterator is used to move through all nodes of the tree. It starts with the BaseObject … … 135 134 iterator moves one step back and iterates to the second subclass. If there are no more 136 135 subclasses, it steps another step back, and so on. 136 137 Example: A and B are children of BaseObject, A1 and A2 are children of A, B1 and B2 are children of B. 138 The ClassTreeMaskIterator would move trough the tree in the following order: 139 BaseObject, A, A1, A2, B, B1, B2. 140 141 Note that the iterator doesn't move trough the whole class-tree, but only through the 142 internal tree of the mask, containing the minimal needed set of nodes to describe the mask. 137 143 */ 138 144 class _CoreExport ClassTreeMaskIterator … … 150 156 151 157 private: 152 std::stack<std::pair<std::list<ClassTreeMaskNode*>::iterator, std::list<ClassTreeMaskNode*>::iterator> > nodes_; // !< A stack to store list-iterators153 std::list<ClassTreeMaskNode*> rootlist_; // !< A list for internal use (it only stores the root-node)158 std::stack<std::pair<std::list<ClassTreeMaskNode*>::iterator, std::list<ClassTreeMaskNode*>::iterator> > nodes_; ///< A stack to store list-iterators 159 std::list<ClassTreeMaskNode*> rootlist_; ///< A list for internal use (it only stores the root-node) 154 160 }; 155 161 … … 158 164 // ### ClassTreeMask ### 159 165 // ################################### 160 //! The ClassTreeMask is a set of rules, containing the information for each class whether it's included or not.161 166 /** 167 @brief The ClassTreeMask is a set of rules, containing the information for each class whether it's included or not. 168 162 169 With a ClassTreeMask, you can include or exclude subtrees of the class-tree, starting 163 170 with a given subclass, described by the corresponding Identifier. To minimize the size 164 171 of the mask, the mask saves only relevant rules. But you can manually add rules that 165 don't change the information of the mask by using clean = false. If you want to drop172 don't change the information of the mask by using <tt>clean = false</tt>. If you want to drop 166 173 useless rules, call the clean() function. 174 175 Example: 176 @code 177 ClassTreeMask mymask; 178 mymask.exclude(Class(A)); 179 mymask.exclude(Class(B)); 180 mymask.include(Class(ChildOfA)); 181 @endcode 182 183 In this example, the classes A and B are excluded from the mask, but one of the child 184 classes of A is included again. 167 185 */ 168 186 class _CoreExport ClassTreeMask … … 189 207 bool isExcluded(const Identifier* subclass) const; 190 208 191 / ** @brief Begin of the ClassTreeMaskObjectIterator. */209 /// Begin of the ClassTreeMaskObjectIterator. 192 210 inline const ClassTreeMask& begin() const { return (*this); } 193 / ** @brief End of the ClassTreeMaskObjectIterator. */211 /// End of the ClassTreeMaskObjectIterator. 194 212 inline BaseObject* end() const { return 0; } 195 213 … … 228 246 bool nodeExists(const Identifier* subclass); 229 247 230 ClassTreeMaskNode* root_; // !< The root-node of the internal rule-tree, usually BaseObject248 ClassTreeMaskNode* root_; ///< The root-node of the internal rule-tree, usually BaseObject 231 249 }; 232 250 … … 235 253 // ### ClassTreeMaskObjectIterator ### 236 254 // ################################### 237 //! The ClassTreeMaskObjectIterator iterates through all objects of all classes, included by a ClassTreeMask.238 255 /** 239 The ClassTreeMaskObjectIterator iterates through all objects of all classes, 240 included by a ClassTreeMask. This is done the following way: 241 256 @brief The ClassTreeMaskObjectIterator iterates through all objects of the classes that were included by a ClassTreeMask. 257 258 This is done the following way: 259 @code 242 260 ClassTreeMask mask; 243 261 for (ClassTreeMaskObjectIterator it = mask.begin(); it != mask.end(); ++it) 244 262 it->doSomething(); 245 246 Note: The ClassTreeMaskObjectIterator handles all objects as BaseObjects. If 263 @endcode 264 265 @note The ClassTreeMaskObjectIterator handles all objects as BaseObjects. If 247 266 you want to use another class, you should use a dynamic_cast. 248 267 249 Performance of ClassTreeMaskObjectIterator is good as long as you don't exclude268 The performance of ClassTreeMaskObjectIterator is good as long as you don't exclude 250 269 subclasses of included classes. Of course you can still exlucde subclasses, but 251 270 if this is done more often, we need a new implementation using a second ObjectList … … 255 274 { 256 275 public: 257 / ** @brief Defaultconstructor: Does nothing. */276 /// Default-constructor: Does nothing. 258 277 inline ClassTreeMaskObjectIterator() {} 259 / ** @brief Constructor: Initializes the iterator from a given ClassTreeMask. @param mask The mask */278 /// Copy-Constructor: Initializes the iterator from another ClassTreeMask. 260 279 inline ClassTreeMaskObjectIterator(const ClassTreeMask& mask) { (*this) = mask; } 261 280 … … 264 283 const ClassTreeMaskObjectIterator& operator++(); 265 284 266 / ** @brief Returns true if the ClassTreeMaskObjectIterator points at the given object. @param pointer The pointer of the object */285 /// Returns true if the ClassTreeMaskObjectIterator points at the given object. 267 286 inline bool operator==(BaseObject* pointer) const { return (this->objectIterator_ && (*this->objectIterator_) == pointer) || (!this->objectIterator_ && pointer == 0); } 268 / ** @brief Returns true if the ClassTreeMaskObjectIterator doesn't point at the given object. @param pointer The pointer of the object */287 /// Returns true if the ClassTreeMaskObjectIterator doesn't point at the given object. 269 288 inline bool operator!=(BaseObject* pointer) const { return (this->objectIterator_ && (*this->objectIterator_) != pointer) || (!this->objectIterator_ && pointer != 0); } 270 / ** @brief Returns true if the ClassTreeMaskObjectIterator hasn't already reached the end. */289 /// Returns true if the ClassTreeMaskObjectIterator hasn't already reached the end. 271 290 inline operator bool() const { return (this->objectIterator_); } 272 / ** @brief Returns the object the ClassTreeMaskObjectIterator currently points at. */291 /// Returns the object the ClassTreeMaskObjectIterator currently points at. 273 292 inline BaseObject* operator*() const { return (*this->objectIterator_); } 274 / ** @brief Returns the object the ClassTreeMaskObjectIterator currently points at. */293 /// Returns the object the ClassTreeMaskObjectIterator currently points at. 275 294 inline BaseObject* operator->() const { return (*this->objectIterator_); } 276 295 … … 278 297 void create(ClassTreeMaskNode* node); 279 298 280 std::list<std::pair<const Identifier*, bool> > subclasses_; // !< A list of all Identifiers through which objects the iterator should iterate281 std::list<std::pair<const Identifier*, bool> >::iterator subclassIterator_; // !< The current class of the iterator282 Iterator<BaseObject> objectIterator_; // !< The current object of the iterator299 std::list<std::pair<const Identifier*, bool> > subclasses_; ///< A list of all Identifiers through which objects the iterator should iterate 300 std::list<std::pair<const Identifier*, bool> >::iterator subclassIterator_; ///< The current class of the iterator 301 Iterator<BaseObject> objectIterator_; ///< The current object of the iterator 283 302 }; 284 303 } -
code/trunk/src/libraries/core/CommandLineParser.cc
r7284 r7401 126 126 @param arguments 127 127 Vector of space separated strings. 128 @param bParsingFile 129 Parsing a file or the command line itself 128 130 */ 129 131 void CommandLineParser::_parse(const std::vector<std::string>& arguments, bool bParsingFile) … … 244 246 @param value 245 247 String containing the value 248 @param bParsingFile 249 Parsing a file or the command line itself 246 250 */ 247 251 void CommandLineParser::checkFullArgument(const std::string& name, const std::string& value, bool bParsingFile) … … 258 262 Parses an argument based on its shortcut. 259 263 @param shortcut 260 Sho tcut to the argument264 Shortcut to the argument 261 265 @param value 262 266 String containing the value 267 @param bParsingFile 268 Parsing a file or the command line itself 263 269 */ 264 270 void CommandLineParser::checkShortcut(const std::string& shortcut, const std::string& value, bool bParsingFile) … … 308 314 } 309 315 316 void CommandLineParser::generateDoc(std::ofstream& file) 317 { 318 file << "/** @page cmdargspage Command Line Arguments Reference" << endl; 319 file << " @verbatim"; /*no endl*/ 320 file << getUsageInformation(); /*no endl*/ 321 file << " @endverbatim" << endl; 322 file << "*/" << endl; 323 } 324 310 325 /** 311 326 @brief … … 313 328 The method throws an exception if 'name' was not found or the value could not be converted. 314 329 @note 315 You sho ld of course not call this method before the command line has been parsed.330 You should of course not call this method before the command line has been parsed. 316 331 */ 317 332 const CommandLineArgument* CommandLineParser::getArgument(const std::string& name) -
code/trunk/src/libraries/core/CommandLineParser.h
r7284 r7401 27 27 */ 28 28 29 /** 30 @defgroup CmdArgs Commandline arguments 31 @ingroup Config 32 @brief For a reference of all commandline arguments see @ref cmdargspage 33 */ 34 35 /** 36 @file 37 @ingroup Config CmdArgs 38 @brief Declaration of CommandLineParser and CommandLineArgument, definition of the SetCommandLineArgument() macros. 39 */ 40 29 41 #ifndef _CommandLine_H__ 30 42 #define _CommandLine_H__ … … 32 44 #include "CorePrereqs.h" 33 45 46 #include <fstream> 34 47 #include <map> 35 48 #include "util/OrxAssert.h" … … 165 178 static void destroyAllArguments(); 166 179 180 static void generateDoc(std::ofstream& file); 181 167 182 private: 168 183 //! Constructor initialises bFirstTimeParse_ with true. … … 207 222 @param defaultValue 208 223 Default value that is used when argument was not given. 224 @param bCommandLineOnly 225 Parsing a file or the command line itself 209 226 */ 210 227 template <class T> -
code/trunk/src/libraries/core/ConfigFileManager.cc
r7284 r7401 27 27 */ 28 28 29 /** 30 @file 31 @brief Implementation of ConfigFileManager and its helper classes. 32 */ 33 29 34 #include "ConfigFileManager.h" 30 35 … … 43 48 // ConfigFileEntryValue // 44 49 ////////////////////////// 45 50 /** 51 @brief Updates the string that will be stored in the file after one of it's components (name, value, comment) has changed. 52 */ 46 53 void ConfigFileEntryValue::update() 47 54 { … … 63 70 // ConfigFileEntryVectorValue // 64 71 //////////////////////////////// 72 /** 73 @brief Updates the string that will be stored in the file after one of it's components (name, value, index, comment) has changed. 74 */ 65 75 void ConfigFileEntryVectorValue::update() 66 76 { … … 73 83 // ConfigFileSection // 74 84 /////////////////////// 85 /** 86 @brief Destructor: Deletes all entries. 87 */ 75 88 ConfigFileSection::~ConfigFileSection() 76 89 { … … 79 92 } 80 93 94 /** 95 @brief Deletes all elements of a config vector if their index is greater or equal to @a startindex. 96 97 @param name The name of the vector 98 @param startindex The index of the first element that will be deleted 99 */ 81 100 void ConfigFileSection::deleteVectorEntries(const std::string& name, unsigned int startindex) 82 101 { … … 95 114 } 96 115 116 /** 117 @brief Returns the size of a config vector. 118 @param name The name of the vector 119 */ 97 120 unsigned int ConfigFileSection::getVectorSize(const std::string& name) const 98 121 { … … 108 131 } 109 132 133 /** 134 @brief Returns the title and comment of the section as it will be stored in the file. 135 */ 110 136 std::string ConfigFileSection::getFileEntry() const 111 137 { … … 116 142 } 117 143 144 /** 145 @brief Returns the entry with given name (or NULL if it doesn't exist). 146 147 @param name The name of the entry 148 */ 118 149 ConfigFileEntry* ConfigFileSection::getEntry(const std::string& name) const 119 150 { … … 126 157 } 127 158 159 /** 160 @brief Returns the entry of a vector element with given name and index (or NULL if it doesn't exist). 161 162 @param name The name of the vector 163 @param index The index of the element in the vector 164 */ 128 165 ConfigFileEntry* ConfigFileSection::getEntry(const std::string& name, unsigned int index) const 129 166 { … … 136 173 } 137 174 175 /** 176 @brief Returns the iterator to the entry with given name. If the entry doesn't exist, it is created using the fallback value. 177 178 @param name The name of the entry 179 @param fallback The value that will be used if the entry doesn't exist 180 @param bString If true, the value is treated as string which means some special treatment of special characters. 181 */ 138 182 std::list<ConfigFileEntry*>::iterator ConfigFileSection::getOrCreateEntryIterator(const std::string& name, const std::string& fallback, bool bString) 139 183 { … … 152 196 } 153 197 198 /** 199 @brief Returns the iterator to the entry of a vector element with given name and index. If the entry doesn't exist, it is created using the fallback value. 200 201 @param name The name of the vector 202 @param index The index of the element in the vector 203 @param fallback The value that will be used if the entry doesn't exist 204 @param bString If true, the value is treated as string which means some special treatment of special characters. 205 */ 154 206 std::list<ConfigFileEntry*>::iterator ConfigFileSection::getOrCreateEntryIterator(const std::string& name, unsigned int index, const std::string& fallback, bool bString) 155 207 { … … 178 230 const char* ConfigFile::DEFAULT_CONFIG_FOLDER = "defaultConfig"; 179 231 232 /** 233 @brief Constructor: Initializes the config file. 234 @param filename The file-name of this config file 235 @param bCopyFallbackFile If true, the default config file is copied into the config-directory before loading the file 236 */ 180 237 ConfigFile::ConfigFile(const std::string& filename, bool bCopyFallbackFile) 181 238 : filename_(filename) … … 185 242 } 186 243 244 /** 245 @brief Destructor: Deletes all sections and entries. 246 */ 187 247 ConfigFile::~ConfigFile() 188 248 { … … 190 250 } 191 251 252 /** 253 @brief Loads the config file from the hard-disk and reads the sections and their values. 254 */ 192 255 void ConfigFile::load() 193 256 { … … 318 381 } 319 382 383 /** 384 @brief Writes the sections and values to the hard-disk. 385 */ 320 386 void ConfigFile::save() const 321 387 { … … 323 389 } 324 390 391 /** 392 @brief Writes the sections and values to a given file on the hard-disk. 393 */ 325 394 void ConfigFile::saveAs(const std::string& filename) const 326 395 { … … 354 423 } 355 424 425 /** 426 @brief Deletes all sections (which again delete all their values) and clears the list of sections. 427 */ 356 428 void ConfigFile::clear() 357 429 { … … 361 433 } 362 434 363 const std::string& ConfigFile::getOrCreateValue(const std::string& section, const std::string& name, const std::string& fallback, bool bString) 364 { 365 const std::string& output = this->getOrCreateSection(section)->getOrCreateValue(name, fallback, bString); 366 this->saveIfUpdated(); 367 return output; 368 } 369 370 const std::string& ConfigFile::getOrCreateValue(const std::string& section, const std::string& name, unsigned int index, const std::string& fallback, bool bString) 371 { 372 const std::string& output = this->getOrCreateSection(section)->getOrCreateValue(name, index, fallback, bString); 373 this->saveIfUpdated(); 374 return output; 375 } 376 435 /** 436 @brief Deletes all elements of a config vector if their index is greater or equal to @a startindex. 437 438 @param section The name of the section 439 @param name The name of the vector 440 @param startindex The index of the first element that will be deleted 441 */ 377 442 void ConfigFile::deleteVectorEntries(const std::string& section, const std::string& name, unsigned int startindex) 378 443 { … … 384 449 } 385 450 451 /** 452 @brief Returns a pointer to the section with given name (or NULL if the section doesn't exist). 453 */ 386 454 ConfigFileSection* ConfigFile::getSection(const std::string& section) const 387 455 { … … 392 460 } 393 461 462 /** 463 @brief Returns a pointer to the section with given name. If it doesn't exist, the section is created. 464 */ 394 465 ConfigFileSection* ConfigFile::getOrCreateSection(const std::string& section) 395 466 { … … 403 474 } 404 475 476 /** 477 @brief Saves the config file if it was updated (or if any of its sections were updated). 478 */ 405 479 void ConfigFile::saveIfUpdated() 406 480 { … … 442 516 SettingsConfigFile* SettingsConfigFile::singletonPtr_s = 0; 443 517 518 /** 519 @brief Constructor: Activates the console commands. 520 */ 444 521 SettingsConfigFile::SettingsConfigFile(const std::string& filename) 445 522 : ConfigFile(filename) … … 452 529 } 453 530 531 /** 532 @brief Destructor: Deactivates the console commands. 533 */ 454 534 SettingsConfigFile::~SettingsConfigFile() 455 535 { … … 461 541 } 462 542 543 /** 544 @brief Loads the config file and updates the @ref ConfigValueContainer "config value containers". 545 */ 463 546 void SettingsConfigFile::load() 464 547 { … … 467 550 } 468 551 552 /** 553 @brief Changes the file-name. 554 */ 469 555 void SettingsConfigFile::setFilename(const std::string& filename) 470 556 { … … 472 558 } 473 559 560 /** 561 @brief Registers a new @ref ConfigValueContainer "config value container". 562 */ 474 563 void SettingsConfigFile::addConfigValueContainer(ConfigValueContainer* container) 475 564 { … … 481 570 } 482 571 572 /** 573 @brief Unregisters a @ref ConfigValueContainer "config value container". 574 */ 483 575 void SettingsConfigFile::removeConfigValueContainer(ConfigValueContainer* container) 484 576 { … … 500 592 } 501 593 594 /** 595 @brief Updates all @ref ConfigValueContainer "config value containers". 596 */ 502 597 void SettingsConfigFile::updateConfigValues() 503 598 { 599 // todo: can this be done more efficiently? looks like some identifiers will be updated multiple times. 600 504 601 for (ContainerMap::const_iterator it = this->containers_.begin(); it != this->containers_.end(); ++it) 505 602 { … … 509 606 } 510 607 608 /** 609 @brief Removes entries and sections from the file that don't exist anymore (i.e. if there's no corresponding @ref ConfigValueContainer "config value container"). 610 @param bCleanComments If true, comments are also removed from the file 611 */ 511 612 void SettingsConfigFile::clean(bool bCleanComments) 512 613 { … … 558 659 } 559 660 661 /** 662 @brief Console-command: Changes the value of an entry and stores it the file. 663 664 @param section The section of the config value 665 @param entry The name of the config value 666 @param value The new value 667 */ 560 668 void SettingsConfigFile::config(const std::string& section, const std::string& entry, const std::string& value) 561 669 { … … 564 672 } 565 673 674 /** 675 @brief Console-command: Changes the value of an entry, but doesn't store it in the file (it's only a temporary change). 676 677 @param section The section of the config value 678 @param entry The name of the config value 679 @param value The new value 680 */ 566 681 void SettingsConfigFile::tconfig(const std::string& section, const std::string& entry, const std::string& value) 567 682 { … … 570 685 } 571 686 687 /** 688 @brief Changes the value of an entry, depending on @a function, either by using "set" or "tset" 689 690 @param section The section of the config value 691 @param entry The name of the config value 692 @param value The new value 693 @param function The function ("set" or "tset") that will be used to change the value. 694 */ 572 695 bool SettingsConfigFile::configImpl(const std::string& section, const std::string& entry, const std::string& value, bool (ConfigValueContainer::*function)(const MultiType&)) 573 696 { … … 586 709 } 587 710 711 /** 712 @brief Console-command: Returns the value of a given entry. 713 714 @param section The section of the config value 715 @param entry The name of the config value 716 */ 588 717 std::string SettingsConfigFile::getConfig(const std::string& section, const std::string& entry) 589 718 { … … 611 740 ConfigFileManager* ConfigFileManager::singletonPtr_s = 0; 612 741 742 /// Constructor: Initializes the array of config files with NULL. 613 743 ConfigFileManager::ConfigFileManager() 614 744 { … … 616 746 } 617 747 748 /// Destructor: Deletes the config files. 618 749 ConfigFileManager::~ConfigFileManager() 619 750 { … … 623 754 } 624 755 756 /// Defines the file-name for the config file of a given type (settings, calibration, etc.). 625 757 void ConfigFileManager::setFilename(ConfigFileType::Value type, const std::string& filename) 626 758 { -
code/trunk/src/libraries/core/ConfigFileManager.h
r7284 r7401 27 27 */ 28 28 29 /** 30 @file 31 @ingroup Config ConfigFile 32 @brief Declaration of ConfigFileManager and its helper classes, used to load and save config files. 33 */ 34 29 35 #ifndef _ConfigFileManager_H__ 30 36 #define _ConfigFileManager_H__ … … 46 52 // ConfigFileEntry // 47 53 ///////////////////// 54 /** 55 @brief This class represents an entry in the config file. 56 57 This class is pure virtual. Use one of the derived classes to define the type of the entry. 58 */ 48 59 class _CoreExport ConfigFileEntry 49 60 { 50 61 public: 62 /// Destructor 51 63 virtual ~ConfigFileEntry() {}; 64 65 /// Changes the value of the entry. 52 66 virtual void setValue(const std::string& value) = 0; 67 /// Returns the value of the entry. 53 68 virtual const std::string& getValue() const = 0; 69 70 /// Returns the name of the entry 54 71 virtual const std::string& getName() const = 0; 72 73 /// Changes the comment of the entry (will be placed after the value) 55 74 virtual void setComment(const std::string& comment) = 0; 75 76 /// Returns the index of the entry in a vector (used only if it is a vector) 56 77 virtual unsigned int getIndex() const { return 0; } 78 79 /// Defines if this entry is treated as string which means some special treatment of special characters. 57 80 virtual void setString(bool bString) = 0; 81 82 /// Returns the line as it will be stored in the config file. 58 83 virtual const std::string& getFileEntry() const = 0; 59 84 }; … … 63 88 // ConfigFileEntryValue // 64 89 ////////////////////////// 90 /** 91 @brief This class represents a normal value in the config file. 92 */ 65 93 class _CoreExport ConfigFileEntryValue : public ConfigFileEntry 66 94 { 67 95 public: 96 /** 97 @brief Constructor: Initializes the entry. 98 99 @param name The name of the entry 100 @param value The value of the entry 101 @param bString If true, the value is treated as string which means some special treatment of special characters. 102 @param additionalComment An optional comment that will be placed behind the value in the config file 103 */ 68 104 inline ConfigFileEntryValue(const std::string& name, const std::string& value = "", bool bString = false, const std::string& additionalComment = "") 69 105 : name_(name) … … 73 109 { this->update(); } 74 110 111 /// Destructor 75 112 inline virtual ~ConfigFileEntryValue() {} 76 113 … … 92 129 { return this->fileEntry_; } 93 130 131 /// Returns the "key" of the value (in this case it's just the name of the entry, but for vectors it's different) 94 132 inline virtual const std::string& getKeyString() const 95 133 { return this->name_; } … … 98 136 virtual void update(); 99 137 100 const std::string name_; 101 std::string value_; 102 std::string additionalComment_; 103 std::string fileEntry_; 104 bool bString_; 138 const std::string name_; ///< The name of the value 139 std::string value_; ///< The value 140 std::string additionalComment_; ///< The additional comment 141 std::string fileEntry_; ///< The string as it will be stored in the config file 142 bool bString_; ///< If true, the value is treated as string which means some special treatment of special characters. 105 143 }; 106 144 … … 109 147 // ConfigFileEntryVectorValue // 110 148 //////////////////////////////// 149 /** 150 @brief Subclass of ConfigFileEntryValue, represents an element of a vector. 151 */ 111 152 class _CoreExport ConfigFileEntryVectorValue : public ConfigFileEntryValue 112 153 { 113 154 public: 155 /** 156 @brief Constructor: Initializes the entry. 157 158 @param name The name of the vector 159 @param index The index of the element in the vector 160 @param value The value of the element 161 @param bString If true, the value is treated as string which means some special treatment of special characters. 162 @param additionalComment An optional comment that will be placed behind the value in the config file 163 */ 114 164 inline ConfigFileEntryVectorValue(const std::string& name, unsigned int index, const std::string& value = "", bool bString = false, const std::string& additionalComment = "") 115 165 : ConfigFileEntryValue(name, value, bString, additionalComment) … … 117 167 { this->update(); /*No virtual calls in base class ctor*/ } 118 168 169 /// Destructor 119 170 inline ~ConfigFileEntryVectorValue() {} 120 171 … … 122 173 { return this->index_; } 123 174 175 /// Returns the "key" of the value (the name of the vector plus the index of the element) 124 176 inline const std::string& getKeyString() const 125 177 { return this->keyString_; } … … 128 180 void update(); 129 181 130 unsigned int index_; 131 std::string keyString_; 182 unsigned int index_; ///< The index of the element in the vector 183 std::string keyString_; ///< The full name of the entry (the name of the vector plus the index of the element) 132 184 }; 133 185 … … 136 188 // ConfigFileEntryComment // 137 189 //////////////////////////// 190 /** 191 @brief This class represents a line in the config file which contains only a comment. 192 */ 138 193 class _CoreExport ConfigFileEntryComment : public ConfigFileEntry 139 194 { 140 195 public: 196 /// Constructor: Initializes the object. 141 197 inline ConfigFileEntryComment(const std::string& comment) : comment_(comment) {} 198 199 /// Destructor 142 200 inline virtual ~ConfigFileEntryComment() {} 143 201 … … 159 217 { return this->comment_; } 160 218 161 inline virtual const std::string& getKeyString() const162 { return BLANKSTRING; }163 164 219 private: 165 std::string comment_; 220 std::string comment_; ///< The comment 166 221 }; 167 222 … … 170 225 // ConfigFileSection // 171 226 /////////////////////// 227 /** 228 @brief Represents a section in a config file. 229 230 A section has a name and a list of config values. 231 */ 172 232 class _CoreExport ConfigFileSection 173 233 { … … 176 236 177 237 public: 238 /** 239 @brief Constructor: Initializes the section. 240 241 @param name The name of the section 242 @param additionalComment An additional comment placed after the title of the section in the config file 243 */ 178 244 inline ConfigFileSection(const std::string& name, const std::string& additionalComment = "") 179 245 : name_(name) … … 183 249 ~ConfigFileSection(); 184 250 251 /// Returns the name of the section. 185 252 inline const std::string& getName() const 186 253 { return this->name_; } 187 254 255 /// Changes the comment which is placed after the title of the section in the config file. 188 256 inline void setComment(const std::string& comment) 189 257 { this->additionalComment_ = comment; } 190 258 259 /** 260 @brief Stores a value in the section. If the entry doesn't exist, it's created. 261 262 @param name The name of the entry 263 @param value The new value 264 @param bString If true, the value is treated as string which means some special treatment of special characters. 265 */ 191 266 inline void setValue(const std::string& name, const std::string& value, bool bString) 192 267 { this->getOrCreateEntry(name, value, bString)->setValue(value); } 268 /** 269 @brief Returns the value of a given entry in the section. Returns a blank string if the value doesn't exist. 270 271 @param name The name of the entry 272 @param bString If true, the value is treated as string which means some special treatment of special characters. 273 */ 193 274 inline const std::string& getValue(const std::string& name, bool bString) 194 275 { … … 196 277 if (entry) 197 278 { 198 entry->setString(bString); 279 entry->setString(bString); // if the entry was loaded from the config file, we have to tell it if it's a string 199 280 return entry->getValue(); 200 281 } 201 282 return BLANKSTRING; 202 283 } 284 /** 285 @brief Returns the value of a given entry in the section. If it doesn't exist, the entry is created using the fallback value. 286 287 @param name The name of the entry 288 @param fallback The value that will be used if the entry doesn't exist 289 @param bString If true, the value is treated as string which means some special treatment of special characters. 290 */ 203 291 inline const std::string& getOrCreateValue(const std::string& name, const std::string& fallback, bool bString) 204 292 { return this->getOrCreateEntry(name, fallback, bString)->getValue(); } 205 293 294 /** 295 @brief Stores the value of an element of a vector in the section. If the entry doesn't exist, it's created. 296 297 @param name The name of the vector 298 @param index The index of the element in the vector 299 @param value The new value 300 @param bString If true, the value is treated as string which means some special treatment of special characters. 301 */ 206 302 inline void setValue(const std::string& name, unsigned int index, const std::string& value, bool bString) 207 303 { this->getOrCreateEntry(name, index, value, bString)->setValue(value); } 304 /** 305 @brief Returns the value of a given element of a vector in the section. Returns a blank string if the value doesn't exist. 306 307 @param name The name of the vector 308 @param index The index of the element in the vector 309 @param bString If true, the value is treated as string which means some special treatment of special characters. 310 */ 208 311 inline const std::string& getValue(const std::string& name, unsigned int index, bool bString) 209 312 { … … 211 314 if (entry) 212 315 { 213 entry->setString(bString); 316 entry->setString(bString); // if the entry was loaded from the config file, we have to tell it if it's a string 214 317 return entry->getValue(); 215 318 } 216 319 return BLANKSTRING; 217 320 } 321 /** 322 @brief Returns the value of a given element of a vector in the section. If it doesn't exist, the entry is created using the fallback value. 323 324 @param name The name of the vector 325 @param index The index of the element in the vector 326 @param fallback The value that will be used if the entry doesn't exist 327 @param bString If true, the value is treated as string which means some special treatment of special characters. 328 */ 218 329 inline const std::string& getOrCreateValue(const std::string& name, unsigned int index, const std::string& fallback, bool bString) 219 330 { return this->getOrCreateEntry(name, index, fallback, bString)->getValue(); } … … 225 336 226 337 private: 338 /// Returns the list of entries in this section. 227 339 std::list<ConfigFileEntry*>& getEntries() 228 340 { return this->entries_; } 341 /// Returns the begin-iterator of the list of entries in this section. 229 342 std::list<ConfigFileEntry*>::const_iterator getEntriesBegin() const 230 343 { return this->entries_.begin(); } 344 /// Returns the end-iterator of the list of entries in this section. 231 345 std::list<ConfigFileEntry*>::const_iterator getEntriesEnd() const 232 346 { return this->entries_.end(); } … … 236 350 237 351 ConfigFileEntry* getEntry(const std::string& name) const; 352 /** 353 @brief Returns the entry with given name. If it doesn't exist, the entry is created using the fallback value. 354 355 @param name The name of the entry 356 @param fallback The value that will be used if the entry doesn't exist 357 @param bString If true, the value is treated as string which means some special treatment of special characters. 358 */ 238 359 inline ConfigFileEntry* getOrCreateEntry(const std::string& name, const std::string& fallback, bool bString) 239 360 { return (*this->getOrCreateEntryIterator(name, fallback, bString)); } 361 240 362 ConfigFileEntry* getEntry(const std::string& name, unsigned int index) const; 363 /** 364 @brief Returns the entry that contains an element of a vector with given name. If it doesn't exist, the entry is created using the fallback value. 365 366 @param name The name of the entry 367 @param index The index of the element in the vector 368 @param fallback The value that will be used if the entry doesn't exist 369 @param bString If true, the value is treated as string which means some special treatment of special characters. 370 */ 241 371 inline ConfigFileEntry* getOrCreateEntry(const std::string& name, unsigned int index, const std::string& fallback, bool bString) 242 372 { return (*this->getOrCreateEntryIterator(name, index, fallback, bString)); } 243 373 244 std::string name_; 245 std::string additionalComment_; 246 std::list<ConfigFileEntry*> entries_; 247 bool bUpdated_; 374 std::string name_; ///< The name of the section 375 std::string additionalComment_; ///< The additional comment which is placed after the title of the section in the config file 376 std::list<ConfigFileEntry*> entries_; ///< The list of entries in this section 377 bool bUpdated_; ///< True if an entry is created 248 378 }; 249 379 … … 252 382 // ConfigFile // 253 383 //////////////// 384 /** 385 @brief This class represents a config file, which is stored on the hard-disk and contains config values in different sections. 386 387 It provides an interface to manipulate the sections and values. 388 */ 254 389 class _CoreExport ConfigFile 255 390 { … … 263 398 virtual void clear(); 264 399 400 /// Returns the file-name of this config file 265 401 inline const std::string& getFilename() 266 402 { return this->filename_; } 267 403 404 /** 405 @brief Stores a value in the config file. If the entry or its section doesn't exist, it's created. 406 407 @param section The name of the section 408 @param name The name of the entry 409 @param value The new value 410 @param bString If true, the value is treated as string which means some special treatment of special characters. 411 */ 268 412 inline void setValue(const std::string& section, const std::string& name, const std::string& value, bool bString) 269 413 { … … 271 415 this->save(); 272 416 } 417 /** 418 @brief Returns the value of a given entry in the config file. Returns a blank string if the value doesn't exist. 419 420 @param section The name of the section 421 @param name The name of the entry 422 @param bString If true, the value is treated as string which means some special treatment of special characters. 423 */ 273 424 inline const std::string& getValue(const std::string& section, const std::string& name, bool bString) 274 425 { … … 276 427 return (sectionPtr ? sectionPtr->getValue(name, bString) : BLANKSTRING); 277 428 } 278 const std::string& getOrCreateValue(const std::string& section, const std::string& name, const std::string& fallback, bool bString); 279 429 /** 430 @brief Returns the value of a given entry in the config file. If it doesn't exist, the entry is created using the fallback value. 431 432 @param section The name of the section 433 @param name The name of the entry 434 @param fallback The value that will be used if the entry doesn't exist 435 @param bString If true, the value is treated as string which means some special treatment of special characters. 436 */ 437 inline const std::string& getOrCreateValue(const std::string& section, const std::string& name, const std::string& fallback, bool bString) 438 { 439 const std::string& output = this->getOrCreateSection(section)->getOrCreateValue(name, fallback, bString); 440 this->saveIfUpdated(); 441 return output; 442 } 443 444 /** 445 @brief Stores the value of an element of a vector in the config file. If the entry or its section doesn't exist, it's created. 446 447 @param section The name of the section 448 @param name The name of the vector 449 @param index The index of the element in the vector 450 @param value The new value 451 @param bString If true, the value is treated as string which means some special treatment of special characters. 452 */ 280 453 inline void setValue(const std::string& section, const std::string& name, unsigned int index, const std::string& value, bool bString) 281 454 { … … 283 456 this->save(); 284 457 } 458 /** 459 @brief Returns the value of a given element of a vector in the config file. Returns a blank string if the value doesn't exist. 460 461 @param section The name of the section 462 @param name The name of the vector 463 @param index The index of the element in the vector 464 @param bString If true, the value is treated as string which means some special treatment of special characters. 465 */ 285 466 inline const std::string& getValue(const std::string& section, const std::string& name, unsigned int index, bool bString) 286 467 { … … 288 469 return (sectionPtr ? sectionPtr->getValue(name, index, bString) : BLANKSTRING); 289 470 } 290 const std::string& getOrCreateValue(const std::string& section, const std::string& name, unsigned int index, const std::string& fallback, bool bString); 471 /** 472 @brief Returns the value of a given element of a vector in the config file. If it doesn't exist, the entry is created using the fallback value. 473 474 @param section The name of the section 475 @param name The name of the vector 476 @param index The index of the element in the vector 477 @param fallback The value that will be used if the entry doesn't exist 478 @param bString If true, the value is treated as string which means some special treatment of special characters. 479 */ 480 const std::string& getOrCreateValue(const std::string& section, const std::string& name, unsigned int index, const std::string& fallback, bool bString) 481 { 482 const std::string& output = this->getOrCreateSection(section)->getOrCreateValue(name, index, fallback, bString); 483 this->saveIfUpdated(); 484 return output; 485 } 291 486 292 487 void deleteVectorEntries(const std::string& section, const std::string& name, unsigned int startindex = 0); 488 /** 489 @brief Returns the size of a config vector. 490 @param section The section of the vector 491 @param name The name of the vector 492 */ 293 493 inline unsigned int getVectorSize(const std::string& section, const std::string& name) const 294 494 { … … 297 497 } 298 498 299 static const char* DEFAULT_CONFIG_FOLDER; 499 static const char* DEFAULT_CONFIG_FOLDER; ///< The folder where the default config files will be stored 300 500 301 501 protected: … … 303 503 ConfigFileSection* getOrCreateSection(const std::string& section); 304 504 305 std::list<ConfigFileSection*> sections_; 505 std::list<ConfigFileSection*> sections_; ///< A list of sections in this config file 306 506 307 507 private: 308 508 void saveIfUpdated(); 309 const std::string filename_; 310 const bool bCopyFallbackFile_; 311 bool bUpdated_; 509 510 const std::string filename_; ///< The filename of this config file 511 const bool bCopyFallbackFile_; ///< If true, the default config file is copied into the config-directory before loading the file 512 bool bUpdated_; ///< Becomes true if a section is added 312 513 }; 313 514 … … 316 517 // SettingsConfigFile // 317 518 //////////////////////// 519 /** 520 @brief Child class of ConfigFile, used to store the settings of the game. 521 522 In addition to ConfigFile, this class provides an interface to manipulate the settings 523 with console commands and to cache entries in instances of ConfigValueContainer. 524 525 SettingsConfigFile is a Singleton, meaning there's only one instance of this class 526 (and thus only one config file that stores settings). 527 */ 318 528 class _CoreExport SettingsConfigFile // tolua_export 319 529 : public ConfigFile, public Singleton<SettingsConfigFile> … … 338 548 void removeConfigValueContainer(ConfigValueContainer* container); 339 549 550 /// Returns a set containing the names of all sections in this config file. 340 551 inline const std::set<std::string>& getSectionNames() 341 552 { return this->sectionNames_; } 553 /// Returns the lower-bound-iterator of the @ref ConfigValueContainer "config value containers" for the given section. 342 554 inline ContainerMap::const_iterator getContainerLowerBound(const std::string section) 343 555 { return this->containers_.lower_bound(section); } 556 /// Returns the upper-bound-iterator of the @ref ConfigValueContainer "config value containers" for the given section. 344 557 inline ContainerMap::const_iterator getContainerUpperBound(const std::string section) 345 558 { return this->containers_.upper_bound(section); } … … 351 564 bool configImpl(const std::string& section, const std::string& entry, const std::string& value, bool (ConfigValueContainer::*function)(const MultiType&)); 352 565 353 ContainerMap containers_; 354 std::set<std::string> sectionNames_; 355 static SettingsConfigFile* singletonPtr_s; 566 ContainerMap containers_; ///< Stores all @ref ConfigValueContainer "config value containers" 567 std::set<std::string> sectionNames_; ///< Stores all section names 568 static SettingsConfigFile* singletonPtr_s; ///< The singleton pointer 356 569 }; // tolua_export 357 570 … … 360 573 // ConfigFileManager // 361 574 /////////////////////// 575 /** 576 @brief Manages the different config files (settings, calibration, etc). Implemented as Singleton. 577 */ 362 578 class _CoreExport ConfigFileManager : public Singleton<ConfigFileManager> 363 579 { … … 369 585 void setFilename(ConfigFileType::Value type, const std::string& filename); 370 586 587 /// Returns the config file of a given type (settings, calibration, etc.) 371 588 inline ConfigFile* getConfigFile(ConfigFileType::Value type) 372 589 { … … 376 593 377 594 private: 378 ConfigFileManager(const ConfigFileManager&); 379 380 boost::array<ConfigFile*, 3> configFiles_; 381 static ConfigFileManager* singletonPtr_s; 595 ConfigFileManager(const ConfigFileManager&); ///< Copy-constructor: not implemented 596 597 boost::array<ConfigFile*, 3> configFiles_; ///< Stores the config files for each type in an array (must have the same size like ConfigFileType::Value) 598 static ConfigFileManager* singletonPtr_s; ///< Stores the singleton-pointer 382 599 }; 383 600 } // tolua_export -
code/trunk/src/libraries/core/ConfigValueContainer.h
r6536 r7401 29 29 /** 30 30 @file 31 @brief Definition of the ConfigValueContainer class. 31 @ingroup Config ConfigFile 32 @brief Declaration of the ConfigValueContainer class, caches a config-value. 32 33 33 34 The ConfigValueContainer class contains all needed information about a configurable variable: … … 78 79 79 80 80 //! The ConfigValuecontainer contains all needed information about a configurable variable.81 81 /** 82 @brief The ConfigValuecontainer contains all needed information about a configurable variable. 83 82 84 The ConfigValueContainer class contains all needed information about a configurable variable: 83 85 - the name of the variable … … 117 119 @param type The type of the corresponding config-file 118 120 @param identifier The identifier of the class the variable belongs to 121 @param sectionname Name of the section the configValue should be put in. 119 122 @param varname The name of the variable 120 123 @param defvalue The default-value 124 @param value Only needed do determine the right type. 121 125 */ 122 126 template <class D, class V> … … 213 217 } 214 218 215 / ** @brief Returns the name of this container. */219 /// Returns the name of this container. 216 220 inline const std::string& getName() const 217 221 { return this->varname_; } 218 / ** @brief Returns the name of the section this config value is in. */222 /// Returns the name of the section this config value is in. 219 223 inline const std::string& getSectionName() const 220 224 { return this->sectionname_; } 221 / ** @brief Returns the associated identifier (can be NULL). */225 /// Returns the associated identifier (can be NULL). 222 226 inline Identifier* getIdentifier() const 223 227 { return this->identifier_; } 224 / ** @brief Returns true if this config-value is a vector */228 /// Returns true if this config-value is a vector. 225 229 inline bool isVector() const 226 230 { return this->bIsVector_; } 227 / ** @brief Returns the vectors size (or zero if it's not a vector). */231 /// Returns the vectors size (or zero if it's not a vector). 228 232 inline unsigned int getVectorSize() const 229 233 { return this->valueVector_.size(); } … … 265 269 void update(); 266 270 267 / ** @brief Converts the config-value to a string. @return The string */271 /// Converts the config-value to a string. 268 272 inline std::string toString() const 269 273 { return this->value_; } 270 / ** @brief Returns the typename of the assigned config-value. @return The typename */274 /// Returns the typename of the assigned config-value. 271 275 inline std::string getTypename() const 272 276 { return this->value_.getTypename(); } -
code/trunk/src/libraries/core/ConfigValueIncludes.h
r7166 r7401 28 28 29 29 /** 30 @file 31 @brief 32 Definition of macros and functions for config-values. 30 @defgroup ConfigFile Config file 31 @ingroup Config 32 */ 33 34 /** 35 @file 36 @ingroup Config ConfigFile 37 @brief Definition of macros and functions for config-values. 38 39 An example of how to use SetConfigValue(): 40 41 Definition of a class in the header-file: 42 @code 43 class MyClass : public BaseObject 44 { 45 public: 46 MyClass(); // Constructor 47 void setConfigValues(); // Inherited function 48 49 const std::string& getName() 50 { return this->name_; } 51 52 float getVersion() 53 { return this->version_; } 54 55 private: 56 std::string name_; 57 float version_; 58 }; 59 @endcode 60 61 Implementation of the class source-file: 62 @code 63 MyClass::MyClass() 64 { 65 // Macro-call to create an Identifier 66 RegisterObject(MyClass); 67 68 // Function-call to assign the config-values to the new object 69 this->setConfigValues(); 70 } 71 72 void MyClass::setConfigValues() 73 { 74 SetConfigValue(name_, "Orxonox").description("The name of the game"); 75 SetConfigValue(version_, "1.0").description("The version-number"); 76 } 77 @endcode 78 79 Extract of orxonox.ini: 80 @code 81 [MyClass] 82 name_ = "Orxonox" 83 version_ = 1.1 // We have changed this value from 1.0 to 1.1 84 @endcode 85 86 Some other code: 87 @code 88 MyObject orxonoxobject; 89 std::cout << "Name: " << orxonoxobject.getName() << std::endl; 90 std::cout << "Version: " << orxonoxobject.getVersion() << std::endl; 91 @endcode 92 93 Output: 94 @code 95 Name: Orxonox 96 Version: 1.1 97 @endcode 33 98 */ 34 99 -
code/trunk/src/libraries/core/Core.cc
r7284 r7401 37 37 38 38 #include <cassert> 39 #include <fstream> 39 40 #include <vector> 40 41 … … 171 172 // Create singletons that always exist (in other libraries) 172 173 this->rootScope_.reset(new Scope<ScopeID::Root>()); 174 175 // Generate documentation instead of normal run? 176 std::string docFilename; 177 CommandLineParser::getValue("generateDoc", &docFilename); 178 if (!docFilename.empty()) 179 { 180 std::ofstream docFile(docFilename.c_str()); 181 if (docFile.is_open()) 182 { 183 CommandLineParser::generateDoc(docFile); 184 docFile.close(); 185 } 186 else 187 COUT(0) << "Error: Could not open file for documentation writing" << endl; 188 } 173 189 } 174 190 -
code/trunk/src/libraries/core/Core.h
r7266 r7401 28 28 */ 29 29 30 /** 31 @defgroup CoreGame Core and Game 32 @ingroup Management 33 */ 34 35 /** 36 @file 37 @ingroup Management CoreGame 38 @brief Declaration of the Core singleton which is used to configure the program basics. 39 */ 40 30 41 #ifndef _Core_H__ 31 42 #define _Core_H__ … … 33 44 #include "CorePrereqs.h" 34 45 35 #include <cassert>36 46 #include <string> 37 47 #include <boost/scoped_ptr.hpp> -
code/trunk/src/libraries/core/CoreIncludes.h
r6423 r7401 28 28 29 29 /** 30 @defgroup Factory RegisterObject() and CreateFactory() 31 @ingroup Object 32 */ 33 34 /** 30 35 @file 31 @brief Definition of macros for Identifiers 36 @ingroup Object Factory 37 @brief Defines several very important macros used to register objects, create factories, and to work with identifiers. 32 38 33 Every class needs the RegisterObject(class) macro in its constructor. If the class is an interface34 or the BaseObject itself, it needs the macroRegisterRootObject(class) instead.39 Every class needs the @c RegisterObject(class) macro in its constructor. If the class is an interface 40 or the @c BaseObject itself, it needs the macro @c RegisterRootObject(class) instead. 35 41 36 To allow the object being created through the factory, use the CreateFactory(class) macro outside 37 the of the class implementation, so it gets executed before main(). 42 To allow the object being created through the factory, use the @c CreateFactory(class) macro outside 43 of the class implementation, so it gets executed statically before @c main(). This will at the same time 44 register @a class in the class-hierarchy. If you don't want @a class to be loadable, but still 45 register it, call @c CreateUnloadableFactory(class). 46 47 Example: 48 @code 49 // Create the factory for MyClass 50 CreateFactory(MyClass); 51 52 // Constructor: 53 MyClass::MyClass() 54 { 55 // Register the object in the Identifier of MyClass 56 RegisterObject(MyClass); 57 } 58 @endcode 59 60 This file also defines a number of other useful macros, like, for example, @c Class(class) which 61 returns the @ref orxonox::Identifier "Identifier" of @a class, or @c ClassByString("class") which 62 returns the Identifier of a class with name @a "class". 63 64 Example: 65 @code 66 // Assigns the Identifier of MyClass 67 Identifier* identifier = Class(MyClass); 68 @endcode 69 @code 70 // Assigns the Identifier of a class named "MyClass" 71 Identifier* identifier = ClassByString("MyClass"); 72 @endcode 38 73 */ 39 74 … … 51 86 52 87 /** 53 @brief Intern macro, containing the common parts of RegisterObject andRegisterRootObject.88 @brief Intern macro, containing the common parts of @c RegisterObject and @c RegisterRootObject. 54 89 @param ClassName The name of the class 55 @param bRootClass True if the class is directly derived from OrxonoxClass90 @param bRootClass True if the class is directly derived from orxonox::OrxonoxClass 56 91 */ 57 92 #define InternRegisterObject(ClassName, bRootClass) \ … … 62 97 63 98 /** 64 @brief Register Object - with and without debug output.99 @brief Registers a newly created object in the core. Has to be called at the beginning of the constructor of @a ClassName. 65 100 @param ClassName The name of the class 66 101 */ … … 69 104 70 105 /** 71 @brief Register RootObject - with and without debug output.106 @brief Registers a newly created object in the core. Has to be called at the beginning of the constructor of @a ClassName. 72 107 @param ClassName The name of the class 108 109 In contrast to RegisterObject, this is used for classes that inherit directly from 110 orxonox::OrxonoxClass, namely all interfaces and orxonox::BaseObject. 73 111 */ 74 112 #define RegisterRootObject(ClassName) \ … … 101 139 /** 102 140 @brief Returns the Identifier with a given name. 103 @param StringThe name of the class141 @param name The name of the class 104 142 */ 105 143 inline Identifier* ClassByString(const std::string& name) … … 110 148 /** 111 149 @brief Returns the Identifier with a given lowercase name. 112 @param StringThe lowercase name of the class150 @param name The lowercase name of the class 113 151 */ 114 152 inline Identifier* ClassByLowercaseString(const std::string& name) … … 119 157 /** 120 158 @brief Returns the Identifier with a given network ID. 121 @param networkIDThe network ID of the class159 @param id The network ID of the class 122 160 */ 123 161 inline Identifier* ClassByID(uint32_t id) … … 130 168 @note This of course only works with OrxonoxClasses. 131 169 The only use is in conjunction with macros that don't know the class type. 132 @param Pointer to an OrxonoxClass170 @param object Pointer to an OrxonoxClass 133 171 */ 134 172 template <class T> -
code/trunk/src/libraries/core/DynLib.h
r6073 r7401 29 29 30 30 // 08/11/2009: Small adjustments for Orxonox by Fabian 'x3n' Landau 31 32 /** 33 @file 34 @ingroup Management CoreGame 35 @brief Declaration of DynLib which represents a dynamically loaded module. 36 */ 31 37 32 38 #ifndef _Core_DynLib_H__ … … 61 67 namespace orxonox 62 68 { 63 /** Resource holding data about a dynamic library.69 /** %Resource holding data about a dynamic library. 64 70 @remarks 65 71 This class holds the data required to get symbols from … … 69 75 @since 70 76 27 January 2002 71 @see72 Resource73 77 */ 74 78 class _CoreExport DynLib -
code/trunk/src/libraries/core/DynLibManager.h
r5738 r7401 30 30 // 08/11/2009: Small adjustments for Orxonox by Fabian 'x3n' Landau 31 31 32 /** 33 @file 34 @ingroup Management CoreGame 35 @brief Declaration of DynLibManager, used to load modules at runtime. 36 */ 37 32 38 #ifndef _Core_DynLibManager_H__ 33 39 #define _Core_DynLibManager_H__ … … 56 62 57 63 public: 58 /** Default constructor. 59 @note 60 <br>Should never be called as the singleton is automatically 61 created during the creation of the Root object. 62 @see 63 Root::Root 64 /** 65 @brief 66 Default constructor. 67 @note 68 Should never be called as the singleton is automatically 69 created during the creation of the Root object. 70 @see 71 Root::Root 64 72 */ 65 73 DynLibManager(); 66 74 67 /** Default destructor. 68 @see 69 Root::~Root 75 /** 76 @brief 77 Default destructor. 78 @see 79 Root::~Root 70 80 */ 71 81 virtual ~DynLibManager(); 72 82 73 /** Loads the passed library. 74 @param 75 filename The name of the library. The extension can be omitted 83 /** 84 @brief 85 Loads the passed library. 86 @param filename 87 The name of the library. The extension can be omitted 76 88 */ 77 89 DynLib* load(const std::string& filename); 78 90 79 /** Unloads the passed library. 80 @param 81 filename The name of the library. The extension can be omitted 91 /** 92 @brief 93 Unloads the passed library. 94 @param lib 95 A pointer to the library object 82 96 */ 83 97 void unload(DynLib* lib); -
code/trunk/src/libraries/core/Event.cc
r7284 r7401 26 26 * 27 27 */ 28 29 /** 30 @file 31 @brief Implementation of the classes Event and EventState. 32 */ 28 33 29 34 #include "Event.h" -
code/trunk/src/libraries/core/Event.h
r7284 r7401 27 27 */ 28 28 29 /** 30 @defgroup Event Events 31 @ingroup Core 32 */ 33 34 /** 35 @file 36 @ingroup Event 37 @brief Declaration of the classes Event and EventState. 38 */ 39 29 40 #ifndef _Event_H__ 30 41 #define _Event_H__ … … 54 65 An event state is a state of an object, which can be changed by events. 55 66 Event states are changed through functions. Possible functions headers for set event states are: 56 - memoryless state: function()57 - boolean state: function(bool state)58 - individual state: function(bool state, SomeClass originator)67 - memoryless state: <tt>function()</tt> 68 - boolean state: <tt>function(bool state)</tt> 69 - individual state: <tt>function(bool state, SomeClass originator)</tt> 59 70 60 71 Note that SomeClass may be any class deriving from BaseObject. You will not receive events from originators of other classes. 61 The actual class for SomeClass must be specified as the second argument of the XMLPortEventState macro.72 The actual class for SomeClass must be specified as the second argument of the XMLPortEventState() macro. 62 73 63 74 The this pointer of the affected object is hidden in the functors, because the events are processed in the BaseObject, but some -
code/trunk/src/libraries/core/EventIncludes.h
r7301 r7401 26 26 * 27 27 */ 28 29 /** 30 @file 31 @ingroup Event 32 @brief Definition of the XMLPortEventState() macro, as well as some more useful macros. 33 */ 28 34 29 35 #ifndef _EventIncludes_H__ -
code/trunk/src/libraries/core/GUIManager.cc
r7284 r7401 110 110 After Lua setup tolua++-elements are linked to Lua-state to give Lua access to C++-code. 111 111 Finally initial Lua code is executed (maybe we can do this with the CEGUI startup script automatically). 112 @param renderWindow113 Ogre's render window. Without this, the GUI cannot be displayed.114 112 @return true if success, otherwise false 115 113 */ … … 237 235 @param name 238 236 The name of the GUI 237 @param bHidePrevious 238 If true all displayed GUIs on the stack, that are below this GUI are hidden. 239 239 240 240 The function executes the Lua function with the same name in case the GUIManager is ready. -
code/trunk/src/libraries/core/GUIManager.h
r7163 r7401 27 27 * 28 28 */ 29 30 /** 31 @file 32 @ingroup Graphics 33 */ 29 34 30 35 #ifndef _GUIManager_H__ -
code/trunk/src/libraries/core/Game.h
r7266 r7401 29 29 /** 30 30 @file 31 @ingroup Management CoreGame 31 32 @brief 32 Declaration of Game Singleton .33 Declaration of Game Singleton which is responsible for running the game. 33 34 */ 34 35 … … 53 54 54 55 /** 55 @ def56 @brief 56 57 Adds a new GameState to the Game. The second parameter is the name as string 57 58 and every following paramter is a constructor argument (which is usually non existent) -
code/trunk/src/libraries/core/GameMode.cc
r5929 r7401 33 33 bool GameMode::bShowsGraphics_s = false; 34 34 bool GameMode::bPlaysSound_s = false; 35 bool GameMode::b HasServer_s= false;35 bool GameMode::bIsServer_s = false; 36 36 bool GameMode::bIsClient_s = false; 37 37 bool GameMode::bIsStandalone_s = false; -
code/trunk/src/libraries/core/GameMode.h
r6417 r7401 29 29 /** 30 30 @file 31 @brief Declaration of the GameMode class. 31 @ingroup Management CoreGame 32 @brief Declaration of the GameMode class which stores and returns the current mode of the game. 32 33 */ 33 34 … … 40 41 namespace orxonox 41 42 { 43 /// Helper class, stores and returns the current mode of the game. 42 44 class _CoreExport GameMode 43 45 { … … 47 49 public: 48 50 // tolua_begin 49 static bool showsGraphics() { return bShowsGraphics_s; } 50 static bool playsSound() { return bPlaysSound_s; } 51 static bool hasServer() { return bHasServer_s; }52 static bool isClient() { return bIsClient_s; } 53 static bool isStandalone() { return bIsStandalone_s; } 54 static bool isMaster() { return bIsMaster_s; } 51 static bool showsGraphics() { return bShowsGraphics_s; } ///< Returns true if the game shows graphics, false if it is in text-console mode 52 static bool playsSound() { return bPlaysSound_s; } ///< Returns true if the game is able to play sounds 53 static bool isServer() { return bIsServer_s; } ///< Returns true if we're currently a server (online) 54 static bool isClient() { return bIsClient_s; } ///< Returns true if we're currently a client (online) 55 static bool isStandalone() { return bIsStandalone_s; } ///< Returns true if we're in standalone mode (offline) 56 static bool isMaster() { return bIsMaster_s; } ///< Returns true if we're in control of the game (either standalone or server) 55 57 // tolua_end 56 58 57 static void setPlaysSound (bool val) { bPlaysSound_s = val; } 58 static void set HasServer (bool val) { bHasServer_s = val; updateIsMaster(); }59 static void setIsClient (bool val) { bIsClient_s = val; updateIsMaster(); } 60 static void setIsStandalone (bool val) { bIsStandalone_s = val; updateIsMaster(); } 59 static void setPlaysSound (bool val) { bPlaysSound_s = val; } ///< Defines if the game can play sounds 60 static void setIsServer (bool val) { bIsServer_s = val; updateIsMaster(); } ///< Defines if the program is in server mode (online) 61 static void setIsClient (bool val) { bIsClient_s = val; updateIsMaster(); } ///< Defines if the program is in client mode (online) 62 static void setIsStandalone (bool val) { bIsStandalone_s = val; updateIsMaster(); } ///< Defines if the program is in standalone mode (offline) 61 63 62 64 private: … … 65 67 ~GameMode(); 66 68 69 /// Checks if we're in control of the game (either standalone or server). 67 70 static void updateIsMaster() 68 71 { 69 bIsMaster_s = (b HasServer_s || bIsStandalone_s);72 bIsMaster_s = (bIsServer_s || bIsStandalone_s); 70 73 } 71 74 72 75 static bool bShowsGraphics_s; //!< global variable that tells whether to show graphics 73 76 static bool bPlaysSound_s; //!< global variable that tells whether to sound works 74 static bool b HasServer_s; //!< global variable that tells whether this is a server75 static bool bIsClient_s; 76 static bool bIsStandalone_s; 77 static bool bIsMaster_s; 77 static bool bIsServer_s; //!< global variable that tells whether this is a server (online) 78 static bool bIsClient_s; //!< global variable that tells whether this is a client (online) 79 static bool bIsStandalone_s; //!< global variable that tells whether the game is running in standalone mode (offline) 80 static bool bIsMaster_s; //!< global variable that tells whether we're in control of the game (standalone or server) 78 81 }; // tolua_export 79 82 } // tolua_export -
code/trunk/src/libraries/core/GameState.h
r5929 r7401 29 29 /** 30 30 @file 31 @ingroup Management CoreGame 31 32 @brief 32 33 Definition of GameState class. -
code/trunk/src/libraries/core/GraphicsManager.h
r7284 r7401 29 29 30 30 /** 31 @defgroup Graphics Graphics and GUI 32 @ingroup Core 33 */ 34 35 /** 31 36 @file 37 @ingroup Graphics 32 38 @brief 33 39 Declaration of GraphicsManager Singleton. -
code/trunk/src/libraries/core/Identifier.cc
r7284 r7401 217 217 /** 218 218 @brief Sets the name of the class. 219 @param name The name220 219 */ 221 220 void Identifier::setName(const std::string& name) … … 253 252 /** 254 253 @brief Sets the network ID to a new value and changes the entry in the ID-Identifier-map. 255 @param id The new network ID256 254 */ 257 255 void Identifier::setNetworkID(uint32_t id) -
code/trunk/src/libraries/core/Identifier.h
r7284 r7401 28 28 29 29 /** 30 @defgroup Identifier Identifier 31 @ingroup Class 32 */ 33 34 /** 30 35 @file 31 @brief Definition of the Identifier class, definition and implementation of the ClassIdentifier class. 32 33 The Identifier contains all needed information about the class it belongs to: 34 - the name 35 - a list with all objects 36 - parents and children 37 - the factory (if available) 38 - the networkID that can be synchronised with the server 39 - all configurable variables (if available) 40 41 Every object has a pointer to the Identifier of its class. This allows the use isA(...), 42 isExactlyA(...), isChildOf(...) and isParentOf(...). 43 44 To create the class-hierarchy, the Identifier has some intern functions and variables. 45 46 Every Identifier is in fact a ClassIdentifier, but they are derived from Identifier. 36 @ingroup Class Identifier 37 @brief Declaration of Identifier, definition of ClassIdentifier<T>; used to identify the class of an object. 38 39 @anchor IdentifierExample 40 41 An Identifier "identifies" the class of an object. It contains different information about 42 the class: Its name and ID, a list of all instances of this class, a factory to create new 43 instances of this class, and more. 44 45 It also contains information about the inheritance of this class: It stores a list of the 46 Identifiers of all parent-classes as well as a list of all child-classes. These relationships 47 can be tested using functions like @c isA(), @c isChildOf(), @c isParentOf(), and more. 48 49 Every Identifier is in fact a ClassIdentifier<T> (where T is the class that is identified 50 by the Identifier), Identifier is just the common base-class. 51 52 Example: 53 @code 54 MyClass* object = new MyClass(); // create an instance of MyClass 55 56 object->getIdentifier()->getName(); // returns "MyClass" 57 58 BaseObject* other = object->getIdentifier()->fabricate(0); // fabricates a new instance of MyClass 59 60 61 // iterate through all objects of type MyClass: 62 ObjectListBase* objects = object->getIdentifier()->getObjects(); // get a pointer to the object-list 63 int count; 64 for (Iterator<BaseObject> it = objects.begin(); it != objects.end(); ++it) // iterate through the objects 65 ++count; 66 COUT(0) << count << std::endl; // prints "2" because we created 2 instances of MyClass so far 67 68 69 // test the class hierarchy 70 object->getIdentifier()->isA(Class(MyClass)); // returns true 71 object->isA(Class(MyClass)); // returns true (short version) 72 73 object->isA(Class(BaseClass)); // returns true if MyClass is a child of BaseClass 74 75 Class(ChildClass)->isChildOf(object->getIdentifier()); // returns true if ChildClass is a child of MyClass 76 @endcode 47 77 */ 48 78 … … 70 100 // ### Identifier ### 71 101 // ############################### 72 //! The Identifier is used to identify the class of an object and to store information about the class. 73 /** 74 The Identifier contains all needed information about the class it belongs to: 75 - the name 76 - a list with all objects 77 - parents and children 78 - the factory (if available) 79 - the networkID that can be synchronised with the server 80 - all configurable variables (if available) 81 82 Every object has a pointer to the Identifier of its class. This allows the use isA(...), 83 isExactlyA(...), isChildOf(...) and isParentOf(...). 84 85 You can't directly create an Identifier, it's just the base-class for ClassIdentifier. 102 /** 103 @brief The Identifier is used to identify the class of an object and to store information about the class. 104 105 Each Identifier stores information about one class. The Identifier can then be used to identify 106 this class. On the other hand it's also possible to get the corresponding Identifier of a class, 107 for example by using the macro Class(). 108 109 @see See @ref IdentifierExample "Identifier.h" for more information and some examples. 110 111 @note You can't directly create an Identifier, it's just the base-class of ClassIdentifier<T>. 86 112 */ 87 113 class _CoreExport Identifier 88 114 { 89 115 public: 90 / ** @brief Returns the name of the class the Identifier belongs to. @return The name */116 /// Returns the name of the class the Identifier belongs to. 91 117 inline const std::string& getName() const { return this->name_; } 92 118 void setName(const std::string& name); 93 119 94 / ** @brief Returns the network ID to identify a class through the network. @return the network ID */120 /// Returns the network ID to identify a class through the network. 95 121 inline const uint32_t getNetworkID() const { return this->networkID_; } 96 122 void setNetworkID(uint32_t id); 97 123 98 / ** @brief Returns the unique ID of the class */124 /// Returns the unique ID of the class. 99 125 FORCEINLINE unsigned int getClassID() const { return this->classID_; } 100 126 101 / ** @brief Returns the list of all existing objects of this class. @return The list */127 /// Returns the list of all existing objects of this class. 102 128 inline ObjectListBase* getObjects() const { return this->objects_; } 103 129 104 / ** @brief Sets the Factory. @param factory The factory to assign */130 /// Sets the Factory. 105 131 inline void addFactory(Factory* factory) { this->factory_ = factory; } 106 / ** @brief Returns true if the Identifier has a Factory. */132 /// Returns true if the Identifier has a Factory. 107 133 inline bool hasFactory() const { return (this->factory_ != 0); } 108 134 109 135 BaseObject* fabricate(BaseObject* creator); 110 136 111 / ** @brief Returns true if the class can be loaded through XML. */137 /// Returns true if the class can be loaded through XML. 112 138 inline bool isLoadable() const { return this->bLoadable_; } 113 / ** @brief Set the class to be loadable through XML or not. */139 /// Set the class to be loadable through XML or not. 114 140 inline void setLoadable(bool bLoadable) { this->bLoadable_ = bLoadable; } 115 141 … … 127 153 static void createClassHierarchy(); 128 154 129 / ** @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 */155 /// Returns true, if a branch of the class-hierarchy is being created, causing all new objects to store their parents. 130 156 inline static bool isCreatingHierarchy() { return (hierarchyCreatingCounter_s > 0); } 131 157 132 / ** @brief Returns the parents of the class the Identifier belongs to. @return The list of all parents */158 /// Returns the parents of the class the Identifier belongs to. 133 159 inline const std::set<const Identifier*>& getParents() const { return this->parents_; } 134 / ** @brief Returns the begin-iterator of the parents-list. @return The begin-iterator */160 /// Returns the begin-iterator of the parents-list. 135 161 inline std::set<const Identifier*>::const_iterator getParentsBegin() const { return this->parents_.begin(); } 136 / ** @brief Returns the end-iterator of the parents-list. @return The end-iterator */162 /// Returns the end-iterator of the parents-list. 137 163 inline std::set<const Identifier*>::const_iterator getParentsEnd() const { return this->parents_.end(); } 138 164 139 / ** @brief Returns the children of the class the Identifier belongs to. @return The list of all children */165 /// Returns the children of the class the Identifier belongs to. 140 166 inline const std::set<const Identifier*>& getChildren() const { return this->children_; } 141 / ** @brief Returns the begin-iterator of the children-list. @return The begin-iterator */167 /// Returns the begin-iterator of the children-list. 142 168 inline std::set<const Identifier*>::const_iterator getChildrenBegin() const { return this->children_.begin(); } 143 / ** @brief Returns the end-iterator of the children-list. @return The end-iterator */169 /// Returns the end-iterator of the children-list. 144 170 inline std::set<const Identifier*>::const_iterator getChildrenEnd() const { return this->children_.end(); } 145 171 146 / ** @brief Returns the direct parents of the class the Identifier belongs to. @return The list of all direct parents */172 /// Returns the direct parents of the class the Identifier belongs to. 147 173 inline const std::set<const Identifier*>& getDirectParents() const { return this->directParents_; } 148 / ** @brief Returns the begin-iterator of the direct-parents-list. @return The begin-iterator */174 /// Returns the begin-iterator of the direct-parents-list. 149 175 inline std::set<const Identifier*>::const_iterator getDirectParentsBegin() const { return this->directParents_.begin(); } 150 / ** @brief Returns the end-iterator of the direct-parents-list. @return The end-iterator */176 /// Returns the end-iterator of the direct-parents-list. 151 177 inline std::set<const Identifier*>::const_iterator getDirectParentsEnd() const { return this->directParents_.end(); } 152 178 153 / ** @brief Returns the direct children the class the Identifier belongs to. @return The list of all direct children */179 /// Returns the direct children the class the Identifier belongs to. 154 180 inline const std::set<const Identifier*>& getDirectChildren() const { return this->directChildren_; } 155 / ** @brief Returns the begin-iterator of the direct-children-list. @return The begin-iterator */181 /// Returns the begin-iterator of the direct-children-list. 156 182 inline std::set<const Identifier*>::const_iterator getDirectChildrenBegin() const { return this->directChildren_.begin(); } 157 / ** @brief Returns the end-iterator of the direct-children-list. @return The end-iterator */183 /// Returns the end-iterator of the direct-children-list. 158 184 inline std::set<const Identifier*>::const_iterator getDirectChildrenEnd() const { return this->directChildren_.end(); } 159 185 … … 170 196 static void clearNetworkIDs(); 171 197 172 / ** @brief Returns the map that stores all Identifiers with their names. @return The map */198 /// Returns the map that stores all Identifiers with their names. 173 199 static inline const std::map<std::string, Identifier*>& getStringIdentifierMap() { return Identifier::getStringIdentifierMapIntern(); } 174 / ** @brief Returns a const_iterator to the beginning of the map that stores all Identifiers with their names. @return The const_iterator */200 /// Returns a const_iterator to the beginning of the map that stores all Identifiers with their names. 175 201 static inline std::map<std::string, Identifier*>::const_iterator getStringIdentifierMapBegin() { return Identifier::getStringIdentifierMap().begin(); } 176 / ** @brief Returns a const_iterator to the end of the map that stores all Identifiers with their names. @return The const_iterator */202 /// Returns a const_iterator to the end of the map that stores all Identifiers with their names. 177 203 static inline std::map<std::string, Identifier*>::const_iterator getStringIdentifierMapEnd() { return Identifier::getStringIdentifierMap().end(); } 178 204 179 / ** @brief Returns the map that stores all Identifiers with their names in lowercase. @return The map */205 /// Returns the map that stores all Identifiers with their names in lowercase. 180 206 static inline const std::map<std::string, Identifier*>& getLowercaseStringIdentifierMap() { return Identifier::getLowercaseStringIdentifierMapIntern(); } 181 / ** @brief Returns a const_iterator to the beginning of the map that stores all Identifiers with their names in lowercase. @return The const_iterator */207 /// Returns a const_iterator to the beginning of the map that stores all Identifiers with their names in lowercase. 182 208 static inline std::map<std::string, Identifier*>::const_iterator getLowercaseStringIdentifierMapBegin() { return Identifier::getLowercaseStringIdentifierMap().begin(); } 183 / ** @brief Returns a const_iterator to the end of the map that stores all Identifiers with their names in lowercase. @return The const_iterator */209 /// Returns a const_iterator to the end of the map that stores all Identifiers with their names in lowercase. 184 210 static inline std::map<std::string, Identifier*>::const_iterator getLowercaseStringIdentifierMapEnd() { return Identifier::getLowercaseStringIdentifierMap().end(); } 185 211 186 / ** @brief Returns the map that stores all Identifiers with their IDs. @return The map */212 /// Returns the map that stores all Identifiers with their IDs. 187 213 static inline const std::map<uint32_t, Identifier*>& getIDIdentifierMap() { return Identifier::getIDIdentifierMapIntern(); } 188 / ** @brief Returns a const_iterator to the beginning of the map that stores all Identifiers with their IDs. @return The const_iterator */214 /// Returns a const_iterator to the beginning of the map that stores all Identifiers with their IDs. 189 215 static inline std::map<uint32_t, Identifier*>::const_iterator getIDIdentifierMapBegin() { return Identifier::getIDIdentifierMap().begin(); } 190 / ** @brief Returns a const_iterator to the end of the map that stores all Identifiers with their IDs. @return The const_iterator */216 /// Returns a const_iterator to the end of the map that stores all Identifiers with their IDs. 191 217 static inline std::map<uint32_t, Identifier*>::const_iterator getIDIdentifierMapEnd() { return Identifier::getIDIdentifierMap().end(); } 192 218 … … 197 223 virtual void updateConfigValues(bool updateChildren = true) const = 0; 198 224 199 / ** @brief Returns true if this class has at least one config value. @return True if this class has at least one config value */225 /// Returns true if this class has at least one config value. 200 226 inline bool hasConfigValues() const { return this->bHasConfigValues_; } 201 227 … … 207 233 ///// XMLPort ///// 208 234 /////////////////// 209 / ** @brief Returns the map that stores all XMLPort params. @return The const_iterator */235 /// Returns the map that stores all XMLPort params. 210 236 inline const std::map<std::string, XMLPortParamContainer*>& getXMLPortParamMap() const { return this->xmlportParamContainers_; } 211 / ** @brief Returns a const_iterator to the beginning of the map that stores all XMLPort params. @return The const_iterator */237 /// Returns a const_iterator to the beginning of the map that stores all XMLPort params. 212 238 inline std::map<std::string, XMLPortParamContainer*>::const_iterator getXMLPortParamMapBegin() const { return this->xmlportParamContainers_.begin(); } 213 / ** @brief Returns a const_iterator to the end of the map that stores all XMLPort params. @return The const_iterator */239 /// Returns a const_iterator to the end of the map that stores all XMLPort params. 214 240 inline std::map<std::string, XMLPortParamContainer*>::const_iterator getXMLPortParamMapEnd() const { return this->xmlportParamContainers_.end(); } 215 241 216 / ** @brief Returns the map that stores all XMLPort objects. @return The const_iterator */242 /// Returns the map that stores all XMLPort objects. 217 243 inline const std::map<std::string, XMLPortObjectContainer*>& getXMLPortObjectMap() const { return this->xmlportObjectContainers_; } 218 / ** @brief Returns a const_iterator to the beginning of the map that stores all XMLPort objects. @return The const_iterator */244 /// Returns a const_iterator to the beginning of the map that stores all XMLPort objects. 219 245 inline std::map<std::string, XMLPortObjectContainer*>::const_iterator getXMLPortObjectMapBegin() const { return this->xmlportObjectContainers_.begin(); } 220 / ** @brief Returns a const_iterator to the end of the map that stores all XMLPort objects. @return The const_iterator */246 /// Returns a const_iterator to the end of the map that stores all XMLPort objects. 221 247 inline std::map<std::string, XMLPortObjectContainer*>::const_iterator getXMLPortObjectMapEnd() const { return this->xmlportObjectContainers_.end(); } 222 248 … … 238 264 void initializeClassHierarchy(std::set<const Identifier*>* parents, bool bRootClass); 239 265 240 / ** @brief Returns the map that stores all Identifiers with their names. @return The map */266 /// Returns the map that stores all Identifiers with their names. 241 267 static std::map<std::string, Identifier*>& getStringIdentifierMapIntern(); 242 / ** @brief Returns the map that stores all Identifiers with their names in lowercase. @return The map */268 /// Returns the map that stores all Identifiers with their names in lowercase. 243 269 static std::map<std::string, Identifier*>& getLowercaseStringIdentifierMapIntern(); 244 / ** @brief Returns the map that stores all Identifiers with their network IDs. @return The map */270 /// Returns the map that stores all Identifiers with their network IDs. 245 271 static std::map<uint32_t, Identifier*>& getIDIdentifierMapIntern(); 246 272 247 / ** @brief Returns the children of the class the Identifier belongs to. @return The list of all children */273 /// Returns the children of the class the Identifier belongs to. 248 274 inline std::set<const Identifier*>& getChildrenIntern() const { return this->children_; } 249 / ** @brief Returns the direct children of the class the Identifier belongs to. @return The list of all direct children */275 /// Returns the direct children of the class the Identifier belongs to. 250 276 inline std::set<const Identifier*>& getDirectChildrenIntern() const { return this->directChildren_; } 251 277 … … 253 279 254 280 private: 255 / ** @brief Increases the hierarchyCreatingCounter_s variable, causing all new objects to store their parents. */281 /// Increases the hierarchyCreatingCounter_s variable, causing all new objects to store their parents. 256 282 inline static void startCreatingHierarchy() { hierarchyCreatingCounter_s++; } 257 / ** @brief Decreases the hierarchyCreatingCounter_s variable, causing the objects to stop storing their parents. */283 /// Decreases the hierarchyCreatingCounter_s variable, causing the objects to stop storing their parents. 258 284 inline static void stopCreatingHierarchy() { hierarchyCreatingCounter_s--; } 259 285 … … 291 317 // ### ClassIdentifier ### 292 318 // ############################### 293 //! The ClassIdentifier is derived from Identifier and holds all class-specific functions and variables the Identifier cannot have. 294 /** 295 ClassIdentifier is a Singleton, which means that only one object of a given type T exists. 319 /** 320 @brief The ClassIdentifier is derived from Identifier and holds all class-specific functions and variables the Identifier cannot have. 321 322 ClassIdentifier is a Singleton, which means that only one ClassIdentifier for a given type T exists. 296 323 This makes it possible to store information about a class, sharing them with all 297 324 objects of that class without defining static variables in every class. 298 325 299 326 To be really sure that not more than exactly one object exists (even with libraries), 300 ClassIdentifiers are stored in the Identifier Singleton.327 ClassIdentifiers are stored in a static map in Identifier. 301 328 */ 302 329 template <class T> 303 330 class ClassIdentifier : public Identifier 304 331 { 305 #define SUPER_INTRUSIVE_DECLARATION_INCLUDE 306 #include "Super.h" 332 #ifndef DOXYGEN_SHOULD_SKIP_THIS 333 #define SUPER_INTRUSIVE_DECLARATION_INCLUDE 334 #include "Super.h" 335 #endif 307 336 308 337 public: … … 387 416 @brief Adds an object of the given type to the ObjectList. 388 417 @param object The object to add 418 @param className The name of the class T 419 @param bRootClass True if this is a root class (i.e. it inherits directly from OrxonoxClass) 389 420 */ 390 421 template <class T> -
code/trunk/src/libraries/core/Iterator.h
r7271 r7401 29 29 /** 30 30 @file 31 @brief Definition and implementation of the Iterator class. 32 33 The Iterator of a given class allows to iterate through an ObjectList. Objects in 34 this list are cast to the template argument of the Iterator. 31 @ingroup Object ObjectList 32 @brief Definition of the Iterator class, used to iterate through object-lists. 33 34 @anchor IteratorExample 35 36 @ref orxonox::Iterator "Iterator" allows to iterate through an @ref orxonox::ObjectListBase 37 "ObjectListBase". Objects in this list are cast to the template argument @a T of Iterator<T> using 38 @c dynamic_cast. In contrast to @ref orxonox::ObjectListIterator "ObjectListIterator<T>", 39 @ref orxonox::Iterator "Iterator<T>" can iterate through every object-list. In practice though it 40 is limited to objects of type @a T and its subclasses. Because of the @c dynamic_cast, this iterator 41 is much slower than ObjectListIterator. 35 42 36 43 Usage: 44 @code 37 45 for (Iterator<myClass> it = anyidentifier->getObjects()->begin(); it != anyidentifier->getObjects()->end(); ++it) 38 46 { … … 40 48 myClass* myObject = *it; 41 49 } 50 @endcode 42 51 */ 43 52 … … 52 61 namespace orxonox 53 62 { 54 //! The Iterator allows to iterate through a given ObjectList 63 /** 64 @brief The Iterator allows to iterate through a given ObjectList. 65 66 Independent of the object-list's type, the objects in the list are always casted 67 to @a T using @c dynamic_cast. 68 69 @see See @ref IteratorExample "Iterator.h" for more information an example. 70 */ 55 71 template <class T = OrxonoxClass> 56 72 class Iterator … … 200 216 @return The Iterator itself 201 217 */ 202 inline Iterator<T> operator++(int i)218 inline Iterator<T> operator++(int) 203 219 { 204 220 Iterator<T> copy = *this; -
code/trunk/src/libraries/core/Language.cc
r7284 r7401 168 168 @brief Returns the localisation of a given entry. 169 169 @param label The label of the entry 170 @param bError If true, an error is printed if the label doesn't exist and the default localisation is returned. If false, no error is printed and an empty string is returned. 170 171 @return The localisation 171 172 */ -
code/trunk/src/libraries/core/Language.h
r7284 r7401 28 28 29 29 /** 30 @defgroup Language Language 31 @ingroup Core 32 */ 33 34 /** 30 35 @file 31 @brief Definition of the Language and the LanguageEntry class. 36 @ingroup Language 37 @brief Declaration of the Language and the LanguageEntry class, as well as some helper functions. 38 39 @anchor LanguageExample 32 40 33 41 The Language class is used, to get a localisation of a string in the configured language. … … 37 45 Usage: 38 46 - Set the entry with the default string: 47 @code 39 48 Language::getInstance()->addEntry("label of the entry", "the string to translate"); 49 @endcode 40 50 41 51 - Get the localisation of the entry in the configured language: 52 @code 42 53 std::cout << Language::getInstance()->getLocalisation("name of the entry") << std::endl; 54 @endcode 55 56 Example: 57 @code 58 int age = 20; 59 AddLanguageEntry("user_age", "Age"); 60 std::cout << GetLocalisation("user_age") << ": " << age << std::endl; 61 @endcode 62 63 Resulting output: 64 @code 65 Age: 20 66 @endcode 67 68 The language entry is now defined in @a translation_default.lang: 69 @code 70 user_age=Age 71 @endcode 72 73 We can add a translation for another language, for example @a translation_german.lang: 74 @code 75 user_age=Alter 76 @endcode 77 78 Now change the language in @a orxonox.ini to "german": 79 @code 80 language_ = "german" 81 @endcode 82 83 Now you will see the translated language entry in the resulting output of the above code: 84 @code 85 Alter: 20 86 @endcode 43 87 */ 44 88 … … 58 102 // ### LanguageEntry ### 59 103 // ############################### 60 //! The LanguageEntry class stores the default- and the translated string of a given entry in the language file. 104 /** 105 @brief The LanguageEntry class stores the default- and the translated string of a given entry in the language file. 106 107 This class belongs to the Language class. 108 */ 61 109 class _CoreExport LanguageEntry 62 110 { … … 105 153 // ### Language ### 106 154 // ############################### 107 //! The Language class manges the language files and entries and stores the LanguageEntry objects in a map. 155 /** 156 @brief The Language class manges the language files and entries and stores the LanguageEntry objects in a map. 157 158 @see See @ref LanguageExample "Language.h" for some examples. 159 */ 108 160 class _CoreExport Language : public Singleton<Language> 109 161 { … … 134 186 }; 135 187 136 // !Shortcut function for Language::addEntry188 /// Shortcut function for Language::addEntry 137 189 inline void AddLanguageEntry(const LanguageEntryLabel& label, const std::string& fallbackString) 138 190 { … … 140 192 } 141 193 142 // !Shortcut function for Language::getLocalisation194 /// Shortcut function for Language::getLocalisation 143 195 inline const std::string& GetLocalisation(const LanguageEntryLabel& label) 144 196 { … … 146 198 } 147 199 148 // !Shortcut function for Language::getLocalisation without printing an error in case the label doesn't exist200 /// Shortcut function for Language::getLocalisation without printing an error in case the label doesn't exist 149 201 inline const std::string& GetLocalisation_noerror(const LanguageEntryLabel& label) 150 202 { -
code/trunk/src/libraries/core/Loader.h
r5781 r7401 26 26 * 27 27 */ 28 29 /** 30 @defgroup Loader Loader 31 @ingroup XML 32 */ 33 34 /** 35 @file 36 @ingroup XML Loader 37 */ 28 38 29 39 #ifndef _Loader_H__ -
code/trunk/src/libraries/core/LuaState.h
r7284 r7401 27 27 * 28 28 */ 29 30 /** 31 @defgroup Lua Lua 32 @ingroup Core 33 */ 34 35 /** 36 @file 37 @ingroup Lua 38 */ 29 39 30 40 #ifndef _LuaState_H__ -
code/trunk/src/libraries/core/MemoryArchive.cc
r6417 r7401 54 54 } 55 55 56 DataStreamPtr MemoryArchive::open(const String& filename) const56 DataStreamPtr MemoryArchive::open(const Ogre::String& filename) const 57 57 { 58 58 const FileMap& files = archives_s[this->getName()]; … … 64 64 } 65 65 66 void MemoryArchive::findFiles(const String& pattern, bool bRecursive,67 bool bDirs, StringVector* simpleList,FileInfoList* detailList)66 void MemoryArchive::findFiles(const Ogre::String& pattern, bool bRecursive, 67 bool bDirs, Ogre::StringVector* simpleList, Ogre::FileInfoList* detailList) 68 68 { 69 69 const FileMap& files = archives_s[this->getName()]; … … 110 110 } 111 111 112 StringVectorPtr MemoryArchive::find(const String& pattern,112 StringVectorPtr MemoryArchive::find(const Ogre::String& pattern, 113 113 bool recursive, bool dirs) 114 114 { … … 118 118 } 119 119 120 FileInfoListPtr MemoryArchive::findFileInfo(const String& pattern,120 FileInfoListPtr MemoryArchive::findFileInfo(const Ogre::String& pattern, 121 121 bool recursive, bool dirs) 122 122 { … … 126 126 } 127 127 128 bool MemoryArchive::exists(const String& filename)128 bool MemoryArchive::exists(const Ogre::String& filename) 129 129 { 130 130 const FileMap& files = archives_s[this->getName()]; -
code/trunk/src/libraries/core/MemoryArchive.h
r6417 r7401 26 26 * 27 27 */ 28 29 /** 30 @file 31 @ingroup Management Resources 32 */ 28 33 29 34 #ifndef _MemoryArchive_H__ -
code/trunk/src/libraries/core/MetaObjectList.h
r5738 r7401 29 29 /** 30 30 @file 31 @brief Definition of the MetaObjectList class. 31 @ingroup Object ObjectList 32 @brief Declaration of the MetaObjectList class. 32 33 33 34 The MetaObjectList is a single-linked list, containing all list-elements and their … … 46 47 // ### MetaObjectListElement ### 47 48 // ############################### 48 // !The list-element of the MetaObjectList49 /// The list-element of the MetaObjectList 49 50 class _CoreExport MetaObjectListElement 50 51 { … … 65 66 // ### MetaObjectList ### 66 67 // ############################### 67 //! The MetaObjectList contains ObjectListBaseElements and their ObjectListBases.68 68 /** 69 @brief The MetaObjectList contains ObjectListBaseElements and their ObjectListBases. 70 69 71 The MetaObjectList is a single-linked list, containing all list-elements and their 70 72 lists wherein the object that owns the MetaObjectList is registered. -
code/trunk/src/libraries/core/Namespace.cc
r6417 r7401 55 55 } 56 56 57 /**58 @brief XML loading and saving.59 @param xmlelement The XML-element60 @param loading Loading (true) or saving (false)61 @return The XML-element62 */63 57 void Namespace::XMLPort(Element& xmlelement, XMLPort::Mode mode) 64 58 { -
code/trunk/src/libraries/core/Namespace.h
r5781 r7401 26 26 * 27 27 */ 28 29 /** 30 @file 31 @ingroup XML Loader 32 */ 28 33 29 34 #ifndef _Namespace_H__ -
code/trunk/src/libraries/core/NamespaceNode.h
r5781 r7401 26 26 * 27 27 */ 28 29 /** 30 @file 31 @ingroup XML Loader 32 */ 28 33 29 34 #ifndef _NamespaceNode_H__ -
code/trunk/src/libraries/core/ObjectList.h
r7278 r7401 28 28 29 29 /** 30 @defgroup ObjectList Object-lists and iterators 31 @ingroup Object 32 */ 33 34 /** 30 35 @file 31 @brief Definition and implementation of the ObjectList class. 36 @ingroup Object ObjectList 37 @brief Definition of the ObjectList class, a wrapper of ObjectListBase. 32 38 33 The ObjectList is a wrapper of an ObjectListBase of a given class. 34 Use Iterator<class> to iterate through all objects of the class. 39 @ref orxonox::ObjectList "ObjectList<T>" is a wrapper of an @ref orxonox::ObjectListBase 40 "ObjectListBase" of class @a T. Use @ref orxonox::ObjectListIterator "ObjectListIterator<T>" 41 to iterate through the list. 35 42 */ 36 43 … … 49 56 // ### ObjectList ### 50 57 // ############################### 51 //! The ObjectList contains all objects of the given class.52 58 /** 53 Wraps the ObjectListBase of the corresponding Identifier. 54 Use ObjectListIterator<class> to iterate through all objects in the list. 59 @brief The ObjectList contains all objects of the given class. 60 61 Wraps the ObjectListBase which contains all objects of type @a T. Use @ref ObjectListIterator 62 "ObjectListIterator<T>" or its typedef ObjectList<T>::iterator to iterate through all objects 63 in the list. 55 64 */ 56 65 template <class T> … … 60 69 typedef ObjectListIterator<T> iterator; 61 70 62 / ** @brief Returns an Iterator to the first element in the list. @return The Iterator */71 /// Returns an Iterator to the first element in the list. 63 72 inline static ObjectListElement<T>* begin() 64 73 { … … 67 76 } 68 77 69 / ** @brief Returns an Iterator to the element after the last element in the list. @return The Iterator */78 /// Returns an Iterator to the element after the last element in the list. 70 79 inline static ObjectListElement<T>* end() 71 80 { … … 74 83 } 75 84 76 / ** @brief Returns an Iterator to the last element in the list. @return The Iterator */85 /// Returns an Iterator to the last element in the list. 77 86 inline static ObjectListElement<T>* rbegin() 78 87 { … … 81 90 } 82 91 83 / ** @brief Returns an Iterator to the element before the first element in the list. @return The Iterator */92 /// Returns an Iterator to the element before the first element in the list. 84 93 inline static ObjectListElement<T>* rend() 85 94 { -
code/trunk/src/libraries/core/ObjectListBase.cc
r5738 r7401 30 30 @file 31 31 @brief Implementation of the ObjectListBase class. 32 33 The ObjectListBase is a double-linked list, used by Identifiers to store all objects of a given class.34 Newly created objects are added through the RegisterObject-macro in its constructor.35 32 */ 36 33 … … 70 67 /** 71 68 @brief Increases all Iterators that currently point on the given element (because it gets removed). 72 @param element The element that gets removed69 @param object The object that gets removed 73 70 */ 74 71 void ObjectListBase::notifyIterators(OrxonoxClass* object) const … … 82 79 /** 83 80 @brief Adds a new object to the end of the list. 84 @param object The object to add81 @param element The element to add 85 82 @return The pointer to the new ObjectListBaseElement, needed by the MetaObjectList of the added object 86 83 */ -
code/trunk/src/libraries/core/ObjectListBase.h
r5738 r7401 29 29 /** 30 30 @file 31 @brief Definition of the ObjectListBase class. 31 @ingroup Object ObjectList 32 @brief Declaration of the ObjectListBase class which stores all objects of each class. 32 33 33 The ObjectListBase is a double-linked list, used by Identifiers to store all objects of a given class. 34 Newly created objects are added through the RegisterObject-macro in its constructor. 34 orxonox::ObjectListBase is a double-linked list, used by @ref orxonox::Identifier "Identifiers" 35 to store all objects of a given class. Newly created objects are added to the list through the 36 @c RegisterObject() macro in the constructor. 35 37 */ 36 38 … … 48 50 // ### ObjectListBaseElement ### 49 51 // ############################### 50 // !The list-element of the ObjectListBase52 /// The list-element of the ObjectListBase 51 53 class _CoreExport ObjectListBaseElement 52 54 { … … 54 56 /** 55 57 @brief Constructor: Creates the list-element with an object. 56 @param object The object to store58 @param objectBase The object to store 57 59 */ 58 60 ObjectListBaseElement(OrxonoxClass* objectBase) : next_(0), prev_(0), objectBase_(objectBase) {} … … 67 69 // ### ObjectListElement ### 68 70 // ############################### 69 // !The list-element that actually contains the object71 /// The list-element that actually contains the object 70 72 template <class T> 71 73 class ObjectListElement : public ObjectListBaseElement … … 80 82 // ### ObjectListBase ### 81 83 // ############################### 82 //! The ObjectListBase contains all objects of a given class.83 84 /** 84 The ObjectListBase is used by Identifiers to store all objects of their given class. 85 Use ObjectList<T> to get the list of all T's and Iterator<T> to iterate through them. 85 @brief The ObjectListBase contains all objects of a given class. 86 87 The ObjectListBase is used by Identifiers to store all objects of their class. 88 You can use Identifier::getObjects() to get the object-list from an Identifier. 89 Use @ref Iterator "Iterator<T>" to iterate through them. 90 91 Alternatively you can also use the static helper class @ref orxonox::ObjectList "ObjectList<T>" 92 to get the list of all objects of type @a T. Use @ref ObjectListIterator "ObjectListIterator<T>" 93 or @ref Iterator "Iterator<T>" to iterate through them. 86 94 */ 87 95 class _CoreExport ObjectListBase … … 95 103 ObjectListBaseElement* add(ObjectListBaseElement* element); 96 104 105 /// Helper struct, used to export an element and the list to an instance of Iterator. 97 106 struct Export 98 107 { … … 102 111 }; 103 112 104 / ** @brief Returns a pointer to the first element in the list. @return The element */113 /// Returns a pointer to the first element in the list. Works only with Iterator. 105 114 inline Export begin() { return ObjectListBase::Export(this, this->first_); } 106 / ** @brief Returns a pointer to the element after the last element in the list. @return The element */115 /// Returns a pointer to the element after the last element in the list. Works only with Iterator. 107 116 inline Export end() { return ObjectListBase::Export(this, 0); } 108 / ** @brief Returns a pointer to the last element in the list. @return The element */117 /// Returns a pointer to the last element in the list. Works only with Iterator. 109 118 inline Export rbegin() { return ObjectListBase::Export(this, this->last_); } 110 / ** @brief Returns a pointer to the element in front of the first element in the list. @return The element */119 /// Returns a pointer to the element in front of the first element in the list. Works only with Iterator. 111 120 inline Export rend() { return ObjectListBase::Export(this, 0); } 112 121 -
code/trunk/src/libraries/core/ObjectListIterator.h
r7268 r7401 29 29 /** 30 30 @file 31 @brief Definition and implementation of the Iterator class. 32 33 The ObjectListIterator of a given class allows to iterate through the 34 ObjectList of this class, containing all objects of that type. 35 This is the only way to access the objects stored in an ObjectList. 31 @ingroup Object ObjectList 32 @brief Definition of the ObjectListIterator class, used to iterate through object-lists. 33 34 @anchor ObjectListIteratorExample 35 36 @ref orxonox::ObjectListIterator "ObjectListIterator<T>" allows to iterate through 37 @ref orxonox::ObjectList "ObjectList<T>", containing all objects of type @a T. In contrast to 38 @ref orxonox::Iterator "Iterator<T>", this iterator is limited to the object-list of type @a T. 39 It is, however, much faster as it doesn't need a @c dynamic_cast. 36 40 37 41 Usage: 42 @code 38 43 for (ObjectListIterator<myClass> it = ObjectList<myClass>::begin(); it != ObjectList<myClass>::end(); ++it) 39 44 { … … 41 46 myClass* myObject = *it; 42 47 } 48 @endcode 49 50 @note @ref orxonox::ObjectList::iterator "ObjectList<T>::iterator" is identical to 51 @ref orxonox::ObjectListIterator "ObjectListIterator<T>" (it's just a typedef). 43 52 */ 44 53 … … 52 61 namespace orxonox 53 62 { 54 //! The Iterator allows to iterate through the ObjectList of a given class. 63 /** 64 @brief ObjectListIterator<T> allows to iterate through the ObjectList of class @a T. 65 66 @see See @ref ObjectListIteratorExample "ObjectListIterator.h" for more information an example. 67 */ 55 68 template <class T> 56 69 class ObjectListIterator … … 109 122 /** 110 123 @brief Assigns the element of another ObjectListIterator. 111 @param elementThe other ObjectListIterator124 @param other The other ObjectListIterator 112 125 */ 113 126 inline ObjectListIterator<T>& operator=(const ObjectListIterator<T>& other) … … 131 144 @return The ObjectListIterator itself 132 145 */ 133 inline ObjectListIterator<T> operator++(int i)146 inline ObjectListIterator<T> operator++(int) 134 147 { 135 148 ObjectListIterator<T> copy = *this; … … 217 230 218 231 private: 219 ObjectListElement<T>* element_; //!< The element the Iterator points at232 ObjectListElement<T>* element_; //!< The element the iterator points at 220 233 }; 221 234 } -
code/trunk/src/libraries/core/OrxonoxClass.cc
r6417 r7401 29 29 /** 30 30 @file 31 @brief Implementation of the OrxonoxClassClass.31 @brief Implementation of OrxonoxClass. 32 32 */ 33 33 … … 41 41 namespace orxonox 42 42 { 43 /** @brief Constructor: Sets the default values. */ 43 /** 44 @brief Constructor: Sets the default values. 45 */ 44 46 OrxonoxClass::OrxonoxClass() 45 47 { … … 53 55 } 54 56 55 /** @brief Destructor: Deletes, if existing, the list of the parents. */ 57 /** 58 @brief Destructor: Removes the object from the object-lists, notifies all @ref WeakPtr "weak pointers" that this object is being deleted. 59 */ 56 60 OrxonoxClass::~OrxonoxClass() 57 61 { … … 72 76 } 73 77 74 /** @brief Deletes the object if no smart pointers point to this object. Otherwise schedules the object to be deleted as soon as possible. */ 78 /** 79 @brief Deletes the object if no @ref orxonox::SmartPtr "smart pointers" point to this object. Otherwise schedules the object to be deleted as soon as possible. 80 */ 75 81 void OrxonoxClass::destroy() 76 82 { … … 85 91 } 86 92 93 /** 94 @brief Removes this object from the object-lists. 95 */ 87 96 void OrxonoxClass::unregisterObject() 88 97 { … … 92 101 } 93 102 94 / ** @brief Returns true if the objects class is of the given type or a derivative. */103 /// Returns true if the object's class is of the given type or a derivative. 95 104 bool OrxonoxClass::isA(const Identifier* identifier) 96 105 { return this->getIdentifier()->isA(identifier); } 97 / ** @brief Returns true if the objects class is exactly of the given type. */106 /// Returns true if the object's class is exactly of the given type. 98 107 bool OrxonoxClass::isExactlyA(const Identifier* identifier) 99 108 { return this->getIdentifier()->isExactlyA(identifier); } 100 / ** @brief Returns true if the objects class is a child of the given type. */109 /// Returns true if the object's class is a child of the given type. 101 110 bool OrxonoxClass::isChildOf(const Identifier* identifier) 102 111 { return this->getIdentifier()->isChildOf(identifier); } 103 / ** @brief Returns true if the objects class is a direct child of the given type. */112 /// Returns true if the object's class is a direct child of the given type. 104 113 bool OrxonoxClass::isDirectChildOf(const Identifier* identifier) 105 114 { return this->getIdentifier()->isDirectChildOf(identifier); } 106 / ** @brief Returns true if the objects class is a parent of the given type. */115 /// Returns true if the object's class is a parent of the given type. 107 116 bool OrxonoxClass::isParentOf(const Identifier* identifier) 108 117 { return this->getIdentifier()->isParentOf(identifier); } 109 / ** @brief Returns true if the objects class is a direct parent of the given type. */118 /// Returns true if the object's class is a direct parent of the given type. 110 119 bool OrxonoxClass::isDirectParentOf(const Identifier* identifier) 111 120 { return this->getIdentifier()->isDirectParentOf(identifier); } 112 121 113 122 114 / ** @brief Returns true if the objects class is of the given type or a derivative. */123 /// Returns true if the object's class is of the given type or a derivative. 115 124 bool OrxonoxClass::isA(const OrxonoxClass* object) 116 125 { return this->getIdentifier()->isA(object->getIdentifier()); } 117 / ** @brief Returns true if the objects class is exactly of the given type. */126 /// Returns true if the object's class is exactly of the given type. 118 127 bool OrxonoxClass::isExactlyA(const OrxonoxClass* object) 119 128 { return this->getIdentifier()->isExactlyA(object->getIdentifier()); } 120 / ** @brief Returns true if the objects class is a child of the given type. */129 /// Returns true if the object's class is a child of the given type. 121 130 bool OrxonoxClass::isChildOf(const OrxonoxClass* object) 122 131 { return this->getIdentifier()->isChildOf(object->getIdentifier()); } 123 / ** @brief Returns true if the objects class is a direct child of the given type. */132 /// Returns true if the object's class is a direct child of the given type. 124 133 bool OrxonoxClass::isDirectChildOf(const OrxonoxClass* object) 125 134 { return this->getIdentifier()->isDirectChildOf(object->getIdentifier()); } 126 / ** @brief Returns true if the objects class is a parent of the given type. */135 /// Returns true if the object's class is a parent of the given type. 127 136 bool OrxonoxClass::isParentOf(const OrxonoxClass* object) 128 137 { return this->getIdentifier()->isParentOf(object->getIdentifier()); } 129 / ** @brief Returns true if the objects class is a direct child of the given type. */138 /// Returns true if the object's class is a direct child of the given type. 130 139 bool OrxonoxClass::isDirectParentOf(const OrxonoxClass* object) 131 140 { return this->getIdentifier()->isDirectParentOf(object->getIdentifier()); } -
code/trunk/src/libraries/core/OrxonoxClass.h
r7163 r7401 28 28 29 29 /** 30 @defgroup OrxonoxClass OrxonoxClass 31 @ingroup Class 32 */ 33 34 /** 30 35 @file 31 @brief Declaration of the OrxonoxClass Class. 36 @ingroup Class OrxonoxClass 37 @brief Declaration of OrxonoxClass, the base class of all objects and interfaces in Orxonox. 32 38 33 39 All objects and interfaces of the game-logic (not the engine) are derived from OrxonoxClass. … … 53 59 namespace orxonox 54 60 { 55 //! The class all objects and interfaces of the game-logic (not the engine) are derived from.56 61 /** 57 The BaseObject and Interfaces are derived with 'virtual public OrxonoxClass' from OrxonoxClass. 58 OrxonoxClass is needed to create the class-hierarchy at startup and to store the Identifier and the MetaObjectList. 62 @brief The class all objects and interfaces of the game-logic (not the engine) are derived from. 63 64 The BaseObject and Interfaces are derived with @c virtual @c public @c OrxonoxClass from OrxonoxClass. 65 OrxonoxClass is needed to create the class-hierarchy at startup and to store the Identifier and the 66 MetaObjectList, as well as to provide an interface for SmartPtr and WeakPtr. 59 67 */ 60 68 class _CoreExport OrxonoxClass … … 76 84 void unregisterObject(); 77 85 78 / ** @brief Function to collect the SetConfigValue-macro calls. */86 /// Function to collect the SetConfigValue-macro calls. 79 87 void setConfigValues() {}; 80 88 81 / ** @brief Returns the Identifier of the object. @return The Identifier */89 /// Returns the Identifier of the object. 82 90 inline Identifier* getIdentifier() const { return this->identifier_; } 83 91 … … 89 97 bool isDirectParentOf(const Identifier* identifier); 90 98 99 /// Returns true if the object's class is of the given type or a derivative. 91 100 template <class B> inline bool isA(const SubclassIdentifier<B>* identifier) 92 101 { return this->isA(*identifier); } 102 /// Returns true if the object's class is exactly of the given type. 93 103 template <class B> inline bool isExactlyA(const SubclassIdentifier<B>* identifier) 94 104 { return this->isExactlyA(*identifier); } 105 /// Returns true if the object's class is a child of the given type. 95 106 template <class B> inline bool isChildOf(const SubclassIdentifier<B>* identifier) 96 107 { return this->isChildOf(*identifier); } 108 /// Returns true if the object's class is a direct child of the given type. 97 109 template <class B> inline bool isDirectChildOf(const SubclassIdentifier<B>* identifier) 98 110 { return this->isDirectChildOf(*identifier); } 111 /// Returns true if the object's class is a parent of the given type. 99 112 template <class B> inline bool isParentOf(const SubclassIdentifier<B>* identifier) 100 113 { return this->isParentOf(*identifier); } 114 /// Returns true if the object's class is a direct parent of the given type. 101 115 template <class B> inline bool isDirectParentOf(const SubclassIdentifier<B>* identifier) 102 116 { return this->isDirectParentOf(*identifier); } … … 111 125 virtual void clone(OrxonoxClass*& item) {} 112 126 127 /// Returns the number of @ref orxonox::SmartPtr "smart pointers" that point to this object. 113 128 inline unsigned int getReferenceCount() const 114 129 { return this->referenceCount_; } … … 131 146 } 132 147 133 // !Version of getDerivedPointer with template148 /// Version of getDerivedPointer with template 134 149 template <class T> FORCEINLINE T* getDerivedPointer(unsigned int classID) 135 150 { return static_cast<T*>(this->getDerivedPointer(classID)); } 136 // !Const version of getDerivedPointer with template151 /// Const version of getDerivedPointer with template 137 152 template <class T> FORCEINLINE const T* getDerivedPointer(unsigned int classID) const 138 153 { return const_cast<OrxonoxClass*>(this)->getDerivedPointer<T>(classID); } 139 154 140 155 protected: 156 /// This virtual function is called if destroy() is called and no SmartPtr points to this object. Used in some cases to create a new SmartPtr to prevent destruction. 141 157 virtual void preDestroy() {} 142 158 143 159 private: 144 / ** @brief Increments the reference counter (for smart pointers). */160 /// Increments the reference counter (for smart pointers). 145 161 inline void incrementReferenceCount() 146 162 { ++this->referenceCount_; } 147 / ** @brief Decrements the reference counter (for smart pointers). */163 /// Decrements the reference counter (for smart pointers). 148 164 inline void decrementReferenceCount() 149 165 { … … 153 169 } 154 170 155 / ** @brief Register a weak pointer which points to this object. */171 /// Register a weak pointer which points to this object. 156 172 template <class T> 157 173 inline void registerWeakPtr(WeakPtr<T>* pointer) 158 174 { this->weakPointers_.insert(reinterpret_cast<WeakPtr<OrxonoxClass>*>(pointer)); } 159 / ** @brief Unegister a weak pointer which pointed to this object before. */175 /// Unegister a weak pointer which pointed to this object before. 160 176 template <class T> 161 177 inline void unregisterWeakPtr(WeakPtr<T>* pointer) 162 178 { this->weakPointers_.erase(reinterpret_cast<WeakPtr<OrxonoxClass>*>(pointer)); } 163 179 164 Identifier* identifier_; //!< The Identifier of the object165 std::set<const Identifier*>* parents_; //!< List of all parents of the object166 MetaObjectList* metaList_; //!< MetaObjectList, containing all ObjectLists and ObjectListElements the object is registered in167 int referenceCount_; //!< Counts the references from smart pointers to this object168 bool requestedDestruction_; //!< Becomes true after someone called delete on this object169 std::set<WeakPtr<OrxonoxClass>*> weakPointers_; //!< All weak pointers which point to this object (and like to get notified if it dies)180 Identifier* identifier_; //!< The Identifier of the object 181 std::set<const Identifier*>* parents_; //!< List of all parents of the object 182 MetaObjectList* metaList_; //!< MetaObjectList, containing all ObjectLists and ObjectListElements the object is registered in 183 int referenceCount_; //!< Counts the references from smart pointers to this object 184 bool requestedDestruction_; //!< Becomes true after someone called delete on this object 185 std::set<WeakPtr<OrxonoxClass>*> weakPointers_; //!< All weak pointers which point to this object (and like to get notified if it dies) 170 186 171 // !'Fast map' that holds this-pointers of all derived types187 /// 'Fast map' that holds this-pointers of all derived types 172 188 std::vector<std::pair<unsigned int, void*> > objectPointers_; 173 189 }; -
code/trunk/src/libraries/core/PathConfig.h
r6417 r7401 26 26 * 27 27 */ 28 29 /** 30 @file 31 @ingroup Management Resources 32 */ 28 33 29 34 #ifndef _PathConfig_H__ -
code/trunk/src/libraries/core/Resource.h
r6746 r7401 26 26 * 27 27 */ 28 29 /** 30 @defgroup Resources Resources 31 @ingroup Management 32 */ 33 34 /** 35 @file 36 @ingroup Management Resources 37 */ 28 38 29 39 #ifndef _Core_Resource_H__ … … 105 115 /** 106 116 Find out if the named file exists. 107 @param filename117 @param name 108 118 Fully qualified name of the file to test for 109 119 */ … … 112 122 /** 113 123 Get struct with information about path and size. 114 @param filename124 @param name 115 125 Fully qualified name of the file to test for 116 126 */ -
code/trunk/src/libraries/core/SmartPtr.h
r7268 r7401 29 29 // Inspired by boost::intrusive_ptr by Peter Dimov 30 30 31 /** 32 @defgroup SmartPtr SmartPtr<T> and WeakPtr<T> 33 @ingroup Object 34 */ 35 36 /** 37 @file 38 @ingroup Object SmartPtr 39 @brief Definition of SmartPtr<T>, wraps a pointer to an object and keeps it alive. 40 41 @anchor SmartPtrExample 42 43 orxonox::SmartPtr is an implementation of a smart pointer - it wraps a pointer to an 44 object and keeps this object alive until no SmartPtr points to this object anymore. 45 In contrast to orxonox::SharedPtr, SmartPtr works only with classes that are derived 46 from orxonox::OrxonoxClass, because it's an intrusive implementation, meaning the 47 reference counter is stored in the object itself. 48 49 It's possible to use normal pointers and smart pointers to an object simultaneously. 50 You don't have to use SmartPtr all the time, you can create a SmartPtr for an object 51 at any time and also convert it back to a normal pointer if you like. This is possible 52 because the reference counter is stored in the object itself and not in SmartPtr (in 53 contrast to SharedPtr). 54 55 @b Important: If you want to delete an object, you must not use @c delete @c object but 56 rather @c object->destroy(). This function will check if there are smart pointers 57 pointing to the object. If yes, the object will be kept alive until all smart pointes 58 are destroyed. If no, the object is deleted instantly. 59 60 If all smart pointers that point to an object are destroyed, but you never called 61 @c object->destroy() before, the object will not be deleted! All a SmartPtr will do 62 is to really just keep an object alive, but it will not delete it automatically 63 unless you tried to destroy it before. 64 65 Example: 66 @code 67 class MyClass // class declaration 68 { 69 public: 70 void setObject(OtherClass* object) // passes a normal pointer which will be stored in a SmartPtr 71 { this->object_ = object; } 72 73 OtherClass* getObject() const // converts the SmartPtr to a normal pointer and returns it 74 { return this->object_; } 75 76 private: 77 SmartPtr<OtherClass> object_; // a pointer to an instance of OtherClass is stored in a SmartPtr 78 }; 79 @endcode 80 In this example we assume that OtherClass is a child of OrxonoxClass. We don't care 81 about the inheritance of MyClass though. 82 83 Now we create an instance of MyClass and assign a pointer to an instance of OtherClass: 84 @code 85 MyClass* myclass = new MyClass(); // create an instance of MyClass 86 OtherClass* object = new OtherClass(); // create an instance of OtherClass 87 myclass->setObject(object); // the object is now stored in a SmartPtr inside myclass 88 89 object->destroy(); // we try to destroy object, but there's still a SmartPtr pointing at it. 90 91 # object still exists at this point (because a SmartPtr points at it) 92 93 delete myclass; // now we delete myclass, which also destroys the SmartPtr 94 95 # object doesn't exist anymore (because the SmartPtr is now destroyed) 96 @endcode 97 98 Now we look at the same example, but we first delete myclass, then destroy object: 99 @code 100 MyClass* myclass = new MyClass(); // create an instance of MyClass 101 OtherClass* object = new OtherClass(); // create an instance of OtherClass 102 myclass->setObject(object); // the object is now stored in a SmartPtr inside myclass 103 104 delete myclass; // we delete myclass, which also destroys the SmartPtr 105 106 # object still exists at this point (because destroy() was not called yet) 107 108 object->destroy(); // now we try to destroy object, which works instantly 109 110 # object doesn't exist anymore (because we just destroyed it) 111 @endcode 112 113 Note that in any case @c object->destroy() has to be called to delete the object. 114 However if a SmartPtr points at it, the destruction is delayed until all SmartPtr 115 are destroyed. 116 */ 117 31 118 #ifndef _SmartPtr_H__ 32 119 #define _SmartPtr_H__ … … 42 129 namespace orxonox 43 130 { 131 /** 132 @brief A smart pointer which wraps a pointer to an object and keeps this object alive as long as the smart pointer exists. 133 134 @see See @ref SmartPtrExample "this description" for more information and an example. 135 */ 44 136 template <class T> 45 137 class SmartPtr 46 138 { 47 139 public: 140 /// Constructor: Initializes the smart pointer with a null pointer. 48 141 inline SmartPtr() : pointer_(0), base_(0) 49 142 { 50 143 } 51 144 145 /// Constructor: Used to explicitly initialize the smart pointer with a null pointer 52 146 inline SmartPtr(int) : pointer_(0), base_(0) 53 147 { 54 148 } 55 149 150 /// Constructor: Initializes the smart pointer with a pointer to an object. @param pointer The pointer @param bAddRef If true, the reference counter is increased. Don't set this to false unless you know exactly what you're doing! (for example to avoid circular references if the @c this pointer of the possessing object is stored) 56 151 inline SmartPtr(T* pointer, bool bAddRef = true) : pointer_(pointer), base_(pointer) 57 152 { … … 60 155 } 61 156 157 /// Copy-constructor 62 158 inline SmartPtr(const SmartPtr& other) : pointer_(other.pointer_), base_(other.base_) 63 159 { … … 66 162 } 67 163 164 /// Copy-constructor for smart pointers to objects of another class. 68 165 template <class O> 69 166 inline SmartPtr(const SmartPtr<O>& other) : pointer_(other.get()), base_(other.base_) … … 73 170 } 74 171 172 /// Constructor: Initializes the smart pointer with the pointer that is stored in a WeakPtr. 75 173 template <class O> 76 174 inline SmartPtr(const WeakPtr<O>& other) : pointer_(other.get()), base_(other.getBase()) … … 80 178 } 81 179 180 /// Destructor: Decrements the reference counter. 82 181 inline ~SmartPtr() 83 182 { … … 86 185 } 87 186 187 /// Used to assign a null pointer. 88 188 inline SmartPtr& operator=(int) 89 189 { … … 92 192 } 93 193 194 /// Assigns a new pointer. 94 195 inline SmartPtr& operator=(T* pointer) 95 196 { … … 98 199 } 99 200 201 /// Assigns the wrapped pointer of another SmartPtr. 100 202 inline SmartPtr& operator=(const SmartPtr& other) 101 203 { … … 104 206 } 105 207 208 /// Assigns the wrapped pointer of a SmartPtr of another class 106 209 template <class O> 107 210 inline SmartPtr& operator=(const SmartPtr<O>& other) … … 111 214 } 112 215 216 /// Assigns the wrapped pointer of a WeakPtr. 113 217 template <class O> 114 218 inline SmartPtr& operator=(const WeakPtr<O>& other) … … 118 222 } 119 223 224 /// Returns the wrapped pointer as @c T* 120 225 inline T* get() const 121 226 { … … 123 228 } 124 229 230 /// Returns the wrapped pointer as @c OrxonoxClass* 125 231 inline OrxonoxClass* getBase() const 126 232 { … … 128 234 } 129 235 236 /// Implicitly converts the SmartPtr to a pointer of type @c T* 130 237 inline operator T*() const 131 238 { … … 133 240 } 134 241 242 /// Overloaded operator, returns a pointer to the stored object. 135 243 inline T* operator->() const 136 244 { … … 139 247 } 140 248 249 /// Overloaded operator, returns a reference to the stored object. 141 250 inline T& operator*() const 142 251 { … … 145 254 } 146 255 256 /// Returns true if the wrapped pointer is NULL. 147 257 inline bool operator!() const 148 258 { … … 150 260 } 151 261 262 /// Swaps the contents of two smart pointers. 152 263 inline void swap(SmartPtr& other) 153 264 { … … 164 275 } 165 276 277 /// Resets the smart pointer (equivalent to assigning a NULL pointer). 166 278 inline void reset() 167 279 { … … 170 282 171 283 private: 172 T* pointer_; 173 OrxonoxClass* base_; 284 T* pointer_; ///< The wrapped pointer to an object of type @a T 285 OrxonoxClass* base_; ///< The wrapped pointer, casted up to OrxonoxClass (this is needed because with just a T* pointer, SmartPtr couln't be used with forward declarations) 174 286 }; 175 287 288 /// Swaps the contents of two smart pointers. 176 289 template <class T> 177 290 void swap(SmartPtr<T>& a, SmartPtr<T>& b) … … 180 293 } 181 294 295 /// Uses a static_cast to cast a pointer of type U* to a pointer of type T* and returns it in a new SmartPtr<T>. 182 296 template <class T, class U> 183 297 SmartPtr<T> static_pointer_cast(const SmartPtr<U>& p) … … 186 300 } 187 301 302 /// Uses a const_cast to cast a pointer of type U* to a pointer of type T* and returns it in a new SmartPtr<T>. 188 303 template <class T, class U> 189 304 SmartPtr<T> const_pointer_cast(const SmartPtr<U>& p) … … 192 307 } 193 308 309 /// Uses a dynamic_cast to cast a pointer of type U* to a pointer of type T* and returns it in a new SmartPtr<T>. 194 310 template <class T, class U> 195 311 SmartPtr<T> dynamic_pointer_cast(const SmartPtr<U>& p) -
code/trunk/src/libraries/core/SubclassIdentifier.h
r7268 r7401 29 29 /** 30 30 @file 31 @ingroup Class Identifier 31 32 @brief Definition of SubclassIdentifier. 33 34 @anchor SubclassIdentifierExample 32 35 33 36 SubclassIdentifier is a separated class, acting like an Identifier, but has a given class. 34 37 You can only assign Identifiers of exactly the given class or of a derivative to a SubclassIdentifier. 38 39 Example: 40 41 You can assign an Identifier either through the constructor or by using the assignment @c operator=: 42 @code 43 SubclassIdentifier<BaseClass> identifier = Class(SubClass); 44 @endcode 45 46 The @c operator-> is overloaded an returns the assigned Identifier. That way you can just call 47 functions of the assigned Identifier by using @c ->function(): 48 @code 49 SubclassIdentifier<BaseClass> identifier = Class(SubClass); 50 identifier->getName(); // returns "SubClass" 51 @endcode 52 53 There are two possibilities to create an object out of a SubclassIdentifier: Either you just use 54 the @c fabricate() function of the assigned Identifier through the overloaded @c operator->, which 55 returns a @c BaseObject* pointer, or you use the function of SubclassIdentifier, this time by using 56 @c operator., which returns a @c BaseClass* pointer (@a BaseClass is the baseclass specified by the 57 template argument): 58 @code 59 identifier->fabricate(); // calls Identifier::fabricate(), creates a SubClass, returns a BaseObject* pointer 60 61 identifier.fabricate(); // calls SubclassIdentifier::fabricate(), creates a SubClass, returns a BaseClass* pointer 62 @endcode 35 63 */ 36 64 … … 49 77 // ### SubclassIdentifier ### 50 78 // ############################### 51 //! The SubclassIdentifier acts almost like an Identifier, but has some prerequisites.52 79 /** 80 @brief The SubclassIdentifier acts almost like an Identifier, but has some prerequisites. 81 53 82 You can only assign an Identifier that belongs to a class T (or derived) to a SubclassIdentifier<T>. 54 If you assign something else, the program aborts. 55 Because we know the minimum type, a dynamic_cast is done, which makes it easier to create a new object. 83 If you assign something else, the program prints an error. 84 85 Because we know the base-type, a @c dynamic_cast is done, which makes it easier to create a new object. 86 87 @see See @ref SubclassIdentifierExample "SubclassIdentifier.h" for some examples. 56 88 */ 57 89 template <class T> … … 59 91 { 60 92 public: 61 /** 62 @brief Constructor: Automaticaly assigns the Identifier of the given class. 63 */ 93 /// Constructor: Automaticaly assigns the Identifier of the given class. 64 94 SubclassIdentifier() 65 95 { … … 67 97 } 68 98 69 /** 70 @brief Constructor: Assigns the given Identifier. 71 @param identifier The Identifier 72 */ 99 /// Constructor: Assigns the given Identifier. 73 100 SubclassIdentifier(Identifier* identifier) 74 101 { … … 76 103 } 77 104 78 /** 79 @brief Copyconstructor: Assigns the identifier of the other SubclassIdentifier. 80 @param identifier The other SublcassIdentifier 81 */ 105 /// Copyconstructor: Assigns the identifier of another SubclassIdentifier. 82 106 template <class O> 83 107 SubclassIdentifier(const SubclassIdentifier<O>& identifier) … … 113 137 } 114 138 115 /** 116 @brief Overloading of the = operator: assigns the identifier of the other SubclassIdentifier. 117 @param identifier The other SublcassIdentifier 118 */ 139 /// Overloading of the = operator: assigns the identifier of another SubclassIdentifier. 119 140 template <class O> 120 141 SubclassIdentifier<T>& operator=(const SubclassIdentifier<O>& identifier) … … 123 144 } 124 145 125 /** 126 @brief Overloading of the * operator: returns the assigned identifier. 127 */ 146 /// Overloading of the * operator: returns the assigned identifier. 128 147 inline Identifier* operator*() const 129 148 { … … 131 150 } 132 151 133 /** 134 @brief Overloading of the -> operator: returns the assigned identifier. 135 */ 152 /// Overloading of the -> operator: returns the assigned identifier. 136 153 inline Identifier* operator->() const 137 154 { … … 139 156 } 140 157 141 /** 142 @brief Returns the assigned identifier. This allows you to assign a SubclassIdentifier to a normal Identifier*. 143 */ 158 /// Returns the assigned identifier. This allows you to assign a SubclassIdentifier to a normal Identifier*. 144 159 inline operator Identifier*() const 145 160 { … … 147 162 } 148 163 149 /** 150 @brief Creates a new object of the type of the assigned Identifier and dynamic_casts it to the minimal type given by T. 151 @return The new object 152 */ 164 /// Creates a new object of the type of the assigned Identifier and dynamic_casts it to the minimal type given by T. 153 165 T* fabricate(BaseObject* creator) const 154 166 { … … 181 193 } 182 194 183 / ** @brief Returns the assigned identifier. @return The identifier */195 /// Returns the assigned identifier. 184 196 inline Identifier* getIdentifier() const 185 197 { return this->identifier_; } -
code/trunk/src/libraries/core/Super.h
r7163 r7401 28 28 29 29 /** 30 @defgroup Super Super 31 @ingroup Class 32 */ 33 34 /** 30 35 @file 31 @ brief Definition of all super-function related macros.32 33 This file defines all macros needed to add a new "super-function". 34 If you add a super-function, you can call SUPER(myclass, functionname) inside your35 code and the function of the parentclass gets called. This is comparable with36 super.functionname() in Java or other languages.37 38 This works only with virtual functions that return nothing (void) and belong to 39 classes that have an Identifier. Arguments however are supported.40 41 To add a new super-function, you have process 4 steps:42 43 1) Add a new SUPER macro 44 This allows you to call the super-function in your code.45 Location: This file (Super.h), marked with --> HERE <-- comments (1/3) 46 47 2) Call the SUPER_FUNCTION_GLOBAL_DECLARATION_PART1/2 macros.48 This defines some global classes and templates, needed to create and call the super-functions.49 Location: This file (Super.h), marked with --> HERE <-- comments (2/3)50 51 3) Call the SUPER_INTRUSIVE_DECLARATION macro.52 This will be included into the declaration of ClassIdentifier<T>.53 Location: This file (Super.h), marked with --> HERE <-- comments (3/3)54 55 4) Call the SUPER_FUNCTION macro.36 @ingroup Class Super 37 @brief Definition of all super-function related macros, used to call functions of the base class. 38 39 This file defines all macros needed to add a new "super-function". If you add 40 a super-function, you can call <tt>SUPER(myclass, functionname, arguments)</tt> 41 inside your code and the function of the parent-class gets called. This is comparable 42 to <tt>super.functionname(arguments)</tt> in Java or other languages. 43 44 This works only with virtual functions that return nothing (@c void) and belong to 45 classes that have an @ref orxonox::Identifier "Identifier". Arguments however are 46 supported, there's no limitation for their number and type, except that the type has 47 to be known in Super.h. 48 49 To add a new super-function, you have to process 4 steps: 50 51 -# Add a new @c SUPER macro <br /> 52 This allows you to call the super-function in your code. <br /> 53 Location: This file (Super.h), marked with "--> HERE <--" comments (1/3) 54 -# Call the @c SUPER_FUNCTION_GLOBAL_DECLARATION_PART1/2 macros. <br /> 55 This defines some global classes and templates, needed to create and call the super-functions. <br /> 56 Location: This file (Super.h), marked with "--> HERE <--" comments (2/3) 57 -# Call the @c SUPER_INTRUSIVE_DECLARATION macro. <br /> 58 This will be included into the declaration of @c ClassIdentifier<T>. <br /> 59 Location: This file (Super.h), marked with "--> HERE <--" comments (3/3) 60 -# Call the @c SUPER_FUNCTION macro. <br /> 56 61 This defines a partially specialized template that will decide if a class is "super" to another class. 57 If the check returns true, a SuperFunctionCaller gets created, which will be used by theSUPER macro.62 If the check returns true, a @c SuperFunctionCaller gets created, which will be used by the @c SUPER macro. 58 63 You have to add this into the header-file of the baseclass of the super-function (the class that first 59 64 implements the function), below the class declaration. You can't call it directly in this file, because 60 otherwise you had to include the headerfile right here, which would cause some ugly back dependencies,61 include loops and slower compilation. 62 Dont forget to include Super.h in the header-file. 65 otherwise you had to include the headerfile right here, which would cause some ugly back-dependencies, 66 include loops and slower compilation. <br /> 67 Dont forget to include Super.h in the header-file. <br /> 63 68 Location: The header-file of the baseclass (Baseclass.h), below the class declaration 64 69 */ … … 205 210 */ 206 211 207 // SUPER-macro: Calls Parent::functionname() where Parent is the direct parent ofclassname212 /// SUPER-macro: Calls Parent::functionname(...) where Parent is the direct parent of @a classname 208 213 #ifdef ORXONOX_COMPILER_MSVC 209 214 #define SUPER(classname, functionname, ...) \ -
code/trunk/src/libraries/core/Template.h
r7163 r7401 26 26 * 27 27 */ 28 29 /** 30 @defgroup Template Template 31 @ingroup XML 32 */ 33 34 /** 35 @file 36 @ingroup XML Template 37 */ 28 38 29 39 #ifndef _Template_H__ -
code/trunk/src/libraries/core/Thread.h
r7284 r7401 26 26 * 27 27 */ 28 29 /** 30 @file 31 @ingroup ThreadPool 32 */ 28 33 29 34 #ifndef _Thread_H__ -
code/trunk/src/libraries/core/ThreadPool.h
r7284 r7401 26 26 * 27 27 */ 28 29 /** 30 @defgroup ThreadPool Thread pool 31 @ingroup Core 32 */ 33 34 /** 35 @file 36 @ingroup ThreadPool 37 */ 28 38 29 39 #ifndef _ThreadPool_H__ -
code/trunk/src/libraries/core/ToluaInterface.h
r5738 r7401 29 29 /** 30 30 @file 31 @ingroup Lua 32 @brief 31 33 This is required because tolua would parse this macro in LuaState.h and fail 32 34 */ -
code/trunk/src/libraries/core/WeakPtr.h
r7284 r7401 29 29 // Inspired by boost::intrusive_ptr by Peter Dimov 30 30 31 /** 32 @file 33 @ingroup Object SmartPtr 34 @brief Definition of WeakPtr<T>, wraps a pointer to an object. 35 36 @anchor WeakPtrExample 37 38 A WeakPtr wraps a pointer to an object. If the object gets deleted, the WeakPtr becomes 39 NULL. This can be used to store pointers to objects without knowing when they will be 40 destroyed. 41 42 WeakPtr works only with objects that are derived from orxonox::OrxonoxClass, because 43 WeakPtr is intrusive and registers itself in the stored object, to get a notification if 44 the object is being deleted. 45 46 Example: 47 @code 48 MyClass* object = new MyClass(); // create an instance of MyClass 49 50 WeakPtr<MyClass> pointer = object; // create a WeakPtr and assign the object 51 52 if (pointer) // checks if pointer is not NULL (which is true) 53 pointer->someFunction(); // calls MyClass::someFunction() 54 55 object->destroy(); // calls destroy() which deletes the object 56 57 if (pointer) // checks if pointer is not NULL (which is now false) 58 pointer->someFunction(); // this will not be executed 59 @endcode 60 In this example we assumed that MyClass is derived of OrxonoxClass (otherwise it couldn't 61 be used with a WeakPtr). 62 63 A callback can be registerd with the WeakPtr that will be called if the object gets deleted. 64 @code 65 void myCallback() // definition of the callback function 66 { 67 COUT(0) << "Object destroyed" << std::endl; 68 } 69 70 MyClass* object = new MyClass(); // create an instance of MyClass 71 72 WeakPtr<MyClass> pointer = object; // create a WeakPtr and assign the object 73 74 pointer.setCallback(createFunctor(&myCallback)); // defines a callback 75 76 object->destroy(); // calls destroy() which deletes the object. prints "Object destroyed" to the console 77 @endcode 78 */ 79 31 80 #ifndef _WeakPtr_H__ 32 81 #define _WeakPtr_H__ … … 41 90 namespace orxonox 42 91 { 92 /** 93 @brief WeakPtr wraps a pointer to an object, which becomes NULL if the object is deleted. 94 95 @see See @ref WeakPtrExample "this description" for more information and an example. 96 */ 43 97 template <class T> 44 98 class WeakPtr … … 47 101 48 102 public: 103 /// Constructor: Initializes the weak pointer with a null pointer. 49 104 inline WeakPtr() : pointer_(0), base_(0), callback_(0) 50 105 { 51 106 } 52 107 108 /// Constructor: Used to explicitly initialize the weak pointer with a null pointer 53 109 inline WeakPtr(int) : pointer_(0), base_(0), callback_(0) 54 110 { 55 111 } 56 112 113 /// Constructor: Initializes the weak pointer with a pointer to an object. 57 114 inline WeakPtr(T* pointer) : pointer_(pointer), base_(pointer), callback_(0) 58 115 { … … 61 118 } 62 119 120 /// Copy-constructor 63 121 inline WeakPtr(const WeakPtr& other) : pointer_(other.pointer_), base_(other.base_), callback_(0) 64 122 { … … 67 125 } 68 126 127 /// Copy-constructor for weak pointers to objects of another class. 69 128 template <class O> 70 129 inline WeakPtr(const WeakPtr<O>& other) : pointer_(other.get()), base_(other.base_), callback_(0) … … 74 133 } 75 134 135 /// Destructor 76 136 inline ~WeakPtr() 77 137 { … … 81 141 } 82 142 143 /// Used to assign a null pointer. 83 144 inline WeakPtr& operator=(int) 84 145 { … … 87 148 } 88 149 150 /// Assigns a new pointer. 89 151 inline WeakPtr& operator=(T* pointer) 90 152 { … … 93 155 } 94 156 157 /// Assigns the wrapped pointer of another WeakPtr. 95 158 inline WeakPtr& operator=(const WeakPtr& other) 96 159 { … … 99 162 } 100 163 164 /// Assigns the wrapped pointer of a WeakPtr of another class 101 165 template <class O> 102 166 inline WeakPtr& operator=(const WeakPtr<O>& other) … … 106 170 } 107 171 172 /// Returns the wrapped pointer as @c T* 108 173 inline T* get() const 109 174 { … … 111 176 } 112 177 178 /// Returns the wrapped pointer as @c OrxonoxClass* 113 179 inline OrxonoxClass* getBase() const 114 180 { … … 116 182 } 117 183 184 /// Implicitly converts the WeakPtr to a pointer of type @c T* 118 185 inline operator T*() const 119 186 { … … 121 188 } 122 189 190 /// Overloaded operator, returns a pointer to the stored object. 123 191 inline T* operator->() const 124 192 { … … 127 195 } 128 196 197 /// Overloaded operator, returns a reference to the stored object. 129 198 inline T& operator*() const 130 199 { … … 133 202 } 134 203 204 /// Returns true if the wrapped pointer is NULL. 135 205 inline bool operator!() const 136 206 { … … 138 208 } 139 209 210 /// Swaps the contents of two weak pointers. 140 211 inline void swap(WeakPtr& other) 141 212 { … … 162 233 } 163 234 235 /// Resets the weak pointer (equivalent to assigning a NULL pointer). 164 236 inline void reset() 165 237 { … … 167 239 } 168 240 241 /// Registers a callback that will be executed if the stored object is destroyed. 169 242 inline void setCallback(const FunctorPtr& callback) 170 243 { … … 172 245 } 173 246 247 /// Returns the registered callback. 174 248 inline const FunctorPtr& getCallback() const 175 249 { … … 178 252 179 253 private: 254 /// Will be called by OrxonoxClass::~OrxonoxClass() if the stored object is deleted. Resets the wrapped pointer and executes the callback. 180 255 inline void objectDeleted() 181 256 { … … 186 261 } 187 262 188 T* pointer_; 189 OrxonoxClass* base_; 190 FunctorPtr callback_; 263 T* pointer_; ///< The wrapped pointer to an object of type @a T 264 OrxonoxClass* base_; ///< The wrapped pointer, casted up to OrxonoxClass (this is needed because with just a T* pointer, WeakPtr couln't be used with forward declarations) 265 FunctorPtr callback_; ///< This callback will be executed if the stored object is deleted 191 266 }; 192 267 268 /// Swaps the contents of two weak pointers. 193 269 template <class T> 194 270 void swap(WeakPtr<T>& a, WeakPtr<T>& b) … … 197 273 } 198 274 275 /// Uses a static_cast to cast a pointer of type U* to a pointer of type T* and returns it in a new WeakPtr<T>. 199 276 template <class T, class U> 200 277 WeakPtr<T> static_pointer_cast(const WeakPtr<U>& p) … … 203 280 } 204 281 282 /// Uses a const_cast to cast a pointer of type U* to a pointer of type T* and returns it in a new WeakPtr<T>. 205 283 template <class T, class U> 206 284 WeakPtr<T> const_pointer_cast(const WeakPtr<U>& p) … … 209 287 } 210 288 289 /// Uses a dynamic_cast to cast a pointer of type U* to a pointer of type T* and returns it in a new WeakPtr<T>. 211 290 template <class T, class U> 212 291 WeakPtr<T> dynamic_pointer_cast(const WeakPtr<U>& p) -
code/trunk/src/libraries/core/WindowEventListener.h
r5781 r7401 26 26 * 27 27 */ 28 29 /** 30 @file 31 @ingroup Graphics 32 */ 28 33 29 34 #ifndef _WindowEventListener_H__ -
code/trunk/src/libraries/core/XMLFile.h
r6417 r7401 26 26 * 27 27 */ 28 29 /** 30 @file 31 @ingroup XML XMLPort 32 */ 28 33 29 34 #ifndef _XMLFile_H__ -
code/trunk/src/libraries/core/XMLNameListener.h
r5781 r7401 27 27 */ 28 28 29 /** 30 @file 31 @ingroup XML XMLPort 32 */ 33 29 34 #ifndef _XMLNameListener_H__ 30 35 #define _XMLNameListener_H__ -
code/trunk/src/libraries/core/XMLPort.h
r7284 r7401 28 28 29 29 /** 30 @defgroup XMLPort XMLPort 31 @ingroup XML 32 */ 33 34 /** 30 35 @file 36 @ingroup XML XMLPort 31 37 @brief Declaration of the XMLPort helper classes and macros. 32 38 … … 69 75 70 76 In the XML file, a param or attribute will be set like this: 77 @code 71 78 <classname paramname="value" /> 79 @endcode 72 80 73 81 The macro will then call loadfunction(value) to set the given value (or call savefunction() to … … 88 96 89 97 In the XML file, a param or attribute will be set like this: 98 @code 90 99 <classname paramname="value" /> 100 @endcode 91 101 92 102 The macro will then store "value" in the variable or read it when saving. … … 148 158 @param paramname The name of the attribute 149 159 @param loadfunction The function to set the attribute inside of the member object. 150 @param loadfunction The function to get the attribute from the member object 160 @param savefunction The function to get the attribute from the member object 161 @param xmlelement The XML-element that is parsed by this macro 162 @param mode Loading or saving 151 163 152 164 Sometimes you'll have a member object in your class, which has it's own load- and savefunctions. 153 165 With this macro, you can simply use them instead of writing your own functions. 154 166 155 @example167 Example: 156 168 Your class is called SpaceShip and this class has an object (myPilot_) of class Pilot. Pilot has a name 157 169 and two functions, setName(name) and getName(). Now you want an attribute "pilotname" in your … … 196 208 @param sectionname The name of the subsection in the XML file that encloses the sub-objects ("" means no subsection) 197 209 @param loadfunction The function to add a new object to the class 198 @param loadfunction The function to get all added objects from the class210 @param savefunction The function to get all added objects from the class 199 211 @param xmlelement The XMLElement (received through the XMLPort function) 200 212 @param mode The mode (load/save) (received through the XMLPort function) … … 210 222 likely the best option, so this is usually true. 211 223 212 @ note224 @details 213 225 The load- and savefunctions have to follow an exactly defined protocol. 214 226 Loadfunction: 215 227 The loadfunction gets a pointer to the object. 216 > void loadfunction(objectclass* pointer); 228 @code 229 void loadfunction(objectclass* pointer); 230 @endcode 217 231 218 232 Savefunction: … … 220 234 gets called again, but with index + 1. It's the functions responsibility to do something smart 221 235 with the index and to return 0 if all objects were returned. 222 > objectclass* savefunction(unsigned int index) const; 236 @code 237 objectclass* savefunction(unsigned int index) const; 238 @endcode 223 239 224 240 Possible implementation: 241 @code 225 242 objectclass* savefunction(unsigned int index) const 226 243 { … … 230 247 return 0; 231 248 } 232 233 @example 249 @endcode 250 251 Example: 234 252 Possible usage of the macro: 235 > XMLPortObject(SpaceShip, Weapon, "weapons", addWeapon, getWeapon, xmlelement, mode, false, true); 253 @code 254 XMLPortObject(SpaceShip, Weapon, "weapons", addWeapon, getWeapon, xmlelement, mode, false, true); 255 @endcode 236 256 237 257 Now you can add weapons through the XML file: 258 @code 238 259 <SpaceShip someattribute="..." ...> 239 260 <weapons> … … 243 264 </weapons> 244 265 </SpaceShip> 266 @endcode 245 267 246 268 Note that "weapons" is the subsection. This allows you to add more types of sub-objects. In our example, -
code/trunk/src/libraries/core/command/ArgumentCompleter.h
r7284 r7401 27 27 */ 28 28 29 /** 30 @defgroup ArgumentCompletion Argument completion 31 @ingroup Command 32 */ 33 34 /** 35 @file 36 @ingroup Command ArgumentCompletion 37 @brief Definition of the orxonox::ArgumentCompleter class that is used to execute @ref ArgumentCompletionFunctions.h "argument completion functions". 38 39 An ArgumentCompleter can be assigned to an orxonox::ConsoleCommand using 40 @ref orxonox::ConsoleCommand::argumentCompleter "argumentCompleter()". 41 The ArgumentCompleter calls an argument completion function that is defined 42 in ArgumentCompletionFunctions.h. This can be used to list possible arguments 43 for console commands and to allow auto-completion. 44 45 Instances of ArgumentCompleter are usually not created manually but rather 46 by the macros defined in ArgumentCompletionFunctions.h. There you'll also 47 find some examples. 48 49 @see See the @ref ArgumentCompletionExample "examples". 50 */ 51 29 52 #ifndef _ArgumentCompleter_H__ 30 53 #define _ArgumentCompleter_H__ … … 35 58 namespace orxonox 36 59 { 60 /** 61 @brief This class executes an argument completion function and returns a list of the possible arguments. 62 63 ArgumentCompleter is used to wrap argument completion functions as defined 64 in ArgumentCompletionFunctions.h and can be assigned to a ConsoleCommand to 65 create a list of possible arguments. 66 67 @see See ArgumentCompleter.h for more information. 68 @see See @ref ArgumentCompletionExample "ArgumentCompletionFunctions.h" for an example. 69 */ 37 70 class _CoreExport ArgumentCompleter 38 71 { 39 72 public: 40 ArgumentCompleter(ArgumentCompletionList (*function) (void), bool bUseMultipleWords) : bUseMultipleWords_(bUseMultipleWords), paramCount_(0), function_0_(function) {} 41 ArgumentCompleter(ArgumentCompletionList (*function) (const std::string& param1), bool bUseMultipleWords) : bUseMultipleWords_(bUseMultipleWords), paramCount_(1), function_1_(function) {} 42 ArgumentCompleter(ArgumentCompletionList (*function) (const std::string& param1, const std::string& param2), bool bUseMultipleWords) : bUseMultipleWords_(bUseMultipleWords), paramCount_(2), function_2_(function) {} 43 ArgumentCompleter(ArgumentCompletionList (*function) (const std::string& param1, const std::string& param2, const std::string& param3), bool bUseMultipleWords) : bUseMultipleWords_(bUseMultipleWords), paramCount_(3), function_3_(function) {} 44 ArgumentCompleter(ArgumentCompletionList (*function) (const std::string& param1, const std::string& param2, const std::string& param3, const std::string& param4), bool bUseMultipleWords) : bUseMultipleWords_(bUseMultipleWords), paramCount_(4), function_4_(function) {} 45 ArgumentCompleter(ArgumentCompletionList (*function) (const std::string& param1, const std::string& param2, const std::string& param3, const std::string& param4, const std::string& param5), bool bUseMultipleWords) : bUseMultipleWords_(bUseMultipleWords), paramCount_(5), function_5_(function) {} 73 ArgumentCompleter(ArgumentCompletionList (*function) (void), bool bUseMultipleWords) : bUseMultipleWords_(bUseMultipleWords), paramCount_(0), function_0_(function) {} ///< Constructor, assigns a function-pointer with no arguments. 74 ArgumentCompleter(ArgumentCompletionList (*function) (const std::string& param1), bool bUseMultipleWords) : bUseMultipleWords_(bUseMultipleWords), paramCount_(1), function_1_(function) {} ///< Constructor, assigns a function-pointer with one argument. 75 ArgumentCompleter(ArgumentCompletionList (*function) (const std::string& param1, const std::string& param2), bool bUseMultipleWords) : bUseMultipleWords_(bUseMultipleWords), paramCount_(2), function_2_(function) {} ///< Constructor, assigns a function-pointer with two arguments. 76 ArgumentCompleter(ArgumentCompletionList (*function) (const std::string& param1, const std::string& param2, const std::string& param3), bool bUseMultipleWords) : bUseMultipleWords_(bUseMultipleWords), paramCount_(3), function_3_(function) {} ///< Constructor, assigns a function-pointer with three arguments. 77 ArgumentCompleter(ArgumentCompletionList (*function) (const std::string& param1, const std::string& param2, const std::string& param3, const std::string& param4), bool bUseMultipleWords) : bUseMultipleWords_(bUseMultipleWords), paramCount_(4), function_4_(function) {} ///< Constructor, assigns a function-pointer with four arguments. 78 ArgumentCompleter(ArgumentCompletionList (*function) (const std::string& param1, const std::string& param2, const std::string& param3, const std::string& param4, const std::string& param5), bool bUseMultipleWords) : bUseMultipleWords_(bUseMultipleWords), paramCount_(5), function_5_(function) {} ///< Constructor, assigns a function-pointer with five arguments. 46 79 80 /** 81 @brief Calls the argument completion function with a maximum of five parameters. 82 @return Returns the list of possible arguments, created by the argument completion function 83 */ 47 84 ArgumentCompletionList operator()(const std::string& param1 = "", const std::string& param2 = "", const std::string& param3 = "", const std::string& param4 = "", const std::string& param5 = "") 48 85 { … … 66 103 } 67 104 105 /// Returns true if the argument completion list supports multiple words. 68 106 inline bool useMultipleWords() const 69 107 { return this->bUseMultipleWords_; } 70 108 71 109 private: 72 bool bUseMultipleWords_; 73 unsigned char paramCount_; 74 ArgumentCompletionList (*function_0_) (void); 75 ArgumentCompletionList (*function_1_) (const std::string& param1); 76 ArgumentCompletionList (*function_2_) (const std::string& param1, const std::string& param2); 77 ArgumentCompletionList (*function_3_) (const std::string& param1, const std::string& param2, const std::string& param3); 78 ArgumentCompletionList (*function_4_) (const std::string& param1, const std::string& param2, const std::string& param3, const std::string& param4); 79 ArgumentCompletionList (*function_5_) (const std::string& param1, const std::string& param2, const std::string& param3, const std::string& param4, const std::string& param5); 110 bool bUseMultipleWords_; ///< If true, the argument completion list supports multiple words 111 unsigned char paramCount_; ///< The number of parameters of the argument completion function 112 ArgumentCompletionList (*function_0_) (void); ///< Function-pointer for an argument completion function with no arguments 113 ArgumentCompletionList (*function_1_) (const std::string& param1); ///< Function-pointer for an argument completion function with one argument 114 ArgumentCompletionList (*function_2_) (const std::string& param1, const std::string& param2); ///< Function-pointer for an argument completion function with two arguments 115 ArgumentCompletionList (*function_3_) (const std::string& param1, const std::string& param2, const std::string& param3); ///< Function-pointer for an argument completion function with three arguments 116 ArgumentCompletionList (*function_4_) (const std::string& param1, const std::string& param2, const std::string& param3, const std::string& param4); ///< Function-pointer for an argument completion function with four arguments 117 ArgumentCompletionList (*function_5_) (const std::string& param1, const std::string& param2, const std::string& param3, const std::string& param4, const std::string& param5); ///< Function-pointer for an argument completion function with five arguments 80 118 }; 81 119 } -
code/trunk/src/libraries/core/command/ArgumentCompletionFunctions.cc
r7284 r7401 26 26 * 27 27 */ 28 29 /** 30 @file 31 @brief Implementation of all argument completion functions 32 */ 28 33 29 34 #include "ArgumentCompletionFunctions.h" … … 53 58 namespace autocompletion 54 59 { 60 /** 61 @brief Fallback implementation, returns an empty list. 62 */ 55 63 ARGUMENT_COMPLETION_FUNCTION_IMPLEMENTATION(fallback)() 56 64 { … … 60 68 namespace detail 61 69 { 70 /** 71 @brief Returns true if a group of console commands is visible (i.e. if at least one command in this group is visible). 72 */ 62 73 bool groupIsVisible(const std::map<std::string, ConsoleCommand*>& group, bool bOnlyShowHidden) 63 74 { … … 69 80 } 70 81 82 /** 83 @brief Returns a list of all console command groups AND all console command shortcuts. 84 @param fragment The last argument 85 @param bOnlyShowHidden If true, only hidden groups and commands are returned 86 */ 71 87 ArgumentCompletionList _groupsandcommands(const std::string& fragment, bool bOnlyShowHidden) 72 88 { 89 // note: this function returns only arguments that begin with "fragment", which would't be necessary for the 90 // auto-completion, but it's necessary to place the line-break "\n" between groups and commands 91 // only if both groups AND commands are in the list. 92 73 93 ArgumentCompletionList groupList; 74 94 std::string fragmentLC = getLowercase(fragment); 75 95 96 // get all the groups that are visible (except the shortcut group "") 76 97 const std::map<std::string, std::map<std::string, ConsoleCommand*> >& commands = ConsoleCommand::getCommands(); 77 98 for (std::map<std::string, std::map<std::string, ConsoleCommand*> >::const_iterator it_group = commands.begin(); it_group != commands.end(); ++it_group) … … 79 100 groupList.push_back(ArgumentCompletionListElement(it_group->first, getLowercase(it_group->first))); 80 101 102 // now add all shortcuts (in group "") 81 103 std::map<std::string, std::map<std::string, ConsoleCommand*> >::const_iterator it_group = commands.find(""); 82 104 if (it_group != commands.end()) 83 105 { 106 // add a line-break if the list isn't empty 84 107 if (!groupList.empty()) 85 108 groupList.push_back(ArgumentCompletionListElement("", "", "\n")); 86 109 110 // add the shortcuts 87 111 for (std::map<std::string, ConsoleCommand*>::const_iterator it_command = it_group->second.begin(); it_command != it_group->second.end(); ++it_command) 88 112 if (it_command->second->isActive() && it_command->second->hasAccess() && (!it_command->second->isHidden())^bOnlyShowHidden && (fragmentLC == "" || getLowercase(it_command->first).find_first_of(fragmentLC) == 0)) … … 90 114 } 91 115 116 // if no shortcut was added, remove the line-break again 92 117 if (!groupList.empty() && groupList.back().getDisplay() == "\n") 93 118 groupList.pop_back(); … … 96 121 } 97 122 123 /** 124 @brief Returns a list of all console commands in a given group. 125 @param fragment The last argument 126 @param group The group's name 127 @param bOnlyShowHidden If true, only hidden console commands are returned 128 */ 98 129 ArgumentCompletionList _subcommands(const std::string& fragment, const std::string& group, bool bOnlyShowHidden) 99 130 { … … 102 133 std::string groupLC = getLowercase(group); 103 134 135 // find the iterator of the given group 104 136 std::map<std::string, std::map<std::string, ConsoleCommand*> >::const_iterator it_group = ConsoleCommand::getCommands().begin(); 105 137 for ( ; it_group != ConsoleCommand::getCommands().end(); ++it_group) … … 107 139 break; 108 140 141 // add all commands in the group to the list 109 142 if (it_group != ConsoleCommand::getCommands().end()) 110 143 { … … 118 151 } 119 152 153 /** 154 @brief Returns a list of all console command groups AND all console command shortcuts. 155 */ 120 156 ARGUMENT_COMPLETION_FUNCTION_IMPLEMENTATION(groupsandcommands)(const std::string& fragment) 121 157 { … … 123 159 } 124 160 161 /** 162 @brief Returns a list of all console commands in a given group. 163 */ 125 164 ARGUMENT_COMPLETION_FUNCTION_IMPLEMENTATION(subcommands)(const std::string& fragment, const std::string& group) 126 165 { … … 128 167 } 129 168 169 /** 170 @brief Returns a list of commands and groups and also supports auto-completion of the arguments of these commands. 171 172 This is a multi-word function, because commands are composed of 1-2 words and additional arguments. 173 */ 130 174 ARGUMENT_COMPLETION_FUNCTION_IMPLEMENTATION_MULTI(command)(const std::string& fragment) 131 175 { … … 145 189 } 146 190 191 /** 192 @brief Returns a list of hidden commands and groups and also supports auto-completion of the arguments of these commands. 193 194 This is a multi-word function, because commands are composed of 1-2 words and additional arguments. 195 196 This function makes commands visible that would usually be hidden. 197 */ 147 198 ARGUMENT_COMPLETION_FUNCTION_IMPLEMENTATION_MULTI(hiddencommand)(const std::string& fragment) 148 199 { … … 170 221 } 171 222 223 /** 224 @brief Returns possible files and directories and also supports files in arbitrary deeply nested subdirectories. 225 226 This function returns files and directories in the given path. This allows to 227 navigate iteratively through the file system. The first argument @a fragment 228 is used to get the current path. 229 */ 172 230 ARGUMENT_COMPLETION_FUNCTION_IMPLEMENTATION(files)(const std::string& fragment) 173 231 { … … 211 269 } 212 270 271 /** 272 @brief Returns the sections of the config file. 273 */ 213 274 ARGUMENT_COMPLETION_FUNCTION_IMPLEMENTATION(settingssections)() 214 275 { … … 222 283 } 223 284 285 /** 286 @brief Returns the entries in a given section of the config file. 287 */ 224 288 ARGUMENT_COMPLETION_FUNCTION_IMPLEMENTATION(settingsentries)(const std::string& fragment, const std::string& section) 225 289 { … … 235 299 } 236 300 301 /** 302 @brief Returns the current value of a given value in a given section of the config file. 303 */ 237 304 ARGUMENT_COMPLETION_FUNCTION_IMPLEMENTATION(settingsvalue)(const std::string& fragment, const std::string& entry, const std::string& section) 238 305 { … … 255 322 } 256 323 324 /** 325 @brief Returns a list of indexes of the available Tcl threads (see TclThreadManager). 326 */ 257 327 ARGUMENT_COMPLETION_FUNCTION_IMPLEMENTATION(tclthreads)() 258 328 { -
code/trunk/src/libraries/core/command/ArgumentCompletionFunctions.h
r7284 r7401 27 27 */ 28 28 29 /** 30 @file 31 @ingroup Command ArgumentCompletion 32 @brief Declaration of all argument completion functions and macros used to define them. 33 34 @anchor ArgumentCompletionExample 35 36 Argument completion functions are used to create a list of possible arguments 37 for an orxonox::ConsoleCommand. These functions are usually wrapped by an instance 38 of orxonox::ArgumentCompleter. 39 40 Argument completion functions can be declared and implemented by using the macros 41 ARGUMENT_COMPLETION_FUNCTION_DECLARATION() and ARGUMENT_COMPLETION_FUNCTION_IMPLEMENTATION() 42 respectively. They are necessary because they don't simply define the function, but they also 43 create a static helper function that returns an instance of orxonox::ArgumentCompleter which 44 wraps the defined function. This allows easier referencing of argument completion functions 45 by simply calling autocompletion::functionname(). 46 47 Argument completion functions can take up to 5 arguments, all of type std::string. 48 The first argument is always the current argument which is being entered by the user 49 in the shell. The second argument is the argument before, so in fact arguments from 50 the shell are sent in reversed order to the argument completion function. This is 51 necessary because the number of arguments can be variable 52 53 Example: The user types the following into the shell: 54 @code 55 $ commandname argument1 argument2 argum 56 @endcode 57 Then he presses the @a tab key to print the possible arguments. Now the argument 58 completion function for the @a third argument of @a commandname will be called in 59 the following way: 60 @code 61 list = argcompfunction3("argum", "argument2", "argument1"); 62 @endcode 63 64 Usually each argument is one word (without whitespaces in it), but some argument completion 65 functions need more than one word. This can be achieved by using ARGUMENT_COMPLETION_FUNCTION_IMPLEMENTATION_MULTI(). 66 In this case all supernumerous words are passed to the first (!) argument. 67 68 An example to show how to declare, implement, and use an argument completion function: 69 @code 70 // ArgumentCompletionFunctions.h: 71 // ------------------------------ 72 73 // Declaration of the function: 74 ARGUMENT_COMPLETION_FUNCTION_DECLARATION(month)(const std::string& fragment); 75 76 // ArgumentCompletionFunctions.cc: 77 // ------------------------------- 78 79 // Implementation of the function 80 ARGUMENT_COMPLETION_FUNCTION_IMPLEMENTATION(month)(const std::string& fragment) 81 { 82 ArgumentCompletionList list; 83 84 // check if the first part of the argument is a number - if yes, the user likely wants to enter the month as a number 85 if (isNumber(fragment)) 86 { 87 for (int month = 1; month <= 12; ++month) 88 list.push_back(ArgumentCompletionListElement(multi_cast<std::string>(month))); 89 } 90 else 91 { 92 list.push_back(ArgumentCompletionListElement("January", "january")); 93 list.push_back(ArgumentCompletionListElement("February", "february")); 94 list.push_back(ArgumentCompletionListElement("March", "march")); 95 list.push_back(ArgumentCompletionListElement("April", "april")); 96 list.push_back(ArgumentCompletionListElement("May", "may")); 97 list.push_back(ArgumentCompletionListElement("June", "june")); 98 list.push_back(ArgumentCompletionListElement("July", "july")); 99 list.push_back(ArgumentCompletionListElement("August", "august")); 100 list.push_back(ArgumentCompletionListElement("September", "september")); 101 list.push_back(ArgumentCompletionListElement("October", "october")); 102 list.push_back(ArgumentCompletionListElement("November", "november")); 103 list.push_back(ArgumentCompletionListElement("December", "december")); 104 } 105 106 return list; 107 } 108 109 // SomeFile: 110 // --------- 111 112 // A class to manage the date: 113 class Date 114 { 115 public: 116 static void setDate(int day, const std::string& month, int year); 117 }; 118 119 // Define a console command that needs a date. Add argument completion for the month: 120 SetConsoleCommand("setDate", &Date::setDate).argumentCompleter(1, autocompletion::month()); 121 @endcode 122 123 This example defines an argument completion function that returns a list of possible 124 months. If the first part of the argument is a number, it returns the numbers 1-12, 125 otherwise the name of the months are returned. Note how the list is composed by 126 instances of orxonox::ArgumentCompletionListElement. For the name of the months, 127 two strings are provided, one in normal case and one in lower case. See the documentation 128 of orxonox::ArgumentCompletionListElement for more information about this. 129 130 Also note that the argument completion list is assigned to the console command by using 131 @ref orxonox::ConsoleCommand::argumentCompleter "argumentCompleter()". The first argument 132 is the index of the argument: 133 - 0 is the first argument (@a day) 134 - 1 is the second argument (@a month) 135 - 2 is the third argument (@a year) 136 137 @a day and @a year don't need an argument completion function as they are just integers. 138 139 The function @c autocompletion::month() is automatically created by the macros 140 ARGUMENT_COMPLETION_FUNCTION_DECLARATION() and ARGUMENT_COMPLETION_FUNCTION_IMPLEMENTATION() 141 and returns an orxonox::ArgumentCompleter that wraps the defined argument completion function. 142 143 The implemented argument completion function uses only one argument, the fragment of the 144 currently entered argument. More complex functions can also use the previous arguments 145 to return different arguments depending on the other arguments (for example to list the 146 members of a class, where the class-name is the first argument and the member the second). 147 */ 148 29 149 #ifndef _ArgumentCompletionFunctions_H__ 30 150 #define _ArgumentCompletionFunctions_H__ … … 33 153 #include "ArgumentCompleter.h" 34 154 35 155 /** 156 @brief Used to declare an argument completion function with name @a functionname. 157 @param functionname The name of the function, will also be used for the implementation of the function. 158 159 The macro also defines a static function that returns an orxonox::ArgumentCompleter 160 which wraps the defined function. This can be accessed by calling autocompletion::functionname(); 161 */ 36 162 #define ARGUMENT_COMPLETION_FUNCTION_DECLARATION(functionname) \ 37 163 _CoreExport ArgumentCompleter* functionname(); \ 38 164 _CoreExport ArgumentCompletionList acf_##functionname 39 165 166 /** 167 @brief Used to implement an argument completion function. 168 @param functionname The name of the function 169 */ 40 170 #define ARGUMENT_COMPLETION_FUNCTION_IMPLEMENTATION(functionname) \ 41 171 _ARGUMENT_COMPLETION_FUNCTION_IMPLEMENTATION_INTERNAL(functionname, false) 172 173 /** 174 @brief Used to implement an argument completion function which allows multiple words. 175 @param functionname The name of the function 176 */ 42 177 #define ARGUMENT_COMPLETION_FUNCTION_IMPLEMENTATION_MULTI(functionname) \ 43 178 _ARGUMENT_COMPLETION_FUNCTION_IMPLEMENTATION_INTERNAL(functionname, true) 44 179 180 /// Internal macro 45 181 #define _ARGUMENT_COMPLETION_FUNCTION_IMPLEMENTATION_INTERNAL(functionname, bUseMultipleWords) \ 46 182 ArgumentCompleter* functionname() \ … … 52 188 ArgumentCompletionList acf_##functionname 53 189 190 /// Calls an argument completion function. Used for functions that return the results of another argument completion function. 54 191 #define ARGUMENT_COMPLETION_FUNCTION_CALL(functionname) acf_##functionname 55 192 -
code/trunk/src/libraries/core/command/ArgumentCompletionListElement.h
r7284 r7401 27 27 */ 28 28 29 /** 30 @file 31 @ingroup Command ArgumentCompletion 32 @brief Definition of ArgumentCompletionList, which is used in @ref ArgumentCompletionFunctions.h "argument completion functions", and its element. 33 */ 34 29 35 #ifndef _ArgumentCompletionListElement_H__ 30 36 #define _ArgumentCompletionListElement_H__ … … 37 43 namespace orxonox 38 44 { 39 const int ACL_MODE_NORMAL = 1;40 const int ACL_MODE_COMPARABLE = 2; 41 const int ACL_MODE_DISPLAY = 4;45 const int ACL_MODE_NORMAL = 1; ///< A flag, used if there's a normal string 46 const int ACL_MODE_COMPARABLE = 2; ///< A flag, used if there's a different string used to compare 47 const int ACL_MODE_DISPLAY = 4; ///< A flag, used if there's a different string used to be displayed 42 48 43 49 typedef std::list<ArgumentCompletionListElement> ArgumentCompletionList; 44 50 51 /** 52 @brief This class is used in argument completion lists and contains up to three different strings, used in different situations. 53 54 A list containing elements of type ArgumentCompletionListElement is returned by 55 an @ref ArgumentCompletionFunctions.h "argument completion function". These elements 56 are composed of up to three strings with different usage: 57 - normal: What is used as the actual argument 58 - comparable: What is used to compere the argument to the input of the user (usually lowercase, except for case-sensitive arguments) 59 - display: This is displayed in the list of possible arguments - can differ from what is actually used for better readability 60 61 @remarks An element with an empty ("") 'comparable' string will be ignored by the argument 62 completion algorithms, but it's 'display' string will still be printed in the list. This 63 can be used to add additional information, whitespaces, linebreaks or whatever is needed 64 to format the output. 65 */ 45 66 class _CoreExport ArgumentCompletionListElement 46 67 { 47 68 public: 69 /// Constructor: Normal, comparable, and display string are all the same. 48 70 ArgumentCompletionListElement(const std::string& normalcase) : mode_(ACL_MODE_NORMAL), normal_(normalcase) {} 71 /// Constructor: Normal and display string are the same, a different (usually lowercase) string is used for comparison. 49 72 ArgumentCompletionListElement(const std::string& normalcase, const std::string& lowercase) : mode_(ACL_MODE_NORMAL | ACL_MODE_COMPARABLE), normal_(normalcase), comparable_(lowercase) {} 73 /// Constructor: Normal, comparable, and display are all different strings. 50 74 ArgumentCompletionListElement(const std::string& normalcase, const std::string& lowercase, const std::string& display) : mode_(ACL_MODE_NORMAL | ACL_MODE_COMPARABLE | ACL_MODE_DISPLAY), normal_(normalcase), comparable_(lowercase), display_(display) {} 51 75 76 /// Returns the normal string which is used as the actual argument. 52 77 const std::string& getString() const 53 78 { return this->normal_; } 79 /// Returns the comparable string which is used to compare arguments and user input 54 80 const std::string& getComparable() const 55 81 { return (this->mode_ & ACL_MODE_COMPARABLE) ? this->comparable_ : this->normal_; } 82 /// Returns the display string which is used in the displayed list of possible arguments 56 83 const std::string& getDisplay() const 57 84 { return (this->mode_ & ACL_MODE_DISPLAY) ? this->display_ : this->normal_; } 58 85 86 /// Returns true if there's a different string for comparison. 59 87 bool hasComparable() const 60 88 { return (this->mode_ & ACL_MODE_COMPARABLE); } 89 /// Returns true if there's a different string to display. 61 90 bool hasDisplay() const 62 91 { return (this->mode_ & ACL_MODE_DISPLAY); } 63 92 93 /// Overloaded operator for usage in maps and sets. 64 94 bool operator<(const ArgumentCompletionListElement& other) const 65 95 { return (this->getComparable() < other.getComparable()); } 66 96 67 97 private: 68 unsigned char mode_; 69 std::string normal_; 70 std::string comparable_; 71 std::string display_; 98 unsigned char mode_; ///< The flags 99 std::string normal_; ///< The normal string 100 std::string comparable_; ///< The comparable (usually lowercase) string 101 std::string display_; ///< The string to display 72 102 }; 73 103 } -
code/trunk/src/libraries/core/command/CommandEvaluation.cc
r7286 r7401 27 27 */ 28 28 29 /** 30 @file 31 @brief Implementation of CommandEvaluation 32 */ 33 29 34 #include "CommandEvaluation.h" 30 35 … … 35 40 namespace orxonox 36 41 { 42 /** 43 @brief Constructor: Initializes the command evaluation with an empty command. 44 */ 37 45 CommandEvaluation::CommandEvaluation() 38 46 { … … 40 48 } 41 49 50 /** 51 @brief Initializes all values. 52 */ 42 53 void CommandEvaluation::initialize(const std::string& command) 43 54 { … … 49 60 this->bPossibleArgumentsRetrieved_ = false; 50 61 this->possibleArguments_.clear(); 51 this->bEvaluatedParams_ = false; 52 this->bTriedToEvaluatedParams_ = false; 53 this->numberOfEvaluatedParams_ = 0; 54 62 this->bEvaluatedArguments_ = false; 63 this->bTriedToEvaluatedArguments_ = false; 64 this->numberOfEvaluatedArguments_ = 0; 65 66 // split the command into tokens 55 67 this->tokens_.split(command, " ", SubString::WhiteSpaces, false, '\\', true, '"', true, '{', '}', true, '\0'); 56 68 } 57 69 70 /** 71 @brief Returns the number of tokens according to the definition of CommandExecutor (which counts also an empty argument at the end of the string). 72 */ 58 73 unsigned int CommandEvaluation::getNumberOfArguments() const 59 74 { 60 75 unsigned int count = this->tokens_.size(); 61 if (count > 0 && this->string_[this->string_.size() - 1] != ' ') 76 77 // If the last char in the string is a space character (or the string is empty), add +1 to the number of tokens, because this counts as an additional (but empty) argument 78 if (count == 0 || this->string_[this->string_.size() - 1] == ' ') 79 return count + 1; 80 else 62 81 return count; 82 } 83 84 /** 85 @brief Returns the last argument (which is the one the user currently enters into the shell). 86 */ 87 const std::string& CommandEvaluation::getLastArgument() const 88 { 89 // the string is empty or ends with a space character, the user is just about to enter a new argument (but its still empty). return a blank string in this case. 90 if (this->tokens_.size() == 0 || this->string_[this->string_.size() - 1] == ' ') 91 return BLANKSTRING; 63 92 else 64 return count + 1;65 }66 67 const std::string& CommandEvaluation::getLastArgument() const68 {69 if (this->tokens_.size() > 0 && this->string_[this->string_.size() - 1] != ' ')70 93 return this->tokens_.back(); 71 else 72 return BLANKSTRING; 73 } 74 94 } 95 96 /** 97 @brief Returns the token with the given index (or a blank string if it doesn't exist). 98 */ 75 99 const std::string& CommandEvaluation::getToken(unsigned int i) const 76 100 { … … 81 105 } 82 106 107 /** 108 @brief Executes the command which was evaluated by this object. 109 @return Returns the error code (see @ref CommandExecutorErrorCodes "CommandExecutor error codes") 110 */ 83 111 int CommandEvaluation::execute() 84 112 { … … 88 116 } 89 117 118 /** 119 @brief Executes the command which was evaluated by this object and returns its return-value. 120 @param error A pointer to an integer (or NULL) which will be used to write error codes to (see @ref CommandExecutorErrorCodes "CommandExecutor error codes") 121 @return Returns the result of the command (or MT_Type::Null if there is no return value) 122 */ 90 123 MultiType CommandEvaluation::query(int* error) 91 124 { 125 // check if an error value was passed by reference 92 126 if (error) 93 127 { 128 // Determine the error-code and return if it is not Success 129 94 130 *error = CommandExecutor::Success; 95 131 … … 105 141 } 106 142 143 // check if it's possible to execute the command 107 144 if (this->execCommand_ && this->execCommand_->isActive() && this->execCommand_->hasAccess()) 108 145 { 109 if (!this->bTriedToEvaluatedParams_) 110 this->evaluateParams(false); 111 112 if (this->bEvaluatedParams_) 113 { 114 COUT(6) << "CE_execute (evaluation): " << this->execCommand_->getName() << " with " << this->numberOfEvaluatedParams_ << " params: " << this->param_[0] << ' ' << this->param_[1] << ' ' << this->param_[2] << ' ' << this->param_[3] << ' ' << this->param_[4] << std::endl; 115 switch (this->numberOfEvaluatedParams_) 146 // if the arguments weren't evaluated yet, do it now. 147 if (!this->bTriedToEvaluatedArguments_) 148 this->evaluateArguments(false); 149 150 // check if the argument evaluation succeded 151 if (this->bEvaluatedArguments_) 152 { 153 COUT(6) << "CE_execute (evaluation): " << this->execCommand_->getName() << " with " << this->numberOfEvaluatedArguments_ << " arguments: " << this->arguments_[0] << ' ' << this->arguments_[1] << ' ' << this->arguments_[2] << ' ' << this->arguments_[3] << ' ' << this->arguments_[4] << std::endl; 154 155 // pass as many arguments to the executor as were evaluated (thus the executor can still use additional default values) 156 switch (this->numberOfEvaluatedArguments_) 116 157 { 117 158 case 0: return (*this->execCommand_->getExecutor())(); 118 case 1: return (*this->execCommand_->getExecutor())(this-> param_[0]);119 case 2: return (*this->execCommand_->getExecutor())(this-> param_[0], this->param_[1]);120 case 3: return (*this->execCommand_->getExecutor())(this-> param_[0], this->param_[1], this->param_[2]);121 case 4: return (*this->execCommand_->getExecutor())(this-> param_[0], this->param_[1], this->param_[2], this->param_[3]);159 case 1: return (*this->execCommand_->getExecutor())(this->arguments_[0]); 160 case 2: return (*this->execCommand_->getExecutor())(this->arguments_[0], this->arguments_[1]); 161 case 3: return (*this->execCommand_->getExecutor())(this->arguments_[0], this->arguments_[1], this->arguments_[2]); 162 case 4: return (*this->execCommand_->getExecutor())(this->arguments_[0], this->arguments_[1], this->arguments_[2], this->arguments_[3]); 122 163 case 5: 123 default: return (*this->execCommand_->getExecutor())(this-> param_[0], this->param_[1], this->param_[2], this->param_[3], this->param_[4]);164 default: return (*this->execCommand_->getExecutor())(this->arguments_[0], this->arguments_[1], this->arguments_[2], this->arguments_[3], this->arguments_[4]); 124 165 } 125 166 } … … 128 169 } 129 170 171 // return a null value in case of an error 130 172 return MT_Type::Null; 131 173 } 132 174 133 int CommandEvaluation::evaluateParams(bool bPrintError) 134 { 135 this->bTriedToEvaluatedParams_ = true; 136 175 /** 176 @brief Evaluates the arguments of the command. 177 @param bPrintError If true, the function prints an error message if it doesn't succeed 178 @return Returns the error code (see @ref CommandExecutorErrorCodes "CommandExecutor error codes") 179 */ 180 int CommandEvaluation::evaluateArguments(bool bPrintError) 181 { 182 this->bTriedToEvaluatedArguments_ = true; 183 184 // check if there's a command to execute 137 185 if (!this->execCommand_) 138 186 { 139 187 if (bPrintError) 140 COUT(1) << "Error: Can't evaluate params, no console command assigned." << std::endl;188 COUT(1) << "Error: Can't evaluate arguments, no console command assigned." << std::endl; 141 189 return CommandExecutor::Error; 142 190 } 143 191 144 192 int error; 145 this->numberOfEvaluatedParams_ = this->execCommand_->getExecutor()->evaluateParams(this->tokens_.subSet(this->execArgumentsOffset_), this->param_, &error, " "); 193 194 // try to evaluate the arguments using the executor of the evaluated command. 195 // the arguments are currently stored as strings in token_, but afterwards they will be converted to the right type and stored in arguments_ 196 this->numberOfEvaluatedArguments_ = this->execCommand_->getExecutor()->evaluateArguments(this->tokens_.subSet(this->execArgumentsOffset_), this->arguments_, &error, " "); 197 198 // check if an error occurred 146 199 if (!error) 147 this->bEvaluated Params_ = true;200 this->bEvaluatedArguments_ = true; 148 201 else if (bPrintError) 149 COUT(1) << "Error: Can't evaluate params, not enough arguments given." << std::endl;202 COUT(1) << "Error: Can't evaluate arguments, not enough arguments given." << std::endl; 150 203 151 204 return error; 152 205 } 153 206 154 void CommandEvaluation::setEvaluatedParameter(unsigned int index, const MultiType& param) 207 /** 208 @brief Replaces an evaluated argument with a new value. 209 @param index The index of the parameter (the first argument has index 0) 210 @param arg The new value of the parameter 211 */ 212 void CommandEvaluation::setEvaluatedArgument(unsigned int index, const MultiType& arg) 155 213 { 156 214 if (index < MAX_FUNCTOR_ARGUMENTS) 157 this->param_[index] = param; 158 } 159 160 MultiType CommandEvaluation::getEvaluatedParameter(unsigned int index) const 215 this->arguments_[index] = arg; 216 } 217 218 /** 219 @brief Returns the evaluated argument with given index. 220 @param index The index of the argument (the first argument has index 0) 221 */ 222 MultiType CommandEvaluation::getEvaluatedArgument(unsigned int index) const 161 223 { 162 224 if (index < MAX_FUNCTOR_ARGUMENTS) 163 return this-> param_[index];225 return this->arguments_[index]; 164 226 165 227 return MT_Type::Null; 166 228 } 167 229 230 /** 231 @brief Completes the given command string using the list of possible arguments. 232 @return Returns the completed command string 233 234 This is called by the shell if the user presses the @a tab key. The currently entered 235 argument will be completed as good as possible by using the argument completion list 236 of the evaluated command. 237 */ 168 238 std::string CommandEvaluation::complete() 169 239 { 240 // check if it's possible to complete the command 170 241 if (!this->hintCommand_ || !this->hintCommand_->isActive()) 171 242 return this->string_; 172 243 244 // get the list of possible arguments 173 245 if (!this->bPossibleArgumentsRetrieved_) 174 246 this->retrievePossibleArguments(); 175 247 248 // if the list is empty, return the current command string 176 249 if (CommandEvaluation::getSize(this->possibleArguments_) == 0) 177 250 { … … 180 253 else 181 254 { 255 // get the first part of the command string from the beginning up to the last space character 182 256 std::string output = this->string_.substr(0, this->string_.find_last_of(' ') + 1); 257 258 // add the common begin of all possible arguments 183 259 output += CommandEvaluation::getCommonBegin(this->possibleArguments_); 260 261 // return the resulting string 184 262 return output; 185 263 } 186 264 } 187 265 266 /** 267 @brief Returns a string containing hints or possible arguments for the evaluated command. 268 269 This is called by the shell if the user presses the @a tab key. It prints a list of 270 possible arguments or other hints, returned by the argument completion list of the 271 evaluated command. If there's no such list, the syntax of the command is returned. 272 */ 188 273 std::string CommandEvaluation::hint() 189 274 { 275 // check if it's possible to get hints for this command 190 276 if (!this->hintCommand_ || !this->hintCommand_->isActive()) 191 277 return ""; 192 278 279 // get the list of possible arguments 193 280 if (!this->bPossibleArgumentsRetrieved_) 194 281 this->retrievePossibleArguments(); 195 282 283 // return the list of possible arguments if: 284 // a) it contains at least one non-empty argument 285 // b) it contains an entry that may be empty (not an actual argument, just a helping text) AND the command is valid 196 286 if (CommandEvaluation::getSize(this->possibleArguments_) > 0 || (!this->possibleArguments_.empty() && this->isValid())) 197 287 return CommandEvaluation::dump(this->possibleArguments_); 198 288 289 // at this point there's no valid argument in the list, so check if the command is actually valid 199 290 if (this->isValid()) 200 291 { 292 // yes it is - return the syntax of the command 201 293 return CommandEvaluation::dump(this->hintCommand_); 202 294 } 203 295 else 204 296 { 297 // no the command is not valid 205 298 if (this->getNumberOfArguments() > 2) 206 299 { 300 // the user typed 2+ arguments, but they don't name a command - print an error 207 301 return std::string("Error: There is no command with name \"") + this->getToken(0) + " " + this->getToken(1) + "\"."; 208 302 } 209 303 else 210 304 { 305 // the user typed 1-2 arguments, check what he tried to type and print a suitable error 211 306 std::string groupLC = getLowercase(this->getToken(0)); 212 307 for (std::map<std::string, std::map<std::string, ConsoleCommand*> >::const_iterator it_group = ConsoleCommand::getCommandsLC().begin(); it_group != ConsoleCommand::getCommandsLC().end(); ++it_group) … … 219 314 } 220 315 316 /** 317 @brief If the command couln't be evaluated because it doesn't exist, print a suggestion for 318 a command that looks close to the entered command (useful if the user mistyped the command). 319 */ 221 320 std::string CommandEvaluation::getCommandSuggestion() const 222 321 { … … 227 326 unsigned int nearestDistance = (unsigned int)-1; 228 327 328 // iterate through all groups and their commands and calculate the distance to the current command. keep the best. 229 329 for (std::map<std::string, std::map<std::string, ConsoleCommand*> >::const_iterator it_group = ConsoleCommand::getCommandsLC().begin(); it_group != ConsoleCommand::getCommandsLC().end(); ++it_group) 230 330 { … … 244 344 } 245 345 346 // now also iterate through all shortcuts and keep the best if it's better than the one found above. 246 347 std::map<std::string, std::map<std::string, ConsoleCommand*> >::const_iterator it_group = ConsoleCommand::getCommandsLC().find(""); 247 348 if (it_group != ConsoleCommand::getCommandsLC().end()) … … 259 360 } 260 361 362 // return the command that's closest to the current one. 261 363 return nearestCommand; 262 364 } 263 365 366 /** 367 @brief Gets the possible arguments for the command in its current state. 368 */ 264 369 void CommandEvaluation::retrievePossibleArguments() 265 370 { 266 371 this->bPossibleArgumentsRetrieved_ = true; 372 373 // we use the hintCommand_ to get possible arguments. get the index of the last argument. limit the index if its greater than the number of arguments supported by the command. 267 374 unsigned int argumentID = std::min(this->getNumberOfArguments() - this->hintArgumentsOffset_, this->hintCommand_->getExecutor()->getParamCount()); 375 376 // get the argument completer for the given argument index 268 377 ArgumentCompleter* ac = this->hintCommand_->getArgumentCompleter(argumentID - 1); 269 378 379 // check if an argument completer exists 270 380 if (ac) 271 381 { 272 MultiType param[MAX_FUNCTOR_ARGUMENTS]; 273 382 MultiType arg[MAX_FUNCTOR_ARGUMENTS]; 383 384 // the index of the last argument in the command string that is supported by this argument completer 274 385 size_t max = this->hintArgumentsOffset_ + this->hintCommand_->getExecutor()->getParamCount(); 275 386 387 // write the argument strings to the argument array (in reversed order, as required by the argument completion function) 276 388 for (size_t i = 0; i < argumentID; ++i) 277 param[i] = this->getToken(std::min(this->getNumberOfArguments(), (unsigned int)max) - i - 1); 278 389 arg[i] = this->getToken(std::min(this->getNumberOfArguments(), (unsigned int)max) - i - 1); 390 391 // check if there are more arguments given by the user than supported 279 392 if (this->getNumberOfArguments() > max) 280 393 { 394 // yes - now check if multiple words are supported by the argument completer 281 395 if (ac->useMultipleWords()) 282 396 { 397 // yes - join the surplus arguments 283 398 std::string surplusArguments = this->tokens_.subSet(max - 1).join(); 284 399 if (this->string_[this->string_.size() - 1] == ' ') 285 400 surplusArguments += ' '; 286 401 287 this->possibleArguments_ = (*ac)(surplusArguments, param[1], param[2], param[3], param[4]); 402 // pass all surplus arguments as the first argument to the argument completer 403 this->possibleArguments_ = (*ac)(surplusArguments, arg[1], arg[2], arg[3], arg[4]); 404 405 // strip the list using the last argument 288 406 CommandEvaluation::strip(this->possibleArguments_, this->getToken(this->getNumberOfArguments() - 1)); 289 407 } 408 else 409 { 410 // no - the user typed more arguments than supported, no action 411 } 290 412 } 291 413 else 292 414 { 293 this->possibleArguments_ = (*ac)(param[0], param[1], param[2], param[3], param[4]); 294 CommandEvaluation::strip(this->possibleArguments_, param[0]); 295 } 296 } 297 } 298 415 // no - so simply call the argument completer and get the list of arguments 416 this->possibleArguments_ = (*ac)(arg[0], arg[1], arg[2], arg[3], arg[4]); 417 418 // strip the list using the last argument (stored arg[0]) 419 CommandEvaluation::strip(this->possibleArguments_, arg[0]); 420 } 421 } 422 } 423 424 /** 425 @brief Returns the size of an argument completion list - empty ("") arguments are not counted. 426 */ 299 427 /* static */ size_t CommandEvaluation::getSize(const ArgumentCompletionList& list) 300 428 { … … 306 434 } 307 435 436 /** 437 @brief Removes all elements from the list that don't start with @a fragment. 438 @param list The argument completion list 439 @param fragment The argument that is currently entered by the user and that needs to be completed 440 */ 308 441 /* static */ void CommandEvaluation::strip(ArgumentCompletionList& list, const std::string& fragment) 309 442 { 310 443 std::string fragmentLC = getLowercase(fragment); 311 444 445 // iterate through the list 312 446 for (ArgumentCompletionList::iterator it = list.begin(); it != list.end(); ) 313 447 { 314 448 const std::string& entry = it->getComparable(); 315 449 450 // check if the argument is empty - if yes, keep it always in the list 316 451 if (entry == "") 317 452 { … … 320 455 } 321 456 457 // check the length of the argument - arguments smaller than 'fragment' are always erased 322 458 if (entry.size() < fragmentLC.size()) 323 459 { … … 326 462 else 327 463 { 464 // compare the argument char by char with 'fragment' 328 465 bool bErase = false; 329 466 for (size_t i = 0; i < fragmentLC.size(); ++i) … … 344 481 } 345 482 483 /** 484 @brief Returns the commond begin of all arguments in the list. 485 */ 346 486 /* static */ std::string CommandEvaluation::getCommonBegin(const ArgumentCompletionList& list) 347 487 { 348 488 if (CommandEvaluation::getSize(list) == 0) 349 489 { 490 // no (non-empty) values in the list, return an empty string 350 491 return ""; 351 492 } 352 493 else if (CommandEvaluation::getSize(list) == 1) 353 494 { 495 // only one (non-empty) value in the list - search it and return it 354 496 for (ArgumentCompletionList::const_iterator it = list.begin(); it != list.end(); ++it) 355 497 { 356 498 if (it->getComparable() != "") 357 499 { 500 // arguments that have a separate string to be displayed need a little more care - just return them without modification. add a space character to the others. 358 501 if (it->hasDisplay()) 359 502 return (it->getString()); … … 367 510 else 368 511 { 512 // multiple arguments in the list - iterate through it and find the common begin of all arguments 369 513 std::string output; 370 514 for (unsigned int i = 0; true; i++) 371 515 { 372 char tempComparable = 0;373 char temp = 0;516 char tempComparable = '\0'; 517 char temp = '\0'; 374 518 for (ArgumentCompletionList::const_iterator it = list.begin(); it != list.end(); ++it) 375 519 { … … 377 521 const std::string& argument = it->getString(); 378 522 523 // ignore empty arguments 379 524 if (argumentComparable == "") 380 525 continue; … … 382 527 if (argument.size() > i) 383 528 { 384 if (tempComparable == 0)529 if (tempComparable == '\0') 385 530 { 531 // the first entry is always taken 386 532 tempComparable = argumentComparable[i]; 387 533 temp = argument[i]; … … 389 535 else 390 536 { 537 // all other entries need comparison to the first entry 391 538 if (tempComparable != argumentComparable[i]) 392 539 return output; 393 else if (temp != argument[i]) 540 else if (temp != argument[i]) // the comparables match, but the normal chars don't - switch to comparable only 394 541 temp = tempComparable; 395 542 } … … 406 553 } 407 554 555 /** 556 @brief Joins the elements of the given list to a string. 557 */ 408 558 /* static */ std::string CommandEvaluation::dump(const ArgumentCompletionList& list) 409 559 { … … 413 563 output += it->getDisplay(); 414 564 565 // add a space character between two elements for all non-empty arguments 415 566 if (it->getComparable() != "") 416 567 output += ' '; … … 419 570 } 420 571 572 /** 573 @brief Returns a string that explains the syntax of the given command. 574 */ 421 575 /* static */ std::string CommandEvaluation::dump(const ConsoleCommand* command) 422 576 { 577 // get the name of the command 423 578 std::string output = command->getName(); 579 580 // check if there are parameters 424 581 if (command->getExecutor()->getParamCount() > 0) 425 582 output += ": "; 426 583 584 // iterate through the parameters 427 585 for (unsigned int i = 0; i < command->getExecutor()->getParamCount(); i++) 428 586 { 587 // separate the parameters with a space character 429 588 if (i != 0) 430 589 output += ' '; 431 590 591 // print default values in [], others in {} braces 432 592 if (command->getExecutor()->defaultValueSet(i)) 433 593 output += '['; … … 435 595 output += '{'; 436 596 597 // add the type-name of the parameter 437 598 output += command->getExecutor()->getTypenameParam(i); 438 599 600 // print the default value if available 439 601 if (command->getExecutor()->defaultValueSet(i)) 440 602 output += '=' + command->getExecutor()->getDefaultValue(i).getString() + ']'; -
code/trunk/src/libraries/core/command/CommandEvaluation.h
r7284 r7401 27 27 */ 28 28 29 /** 30 @defgroup CommandExecEval Command execution and evaluation 31 @ingroup Command 32 */ 33 34 /** 35 @file 36 @ingroup Command CommandExecEval 37 @brief Declaration of the orxonox::CommandEvaluation class which is returned by orxonox::CommandExecutor::evaluate(). 38 39 The orxonox::CommandEvaluation class gathers all information about a command-string. It is used 40 internally by orxonox::CommandExecutor and can also be returned by it to provide more information 41 about a command. It's also possible to evaluate the arguments of a command to execute it faster. 42 43 @see See @ref CommandExecutorExample "this description" for an example. 44 */ 45 29 46 #ifndef _CommandEvaluation_H__ 30 47 #define _CommandEvaluation_H__ … … 41 58 namespace orxonox 42 59 { 60 /** 61 @brief CommandEvaluation is used to gather information about a command and to evaluate its arguments 62 63 This class provides several information about a command-string, for example the 64 evaluated ConsoleCommand, but also other information like hints if the command 65 is not yet finished. 66 67 @note You don't have to call evaluateArguments() manually, it's also done automatically 68 if you call the command the first time. However you can of course do it at any earlier 69 time, for example to return an error message if it doesn't work. 70 71 @remarks execCommand_ and hintCommand_ can be different in this case: There are multiple 72 commands avaliable, let's say "tcl", "tclexecute", and "tclquery". The user enters 73 "tcl", which is already a valid command. Now execCommand_ points to the "tcl"-command, 74 but hintCommand_ still points to the autocompletion command of CommandExecutor, because 75 the auto-completion list must still return the three possible commands, "tcl tclexecute tclquery" 76 because the user may want to execute "tclquery" and needs auto-completion. 77 78 @see See @ref CommandExecutorExample "this description" for an example. 79 */ 43 80 class _CoreExport CommandEvaluation 44 81 { … … 56 93 std::string getCommandSuggestion() const; 57 94 58 int evaluate Params(bool bPrintError = false);95 int evaluateArguments(bool bPrintError = false); 59 96 97 /// Returns true if the command evaluation contains a valid command that can be executed. 60 98 inline bool isValid() const 61 99 { return (this->execCommand_ != 0); } 62 100 101 /// Returns the console command that was evaluated by this object. 63 102 inline const ConsoleCommand* getConsoleCommand() const 64 103 { return this->execCommand_; } 65 104 66 void setEvaluated Parameter(unsigned int index, const MultiType& param);67 MultiType getEvaluated Parameter(unsigned int index) const;105 void setEvaluatedArgument(unsigned int index, const MultiType& arg); 106 MultiType getEvaluatedArgument(unsigned int index) const; 68 107 108 /** 109 @brief Returns a list of possible arguments for the given command. 110 111 Note that the command's arguments may not be complete yet, so in this case 112 this list returns the possibilities. They can then be used to display a list 113 of the possible arguments or to apply auto-completion. 114 */ 69 115 const ArgumentCompletionList& getPossibleArguments() const 70 116 { return this->possibleArguments_; } 71 117 118 /// Returns the number of possible arguments. Empty ("") arguments are not counted. 72 119 size_t getPossibleArgumentsSize() const 73 120 { return CommandEvaluation::getSize(this->possibleArguments_); } … … 90 137 static std::string getCommonBegin(const ArgumentCompletionList& list); 91 138 92 const ConsoleCommand* execCommand_; 93 const ConsoleCommand* hintCommand_; 94 SubString tokens_; 95 std::string string_; 96 unsigned int execArgumentsOffset_; 97 unsigned int hintArgumentsOffset_; 98 bool bPossibleArgumentsRetrieved_; 99 ArgumentCompletionList possibleArguments_; 139 const ConsoleCommand* execCommand_; ///< The command that will be executed (can be NULL if the command is not valid) 140 const ConsoleCommand* hintCommand_; ///< The command that is used to display hints and argument lists (can be different to execCommand_ in some cases) 141 SubString tokens_; ///< The single words of the command string, split into tokens 142 std::string string_; ///< The original command string, entered by the user in the shell 143 unsigned int execArgumentsOffset_; ///< The index of the first argument in tokens_ used to execute the command 144 unsigned int hintArgumentsOffset_; ///< The index of the first argument in tokens_ used to display hints and argument lists 145 bool bPossibleArgumentsRetrieved_; ///< True if the list of possible arguments was already retrieved 146 ArgumentCompletionList possibleArguments_; ///< List of possible arguments for the command in the current state 100 147 101 bool bEvaluated Params_;102 bool bTriedToEvaluated Params_;103 unsigned int numberOfEvaluated Params_;104 MultiType param_[MAX_FUNCTOR_ARGUMENTS];148 bool bEvaluatedArguments_; ///< True if the arguments of the command have been evaluated (and stored in arguments_) 149 bool bTriedToEvaluatedArguments_; ///< True if an attempt was started to evaluate the arguments (but not necessarily successful) 150 unsigned int numberOfEvaluatedArguments_; ///< The number of evaluated arguments (ranges from 0 to MAX_FUNCTOR_ARGUMENTS) 151 MultiType arguments_[MAX_FUNCTOR_ARGUMENTS]; ///< The evaluated arguments (the arguments from string_ or tokens_ converted to the right type) 105 152 }; 106 153 } -
code/trunk/src/libraries/core/command/CommandExecutor.cc
r7284 r7401 27 27 */ 28 28 29 /** 30 @file 31 @brief Implementation of CommandExecutor 32 */ 33 29 34 #include "CommandExecutor.h" 30 35 … … 49 54 .argumentCompleter(1, autocompletion::command()); 50 55 56 /** 57 @brief Returns a reference to the only instance of CommandExecutor. 58 */ 51 59 /* static */ CommandExecutor& CommandExecutor::getInstance() 52 60 { … … 55 63 } 56 64 65 /** 66 @brief Executes a command. 67 @param command A string containing the command 68 @param useTcl If true, the command is passed to tcl (see TclBind) 69 @return Returns the error-code (see @ref CommandExecutorErrorCodes "error codes") 70 */ 57 71 /* static */ int CommandExecutor::execute(const std::string& command, bool useTcl) 58 72 { … … 62 76 } 63 77 78 /** 79 @brief Executes a command and returns its return-value. 80 @param command A string containing the command 81 @param error A pointer to a value (or NULL) where the error-code should be written to (see @ref CommandExecutorErrorCodes "error codes") 82 @param useTcl If true, the command is passed to tcl (see TclBind) 83 @return Returns the return-value of the command (if any - MT_Type::Null otherwise) 84 */ 64 85 /* static */ MultiType CommandExecutor::queryMT(const std::string& command, int* error, bool useTcl) 65 86 { 66 87 if (useTcl) 88 { 89 // pass the command to tcl 67 90 return TclBind::eval(command, error); 91 } 68 92 else 69 93 { 70 94 CommandEvaluation evaluation; 95 96 // try to get the command evaluation from the cache 71 97 if (!CommandExecutor::getInstance().getCached(command, evaluation)) 72 98 { 99 // it wasn't in the cache - evaluate the command 73 100 evaluation = CommandExecutor::evaluate(command); 74 evaluation.evaluateParams(); 101 102 // evaluate its arguments 103 evaluation.evaluateArguments(); 104 105 // write the evaluation to the cache 75 106 CommandExecutor::getInstance().cache(command, evaluation); 76 107 } 77 108 109 // query the command and return its return-value 78 110 return evaluation.query(error); 79 111 } 80 112 } 81 113 114 /** 115 @brief Executes a command and returns its return-value as string. 116 @param command A string containing the command 117 @param error A pointer to a value (or NULL) where the error-code should be written to (see @ref CommandExecutorErrorCodes "error codes") 118 @param useTcl If true, the command is passed to tcl (see TclBind) 119 @return Returns the return-value of the command converted to a string (or "" if there's no return value) 120 */ 82 121 /* static */ std::string CommandExecutor::query(const std::string& command, int* error, bool useTcl) 83 122 { … … 85 124 } 86 125 126 /** 127 @brief Evaluates the given command. 128 @param command A string containing the command 129 @return Returns an instance of CommandEvaluation, which contains the evaluated ConsoleCommand, if the command is valid. 130 131 Evaluates the given command string and returns an instance of CommandEvaluation. 132 If the command is valid, this contains the evaluated ConsoleCommand. Otherwise it 133 can still be used to print hints or complete the command. 134 135 @note Tcl commands can not be evaluated. You have to pass them to execute() or to 136 TclBind directly. 137 */ 87 138 /* static */ CommandEvaluation CommandExecutor::evaluate(const std::string& command) 88 139 { 140 // initialize the command evaluation 89 141 CommandEvaluation evaluation; 90 142 evaluation.initialize(command); 91 143 144 // assign the fallback-command to get hints about the possible commands and groups 92 145 evaluation.hintCommand_ = ConsoleCommand::getCommand(__CC_CommandExecutor_name, __CC_autocomplete_name); 93 146 147 // check if there's at least one argument 94 148 if (evaluation.getNumberOfArguments() >= 1) 95 149 { 150 // try to get a command from the first token 96 151 evaluation.execCommand_ = ConsoleCommand::getCommandLC(evaluation.getToken(0)); 97 152 if (evaluation.execCommand_) … … 99 154 else if (evaluation.getNumberOfArguments() >= 2) 100 155 { 156 // try to get a command from the first two tokens 101 157 evaluation.execCommand_ = ConsoleCommand::getCommandLC(evaluation.getToken(0), evaluation.getToken(1)); 102 158 if (evaluation.execCommand_) … … 105 161 } 106 162 163 // if a valid command was found and the user is already entering arguments, overwrite hintCommand_ with execCommand_ 107 164 if (evaluation.execCommand_ && evaluation.getNumberOfArguments() > evaluation.execArgumentsOffset_) 108 165 { … … 114 171 } 115 172 173 /** 174 @brief Gets an evaluated command from the cache. 175 @param command The command that should be looked up in the cache 176 @param evaluation Reference to a CommandEvaluation that will be used to return the cached evaluation. 177 @return Returns true if the command was found in the cache 178 */ 116 179 bool CommandExecutor::getCached(const std::string& command, CommandEvaluation& evaluation) 117 180 { … … 119 182 return false; 120 183 184 // check if the command is in the cache 121 185 std::map<std::string, CacheEntry>::iterator it = this->cache_.find(command); 122 186 if (it != this->cache_.end()) … … 134 198 } 135 199 200 /** 201 @brief Writes a command evaluation for a given command to the cache. 202 */ 136 203 void CommandExecutor::cache(const std::string& command, const CommandEvaluation& evaluation) 137 204 { … … 156 223 } 157 224 225 /** 226 @brief This function is used as console command which executes commands that are usually hidden. 227 228 The argument completion function of this console commands is used to find 229 and enter hidden commands and their arguments. 230 */ 158 231 /* static */ MultiType CommandExecutor::unhide(const std::string& command) 159 232 { … … 161 234 } 162 235 236 /** 237 @brief This function is used as console command which saves a command and optionally also it's arguments as a new console command with a new name. 238 @param alias The name of the new command alias 239 @param command The existing command and (optionally) its arguments 240 */ 163 241 /* static */ void CommandExecutor::alias(const std::string& alias, const std::string& command) 164 242 { 243 // first check if the given command is valid, else print an error 165 244 CommandEvaluation evaluation = CommandExecutor::evaluate(command); 166 245 if (evaluation.isValid()) 167 246 { 247 // it is valid - copy the executor of this command 168 248 ExecutorPtr executor = new Executor(*evaluation.getConsoleCommand()->getExecutor().get()); 169 249 170 if (!evaluation.evaluateParams()) 250 // evaluate the arguments and if this returns no error, store them as default values 251 if (!evaluation.evaluateArguments()) 171 252 { 172 253 for (size_t i = 0; i < MAX_FUNCTOR_ARGUMENTS; ++i) 173 executor->setDefaultValue(i, evaluation.getEvaluatedParameter(i)); 174 } 175 254 executor->setDefaultValue(i, evaluation.getEvaluatedArgument(i)); 255 } 256 257 // split the alias in tokens 176 258 SubString tokens(alias, " "); 177 259 260 // check if the alias already exists - print an error and return if it does 178 261 if ((tokens.size() == 1 && ConsoleCommand::getCommand(tokens[0])) || (tokens.size() == 2 && ConsoleCommand::getCommand(tokens[0], tokens[1]))) 179 262 { … … 182 265 } 183 266 267 // create a new console command with the given alias as its name 184 268 if (tokens.size() == 1) 185 269 createConsoleCommand(tokens[0], executor); -
code/trunk/src/libraries/core/command/CommandExecutor.h
r7284 r7401 27 27 */ 28 28 29 /** 30 @file 31 @ingroup Command CommandExecEval 32 @brief Declaration of the orxonox::CommandExecutor class which is used to execute and evaluate @ref orxonox::ConsoleCommand "console commands". 33 34 @anchor CommandExecutorExample 35 36 orxonox::CommandExecutor can be used to execute console commands (see orxonox::ConsoleCommand). 37 Commands are strings that can be entered by the user in the shell or they can be part of a 38 script. 39 40 A command can be passed to orxonox::CommandExecutor::execute() which will execute them - eiter 41 directly, or - if requested - passes it to Tcl. See orxonox::TclBind for more information. 42 Appart from execute() the command can also be passed to orxonox::CommandExecutor::query() which 43 behaves the same except for that it returns the return value of the command. 44 45 If you don't want to execute the command, but rather gather more information about it, pass it 46 to orxonox::CommandExecutor::evaluate(). This function returns an instance of 47 orxonox::CommandEvaluation. This class provides more information about the command, for example 48 the evaluated instance of orxonox::ConsoleCommand. Its also possible to gather hints about the 49 command or to complete the command-string by using argument completion functions. More than that 50 the command evaluation can also evaluate the arguments, which allows faster execution of the 51 command. 52 53 Example: 54 @code 55 CommandExecutor::execute("log test"); // writes "test" to the console 56 CommandExecutor::execute("log [expr 1+1]"); // writes "2" to the console - expr is a Tcl command 57 58 CommandExecutor::query("expr 1+1"); // returns "2" 59 CommandExecutor::queryMT("expr 1+1"); // returns 2 60 @endcode 61 62 And another example about how to use evaluate(): 63 @code 64 CommandEvaluation evaluation; 65 evaluation = CommandExecutor::evaluate("log test"); // returns an evaluation of "log test" 66 67 evaluation.execute(); // writes "test" to the console 68 evaluation.hint(); // returns "log: {string}" 69 @endcode 70 71 @anchor CommandExecutorErrorCodes 72 73 @b Error @b codes: 74 75 orxonox::CommandExecutor defines a number of error codes that are returned 76 by different functions that operate with commands: 77 78 - CommandExecutor::Success: No error 79 - CommandExecutor::Error: The command doesn't exist 80 - CommandExecutor::Incomplete: The command needs more arguments 81 - CommandExecutor::Deactivated: The command is not active 82 - CommandExecutor::Denied: The command needs a different @ref orxonox::AccessLevel "access level" 83 */ 84 29 85 #ifndef _CommandExecutor_H__ 30 86 #define _CommandExecutor_H__ … … 42 98 namespace orxonox 43 99 { 100 /** 101 @brief This class is used to execute and evaluate command-strings. 102 103 CommandExecutor executes command-strings and returns evaluated commands. It's 104 also possible to execute Tcl commands if the corresponding argument of execute() 105 is true. 106 107 @see See @ref CommandExecutorExample "this description" for more information and some examples. 108 */ 44 109 class _CoreExport CommandExecutor 45 110 { … … 53 118 static CommandEvaluation evaluate(const std::string& command); 54 119 55 static const int Success = 0; 56 static const int Error = 1; 57 static const int Incomplete = 2; 58 static const int Deactivated = 3; 59 static const int Denied = 4; 120 static const int Success = 0; ///< Error code for "success" (or no error) 121 static const int Error = 1; ///< Error code if the command doesn't exist 122 static const int Incomplete = 2; ///< Error code if the command needs more arguments 123 static const int Deactivated = 3; ///< Error code if the command is not active 124 static const int Denied = 4; ///< Error code if the command needs a different access level 60 125 61 126 static MultiType unhide(const std::string& command); 62 127 static void alias(const std::string& alias, const std::string& command); 63 static void _autocomplete(const std::string& group, const std::string& name) {} 128 static void _autocomplete(const std::string& group, const std::string& name) {} ///< Pseudo console command used whenever no real command is available. In these cases this command provides auto-completion for console commands and groups. 64 129 65 130 private: 66 CommandExecutor() {} 67 CommandExecutor(const CommandExecutor& other); 68 ~CommandExecutor() {} 131 CommandExecutor() {} ///< Empty constructor 132 CommandExecutor(const CommandExecutor& other); ///< Not implemented copy-constructor 133 ~CommandExecutor() {} ///< Empty destructor 69 134 70 135 static CommandExecutor& getInstance(); … … 73 138 void cache(const std::string& command, const CommandEvaluation& evaluation); 74 139 140 /// Helper struct, used to store cached entries 75 141 struct CacheEntry 76 142 { 77 CommandEvaluation evaluation_; 78 std::list<std::string>::iterator iterator_; 143 CommandEvaluation evaluation_; ///< The command evaluation which is stored in the cache 144 std::list<std::string>::iterator iterator_; ///< The iterator of the corresponding element in cachelist_, used for faster access 79 145 }; 80 146 81 std::map<std::string, CacheEntry> cache_; 82 std::list<std::string> cachelist_; 147 std::map<std::string, CacheEntry> cache_; ///< A map that connects command strings and evaluated commands in the cache 148 std::list<std::string> cachelist_; ///< A list used to sort the elements in the cache by their age 83 149 }; // tolua_export 84 150 } // tolua_export -
code/trunk/src/libraries/core/command/ConsoleCommand.cc
r7284 r7401 27 27 */ 28 28 29 /** 30 @file 31 @brief Implementation of the ConsoleCommand class. 32 */ 33 29 34 #include "ConsoleCommand.h" 30 35 … … 36 41 namespace orxonox 37 42 { 43 /** 44 @brief Constructor: Initializes all values and registers the command. 45 @param group The group of the command 46 @param name The name of the command 47 @param executor The executor of the command 48 @param bInitialized If true, the executor is used for both, the definition of the function-header AND to executute the command. If false, the command is inactive and needs to be assigned a function before it can be used. 49 */ 38 50 ConsoleCommand::ConsoleCommand(const std::string& group, const std::string& name, const ExecutorPtr& executor, bool bInitialized) 39 51 { … … 45 57 this->baseFunctor_ = executor->getFunctor(); 46 58 47 this->argumentCompleter_[0] = 0; 48 this->argumentCompleter_[1] = 0; 49 this->argumentCompleter_[2] = 0; 50 this->argumentCompleter_[3] = 0; 51 this->argumentCompleter_[4] = 0; 59 for (size_t i = 0; i < MAX_FUNCTOR_ARGUMENTS; ++i) 60 this->argumentCompleter_[i] = 0; 52 61 53 62 this->keybindMode_ = KeybindMode::OnPress; … … 60 69 } 61 70 71 /** 72 @brief Destructor: Unregisters the command. 73 */ 62 74 ConsoleCommand::~ConsoleCommand() 63 75 { … … 65 77 } 66 78 79 /** 80 @brief Registers the command with the same name, but without group, as shortcut. 81 */ 67 82 ConsoleCommand& ConsoleCommand::addShortcut() 68 83 { … … 71 86 } 72 87 88 /** 89 @brief Registers the command with an alias as shortcut. 90 */ 73 91 ConsoleCommand& ConsoleCommand::addShortcut(const std::string& name) 74 92 { … … 77 95 } 78 96 97 /** 98 @brief Registers the command in a different group but with the same name. 99 */ 79 100 ConsoleCommand& ConsoleCommand::addGroup(const std::string& group) 80 101 { … … 83 104 } 84 105 106 /** 107 @brief Registers an alias of the command in a different group with a different name. 108 */ 85 109 ConsoleCommand& ConsoleCommand::addGroup(const std::string& group, const std::string& name) 86 110 { … … 89 113 } 90 114 115 /** 116 @brief Returns true if the command can be executed right now. 117 118 This returns only true, if the following conditions are met: 119 - The command is active 120 - The command has an executor 121 - The executor has a functor 122 - The functor is static or has an object 123 */ 91 124 bool ConsoleCommand::isActive() const 92 125 { … … 94 127 } 95 128 129 /** 130 @brief Returns true if the current state of the game matches the required access level. 131 */ 96 132 bool ConsoleCommand::hasAccess() const 97 133 { … … 101 137 case AccessLevel::Standalone: return GameMode::isStandalone(); 102 138 case AccessLevel::Master: return GameMode::isMaster(); 103 case AccessLevel::Server: return GameMode:: hasServer();139 case AccessLevel::Server: return GameMode::isServer(); 104 140 case AccessLevel::Client: return GameMode::isClient(); 105 case AccessLevel::Online: return (GameMode:: hasServer() || GameMode::isClient());141 case AccessLevel::Online: return (GameMode::isServer() || GameMode::isClient()); 106 142 case AccessLevel::Offline: return GameMode::isStandalone(); 107 143 case AccessLevel::None: return false; … … 110 146 } 111 147 148 /** 149 @brief Returns true if the headers of the given functor match the declaration of this command. 150 */ 112 151 bool ConsoleCommand::headersMatch(const FunctorPtr& functor) 113 152 { 153 // get the minimum of the number of parameters of both commands 114 154 unsigned int minparams = std::min(this->baseFunctor_->getParamCount(), functor->getParamCount()); 115 155 156 // if the reduced headers don't match -> return false 116 157 if (this->baseFunctor_->getHeaderIdentifier(minparams) != functor->getHeaderIdentifier(minparams)) 117 158 return false; 159 // if the reduced headers match and the new functor has less or equal parameters -> return true 118 160 else if (functor->getParamCount() <= this->baseFunctor_->getParamCount()) 119 161 return true; 162 // the headers match but the new functor has more arguments and there is no executor with default-values -> return false 120 163 else if (!this->executor_) 121 164 return false; 165 // the headers match but the new functor has more arguments, check if the executor has enough default-values 122 166 else 123 167 { … … 135 179 } 136 180 181 /** 182 @brief Returns true if the headers of the given executor match the declaration of this command. 183 */ 137 184 bool ConsoleCommand::headersMatch(const ExecutorPtr& executor) 138 185 { 186 // get the minimum of the number of parameters of both commands 139 187 unsigned int minparams = std::min(this->baseFunctor_->getParamCount(), executor->getParamCount()); 140 188 189 // if the reduced headers don't match -> return false 141 190 if (this->baseFunctor_->getHeaderIdentifier(minparams) != executor->getFunctor()->getHeaderIdentifier(minparams)) 142 191 return false; 192 // if the reduced headers match and the new functor has less or equal parameters -> return true 143 193 else if (executor->getParamCount() <= this->baseFunctor_->getParamCount()) 144 194 return true; 195 // the headers match but the new functor has more arguments, check if the new executor has enough default-values 145 196 else 146 197 { … … 158 209 } 159 210 211 /** 212 @brief Changes the executor. 213 @param executor The new executor 214 @param bForce If true, the executor is always assigned, even if the headers don't match 215 @return Returns true if the assignment was successful 216 */ 160 217 bool ConsoleCommand::setFunction(const ExecutorPtr& executor, bool bForce) 161 218 { 219 // assign the executor if a) it's a null-pointer, b) its functor is a null-pointer, c) it's forced, d) the headers match 162 220 if (!executor || !executor->getFunctor() || bForce || this->headersMatch(executor)) 163 221 { 222 // assign the executor and clear the object stack (because it's also a new function) 164 223 this->executor_ = executor; 165 224 this->objectStack_.clear(); … … 173 232 } 174 233 234 /** 235 @brief Changes the functor of the current executor. 236 @param functor The new functor 237 @param bForce If true, the functor is always assigned, even if the headers don't match 238 @return Returns true if the assignment was successful 239 */ 175 240 bool ConsoleCommand::setFunction(const FunctorPtr& functor, bool bForce) 176 241 { 242 // assign the functor if a) it's a null-pointer, b) it's forced, c) the headers match 177 243 if (!functor || bForce || this->headersMatch(functor)) 178 244 { 245 // assign the functor (create a new executor if necessary) and clear the object stack 179 246 if (this->executor_) 180 247 this->executor_->setFunctor(functor); … … 192 259 } 193 260 261 /** 262 @brief Pushes a new executor to the command-stack. 263 @param executor The new executor 264 @param bForce If true, the executor is always assigned, even if the headers don't match 265 */ 194 266 void ConsoleCommand::pushFunction(const ExecutorPtr& executor, bool bForce) 195 267 { 268 // prepare the old function to be put on the stack 196 269 Command command; 197 270 command.executor_ = this->executor_; … … 200 273 command.objectStack_ = this->objectStack_; 201 274 275 // check if the new executor can be assigned and push the old function to the stack 202 276 if (this->setFunction(executor, bForce)) 203 277 this->commandStack_.push(command); 204 278 } 205 279 280 /** 281 @brief Pushes a new functor to the command-stack. 282 @param functor The new functor 283 @param bForce If true, the functor is always assigned, even if the headers don't match 284 */ 206 285 void ConsoleCommand::pushFunction(const FunctorPtr& functor, bool bForce) 207 286 { 287 // prepare the old function to be put on the stack 208 288 Command command; 209 289 command.executor_ = this->executor_; … … 212 292 command.objectStack_ = this->objectStack_; 213 293 294 // check if the new functor can be assigned and push the old function to the stack 214 295 if (this->setFunction(functor, bForce)) 215 296 this->commandStack_.push(command); 216 297 } 217 298 299 /** 300 @brief Pushes a copy of the current executor and functor on the stack. 301 */ 218 302 void ConsoleCommand::pushFunction() 219 303 { … … 224 308 } 225 309 310 /** 311 @brief Removes the current function from the stack and restores the old state. 312 */ 226 313 void ConsoleCommand::popFunction() 227 314 { 228 315 Command command; 316 317 // check if there's a function on the stack 229 318 if (!this->commandStack_.empty()) 230 319 { 320 // yes it is - assign it to command and remove it from the stack 231 321 command = this->commandStack_.top(); 232 322 this->commandStack_.pop(); 233 323 } 234 324 325 // restore the old executor (and also restore its functor in case this was changed in the meantime) 235 326 this->executor_ = command.executor_; 236 327 if (command.executor_) … … 239 330 } 240 331 332 /** 333 @brief Sets the functor to NULL (which also deactivates the command). 334 */ 241 335 void ConsoleCommand::resetFunction() 242 336 { … … 246 340 } 247 341 342 /** 343 @brief Returns the current executor which can be used to execute the command. 344 */ 248 345 const ExecutorPtr& ConsoleCommand::getExecutor() const 249 346 { … … 251 348 } 252 349 350 /** 351 @brief Changes the current object that is used to execute member-functions. 352 @return Returns true if the object was successfully changed 353 */ 253 354 bool ConsoleCommand::setObject(void* object) 254 355 { 255 if (this->executor_) 256 { 356 // check if there's an executor 357 if (this->executor_) 358 { 359 // check if there's a functor 257 360 if (this->executor_->getFunctor()) 258 361 { 362 // change the object 259 363 this->executor_->getFunctor()->setRawObjectPointer(object); 260 364 return true; … … 269 373 } 270 374 375 /** 376 @brief Push a new object to the object-stack. 377 */ 271 378 void ConsoleCommand::pushObject(void* object) 272 379 { … … 276 383 } 277 384 385 /** 386 @brief Removes the current object from the stack an restores the old object. 387 */ 278 388 void ConsoleCommand::popObject() 279 389 { … … 287 397 } 288 398 399 /** 400 @brief Returns the current object pointer that is used to execute member-functions. 401 */ 289 402 void* ConsoleCommand::getObject() const 290 403 { … … 295 408 } 296 409 297 ConsoleCommand& ConsoleCommand::defaultValues(const MultiType& param1) 298 { 299 if (this->executor_) 300 this->executor_->setDefaultValues(param1); 410 /** 411 @brief Changes the default values of the current executor. 412 */ 413 ConsoleCommand& ConsoleCommand::defaultValues(const MultiType& arg1) 414 { 415 if (this->executor_) 416 this->executor_->setDefaultValues(arg1); 301 417 else 302 418 COUT(1) << "Error: Can't set default values in console command \"" << this->baseName_ << "\", no executor set." << std::endl; … … 305 421 } 306 422 307 ConsoleCommand& ConsoleCommand::defaultValues(const MultiType& param1, const MultiType& param2) 308 { 309 if (this->executor_) 310 this->executor_->setDefaultValues(param1, param2); 423 /** 424 @brief Changes the default values of the current executor. 425 */ 426 ConsoleCommand& ConsoleCommand::defaultValues(const MultiType& arg1, const MultiType& arg2) 427 { 428 if (this->executor_) 429 this->executor_->setDefaultValues(arg1, arg2); 311 430 else 312 431 COUT(1) << "Error: Can't set default values in console command \"" << this->baseName_ << "\", no executor set." << std::endl; … … 315 434 } 316 435 317 ConsoleCommand& ConsoleCommand::defaultValues(const MultiType& param1, const MultiType& param2, const MultiType& param3) 318 { 319 if (this->executor_) 320 this->executor_->setDefaultValues(param1, param2, param3); 436 /** 437 @brief Changes the default values of the current executor. 438 */ 439 ConsoleCommand& ConsoleCommand::defaultValues(const MultiType& arg1, const MultiType& arg2, const MultiType& arg3) 440 { 441 if (this->executor_) 442 this->executor_->setDefaultValues(arg1, arg2, arg3); 321 443 else 322 444 COUT(1) << "Error: Can't set default values in console command \"" << this->baseName_ << "\", no executor set." << std::endl; … … 325 447 } 326 448 327 ConsoleCommand& ConsoleCommand::defaultValues(const MultiType& param1, const MultiType& param2, const MultiType& param3, const MultiType& param4) 328 { 329 if (this->executor_) 330 this->executor_->setDefaultValues(param1, param2, param3, param4); 449 /** 450 @brief Changes the default values of the current executor. 451 */ 452 ConsoleCommand& ConsoleCommand::defaultValues(const MultiType& arg1, const MultiType& arg2, const MultiType& arg3, const MultiType& arg4) 453 { 454 if (this->executor_) 455 this->executor_->setDefaultValues(arg1, arg2, arg3, arg4); 331 456 else 332 457 COUT(1) << "Error: Can't set default values in console command \"" << this->baseName_ << "\", no executor set." << std::endl; … … 335 460 } 336 461 337 ConsoleCommand& ConsoleCommand::defaultValues(const MultiType& param1, const MultiType& param2, const MultiType& param3, const MultiType& param4, const MultiType& param5) 338 { 339 if (this->executor_) 340 this->executor_->setDefaultValues(param1, param2, param3, param4, param5); 462 /** 463 @brief Changes the default values of the current executor. 464 */ 465 ConsoleCommand& ConsoleCommand::defaultValues(const MultiType& arg1, const MultiType& arg2, const MultiType& arg3, const MultiType& arg4, const MultiType& arg5) 466 { 467 if (this->executor_) 468 this->executor_->setDefaultValues(arg1, arg2, arg3, arg4, arg5); 341 469 else 342 470 COUT(1) << "Error: Can't set default values in console command \"" << this->baseName_ << "\", no executor set." << std::endl; … … 345 473 } 346 474 347 ConsoleCommand& ConsoleCommand::defaultValue(unsigned int index, const MultiType& param) 348 { 349 if (this->executor_) 350 this->executor_->setDefaultValue(index, param); 475 /** 476 @brief Changes the default value of the argument with given index of the current executor. 477 @param index The index of the argument (the first argument has index 0) 478 @param arg The new default value 479 */ 480 ConsoleCommand& ConsoleCommand::defaultValue(unsigned int index, const MultiType& arg) 481 { 482 if (this->executor_) 483 this->executor_->setDefaultValue(index, arg); 351 484 else 352 485 COUT(1) << "Error: Can't set default values in console command \"" << this->baseName_ << "\", no executor set." << std::endl; … … 355 488 } 356 489 357 ConsoleCommand& ConsoleCommand::argumentCompleter(unsigned int param, ArgumentCompleter* completer) 358 { 359 if (param < 5) 360 this->argumentCompleter_[param] = completer; 361 else 362 COUT(2) << "Warning: Couldn't add autocompletion-function for param " << param << " in console command \"" << this->baseName_ << "\": index out of bound." << std::endl; 363 364 return *this; 365 } 366 367 ArgumentCompleter* ConsoleCommand::getArgumentCompleter(unsigned int param) const 368 { 369 if (param < 5) 370 return this->argumentCompleter_[param]; 490 /** 491 @brief Changes the argument completer for the given argument. 492 @param index The index of the argument (the first argument has index 0) 493 @param completer The new argument completer 494 */ 495 ConsoleCommand& ConsoleCommand::argumentCompleter(unsigned int index, ArgumentCompleter* completer) 496 { 497 if (index < 5) 498 this->argumentCompleter_[index] = completer; 499 else 500 COUT(2) << "Warning: Couldn't add autocompletion-function for index " << index << " in console command \"" << this->baseName_ << "\": index out of bound." << std::endl; 501 502 return *this; 503 } 504 505 /** 506 @brief Returns the argument completer for the argument with given index. 507 */ 508 ArgumentCompleter* ConsoleCommand::getArgumentCompleter(unsigned int index) const 509 { 510 if (index < 5) 511 return this->argumentCompleter_[index]; 371 512 else 372 513 return 0; 373 514 } 374 515 516 /** 517 @brief Sets the description of this command. 518 */ 375 519 ConsoleCommand& ConsoleCommand::description(const std::string& description) 376 520 { … … 380 524 } 381 525 526 /** 527 @brief Returns the description of this command. 528 */ 382 529 const std::string& ConsoleCommand::getDescription() const 383 530 { … … 385 532 } 386 533 387 ConsoleCommand& ConsoleCommand::descriptionParam(unsigned int param, const std::string& description) 388 { 389 if (param < MAX_FUNCTOR_ARGUMENTS) 390 { 391 this->descriptionParam_[param] = std::string("ConsoleCommandDescription::" + this->baseName_ + "::param" + multi_cast<std::string>(param)); 392 AddLanguageEntry(this->descriptionParam_[param], description); 393 } 394 return *this; 395 } 396 397 const std::string& ConsoleCommand::getDescriptionParam(unsigned int param) const 398 { 399 if (param < MAX_FUNCTOR_ARGUMENTS) 400 return GetLocalisation_noerror(this->descriptionParam_[param]); 534 /** 535 @brief Sets the description for an argument with given index. 536 */ 537 ConsoleCommand& ConsoleCommand::descriptionParam(unsigned int index, const std::string& description) 538 { 539 if (index < MAX_FUNCTOR_ARGUMENTS) 540 { 541 this->descriptionParam_[index] = std::string("ConsoleCommandDescription::" + this->baseName_ + "::param" + multi_cast<std::string>(index)); 542 AddLanguageEntry(this->descriptionParam_[index], description); 543 } 544 return *this; 545 } 546 547 /** 548 @brief Returns the description for the argument with given index. 549 */ 550 const std::string& ConsoleCommand::getDescriptionParam(unsigned int index) const 551 { 552 if (index < MAX_FUNCTOR_ARGUMENTS) 553 return GetLocalisation_noerror(this->descriptionParam_[index]); 401 554 402 555 return this->descriptionParam_[0]; 403 556 } 404 557 558 /** 559 @brief Sets the description for the return-value. 560 */ 405 561 ConsoleCommand& ConsoleCommand::descriptionReturnvalue(const std::string& description) 406 562 { … … 410 566 } 411 567 412 const std::string& ConsoleCommand::getDescriptionReturnvalue(int param) const 568 /** 569 @brief Returns the description for the return-value. 570 */ 571 const std::string& ConsoleCommand::getDescriptionReturnvalue(int index) const 413 572 { 414 573 return GetLocalisation_noerror(this->descriptionReturnvalue_); 415 574 } 416 575 576 /** 577 @brief Returns the command with given group an name. 578 @param group The group of the requested command 579 @param name The group of the requested command 580 @param bPrintError If true, an error is printed if the command doesn't exist 581 */ 417 582 /* static */ const ConsoleCommand* ConsoleCommand::getCommand(const std::string& group, const std::string& name, bool bPrintError) 418 583 { 584 // find the group 419 585 std::map<std::string, std::map<std::string, ConsoleCommand*> >::const_iterator it_group = ConsoleCommand::getCommandMap().find(group); 420 586 if (it_group != ConsoleCommand::getCommandMap().end()) 421 587 { 588 // find the name 422 589 std::map<std::string, ConsoleCommand*>::const_iterator it_name = it_group->second.find(name); 423 590 if (it_name != it_group->second.end()) 424 591 { 592 // return the pointer 425 593 return it_name->second; 426 594 } … … 436 604 } 437 605 606 /** 607 @brief Returns the command with given group an name in lowercase. 608 @param group The group of the requested command in lowercase 609 @param name The group of the requested command in lowercase 610 @param bPrintError If true, an error is printed if the command doesn't exist 611 */ 438 612 /* static */ const ConsoleCommand* ConsoleCommand::getCommandLC(const std::string& group, const std::string& name, bool bPrintError) 439 613 { … … 441 615 std::string nameLC = getLowercase(name); 442 616 617 // find the group 443 618 std::map<std::string, std::map<std::string, ConsoleCommand*> >::const_iterator it_group = ConsoleCommand::getCommandMapLC().find(groupLC); 444 619 if (it_group != ConsoleCommand::getCommandMapLC().end()) 445 620 { 621 // find the name 446 622 std::map<std::string, ConsoleCommand*>::const_iterator it_name = it_group->second.find(nameLC); 447 623 if (it_name != it_group->second.end()) 448 624 { 625 // return the pointer 449 626 return it_name->second; 450 627 } … … 460 637 } 461 638 639 /** 640 @brief Returns the static map that stores all console commands. 641 */ 462 642 /* static */ std::map<std::string, std::map<std::string, ConsoleCommand*> >& ConsoleCommand::getCommandMap() 463 643 { … … 466 646 } 467 647 648 /** 649 @brief Returns the static map that stores all console commands in lowercase. 650 */ 468 651 /* static */ std::map<std::string, std::map<std::string, ConsoleCommand*> >& ConsoleCommand::getCommandMapLC() 469 652 { … … 472 655 } 473 656 657 /** 658 @brief Registers a new command with given group an name by adding it to the command map. 659 */ 474 660 /* static */ void ConsoleCommand::registerCommand(const std::string& group, const std::string& name, ConsoleCommand* command) 475 661 { … … 477 663 return; 478 664 665 // check if a command with this name already exists 479 666 if (ConsoleCommand::getCommand(group, name) != 0) 480 667 { … … 486 673 else 487 674 { 675 // add the command to the map 488 676 ConsoleCommand::getCommandMap()[group][name] = command; 489 677 ConsoleCommand::getCommandMapLC()[getLowercase(group)][getLowercase(name)] = command; … … 491 679 } 492 680 681 /** 682 @brief Removes the command from the command map. 683 */ 493 684 /* static */ void ConsoleCommand::unregisterCommand(ConsoleCommand* command) 494 685 { 686 // iterate through all groups 495 687 for (std::map<std::string, std::map<std::string, ConsoleCommand*> >::iterator it_group = ConsoleCommand::getCommandMap().begin(); it_group != ConsoleCommand::getCommandMap().end(); ) 496 688 { 689 // iterate through all commands of each group 497 690 for (std::map<std::string, ConsoleCommand*>::iterator it_name = it_group->second.begin(); it_name != it_group->second.end(); ) 498 691 { 692 // erase the command 499 693 if (it_name->second == command) 500 694 it_group->second.erase(it_name++); … … 503 697 } 504 698 699 // erase the group if it is empty now 505 700 if (it_group->second.empty()) 506 701 ConsoleCommand::getCommandMap().erase(it_group++); … … 509 704 } 510 705 706 // now the same for the lowercase-map: 707 708 // iterate through all groups 511 709 for (std::map<std::string, std::map<std::string, ConsoleCommand*> >::iterator it_group = ConsoleCommand::getCommandMapLC().begin(); it_group != ConsoleCommand::getCommandMapLC().end(); ) 512 710 { 711 // iterate through all commands of each group 513 712 for (std::map<std::string, ConsoleCommand*>::iterator it_name = it_group->second.begin(); it_name != it_group->second.end(); ) 514 713 { 714 // erase the command 515 715 if (it_name->second == command) 516 716 it_group->second.erase(it_name++); … … 519 719 } 520 720 721 // erase the group if it is empty now 521 722 if (it_group->second.empty()) 522 723 ConsoleCommand::getCommandMapLC().erase(it_group++); … … 526 727 } 527 728 729 /** 730 @brief Deletes all commands 731 */ 528 732 /* static */ void ConsoleCommand::destroyAll() 529 733 { 734 // delete entries until the map is empty 530 735 while (!ConsoleCommand::getCommandMap().empty() && !ConsoleCommand::getCommandMap().begin()->second.empty()) 531 736 delete ConsoleCommand::getCommandMap().begin()->second.begin()->second; -
code/trunk/src/libraries/core/command/ConsoleCommand.h
r7284 r7401 27 27 */ 28 28 29 /** 30 @defgroup ConsoleCommand Console commands 31 @ingroup Command 32 */ 33 34 /** 35 @file 36 @ingroup Command ConsoleCommand 37 @brief Declaration of the orxonox::ConsoleCommand class and the SetConsoleCommand() macro. 38 39 @anchor ConsoleCommandExample 40 41 Console commands can be used to write scripts, use key-bindings or simply to be 42 entered into the shell by the user. Instances of orxonox::ConsoleCommand define 43 the function of a command, and also more information like, for example, if it is 44 active, default values, and possible arguments. 45 46 Commands need to be registered to the system statically on startup by using the 47 SetConsoleCommand() or DeclareConsoleCommand() macros outside of a function. 48 This ensures that commands are known to the system at any time, so they can be 49 evaluated (see orxonox::CommandExecutor::evaluate()), for example for key-bindings. 50 51 Example: 52 @code 53 void myCoutFunction(const std::string& text) // Define a static function 54 { 55 COUT(0) << "Text: " << text << std::endl; // Print the text to the console 56 } 57 58 SetConsoleCommand("cout", &myCoutFunction); // Register the function as command with name "cout" 59 @endcode 60 61 Now you can open the shell and execute the command: 62 @code 63 $ cout Hello World 64 @endcode 65 66 Internally this command is now passed to orxonox::CommandExecutor::execute(): 67 @code 68 CommandExecutor::execute("cout HelloWorld"); 69 @endcode 70 71 CommandExecutor searches for a command with name "cout" and passes the arguments 72 "Hello World" to it. Because we registered myCoutFunction() with this command, 73 as a result the following text will be printed to the console: 74 @code 75 Text: Hello World 76 @endcode 77 78 You can add more attributes to the ConsoleCommand, by using the command-chain feature 79 of SetConsoleCommand(). For example like this: 80 @code 81 SetConsoleCommand("cout", &myCoutFunction) 82 .addGroup("output", "text") 83 .accessLevel(AccessLevel::Offline) 84 .defaultValues("no text"); 85 @endcode 86 87 Open the shell again and try it: 88 @code 89 $ cout Hello World 90 Text: Hello World 91 $ output text Hello World 92 Text: Hello World 93 $ cout 94 Text: no text 95 @endcode 96 97 If you execute it online (note: the access level is "Offline"), you will see the 98 following (or something similar): 99 @code 100 $ cout Hello World 101 Error: Can't execute command "cout", access denied. 102 @endcode 103 104 If a command is executed, the arguments are passed to an underlying function, 105 whitch is wrapped by an orxonox::Functor which again is wrapped by an orxonox::Executor. 106 The Functor contains the function-pointer, as well as the object-pointer in 107 case of a non-static member-function. The executor stores possible default-values 108 for each argument of the function. 109 110 The function of a command can be changed at any time. It's possible to just exchange 111 the function-pointer of the underlying Functor if the headers of the functions are 112 exactly the same. But you can also exchange the Functor itself or even completely 113 replace the Executor. Also the other attributes of a ConsoleCommand can be modified 114 during the game, for example it can be activated or deactivated. 115 116 To do so, the function ModifyConsoleCommand() has to be used. It returns an instance 117 of orxonox::ConsoleCommand::ConsoleCommandManipulator which has an interface similar to 118 orxonox::ConsoleCommand, but with slight differences. You can use it the same way like 119 SetConsoleCommand(), meaning you can use command-chains to change different attributes at 120 the same time. ModifyConsoleCommand() must not be executed statically, but rather in a 121 function at some point of the execution of the program. 122 123 Example: 124 @code 125 void myOtherCoutFunction(const std::string& text) // Define a new static function 126 { 127 COUT(0) << "Uppercase: " << getUppercase(text) << std::endl; // Print the text in uppercase to the console 128 } 129 130 { 131 // ... // somewhere in the code 132 133 ModifyConsoleCommand("cout").setFunction(&myOtherCoutFunction); // Modify the underlying function of the command 134 135 // ... 136 } 137 @endcode 138 139 If you now enter the command into the shell, you'll see a different behavior: 140 @code 141 $ cout Hello World 142 Uppercase: HELLO WORLD 143 $ cout 144 Uppercase: NO TEXT 145 @endcode 146 147 A few important notes about changing functions: 148 149 Instead of changing the function with setFunction(), you can also create a command-stack 150 by using pushFunction() and popFunction(). It's important to note a few things about that, 151 because the underlying structure of Executor and Functor has a few pitfalls: 152 - If you push a new function-pointer, the same executor as before will be used (and, if 153 the headers match, even the same functor can be used, which is very fast) 154 - If you push a new Functor, the same executor as before will be used 155 - If you push a new Executor, everything is changed 156 157 Note that the executor contains the @b default @b values, so if you just exchange the 158 Functor, the default values remain the same. However if you decide to change the default 159 values at any point of the stack, <b>this will also change the default values on all 160 other stack-levels</b> that share the same executor. If you don't like this behavior, 161 you have to explicitly push a new executor before changing the default values, either by 162 calling pushFunction(executor) or by calling pushFunction(void) which pushes a copy of 163 the current executor to the stack. 164 165 Another important point are object pointers in case of non-static member-functions. 166 Whenever you set or push a new function, <b>you must add the object pointer again</b> 167 because objects are stored in the Functor which is usually exchanged if you change 168 the function. 169 170 You can also use a stack for objects, but note that this <b>object-stack is different for each 171 function</b> - so if you set a new function, the object-stack will be cleared. If you push 172 a new function, the old object-stack is stored in the stack, so it can be restored if 173 you pop the function. 174 175 %DeclareConsoleCommand(): 176 177 Appart from SetConsoleCommand() you can also call DeclareConsoleCommand(). In contrast 178 to SetConsoleCommand(), this doesn't assign a function to the command. Indeed you have 179 to pass a function-pointer to DeclareConsoleCommand(), but it is only used to determine 180 the header of the future command-function. This allows to declare a command statically, 181 thus it's possible to evaluate key-bindings of this command, but the actual function 182 can be assigned at a later point. 183 184 Example: 185 @code 186 DeclareConsoleCommand("cout", &prototype::void__string); 187 @endcode 188 189 If you try to execute the command now, you see the following (or something similar): 190 @code 191 $ cout Hello World 192 Error: Can't execute command "cout", command is not active. 193 @endcode 194 195 You first have to assign a function to use the command: 196 @code 197 { 198 // ... 199 200 ModifyConsoleCommand("cout").setFunction(&myCoutFunction); 201 202 // ... 203 } 204 @endcode 205 206 Now you can use it: 207 @code 208 $ cout Hello World 209 Text: Hello World 210 @endcode 211 212 Note that the initial function prototype::void__string is defined in the namespace 213 orxonox::prototype. If there's no function with the desired header, you can extend 214 the collection of functions or simply use another function that has the same header. 215 */ 216 29 217 #ifndef _ConsoleCommand_H__ 30 218 #define _ConsoleCommand_H__ … … 42 230 43 231 232 /** 233 @brief Defines a console command. The macro is overloaded for 2-4 parameters. 234 235 This is an overloaded macro. Depending on the number of arguments a different 236 overloaded implementation of the macro will be chosen. 237 238 Console commands created with SetConsoleCommand() become active immediately and 239 the given function-pointer (and optionally the object) will be used to execute 240 the command. 241 */ 44 242 #define SetConsoleCommand(...) \ 45 243 BOOST_PP_EXPAND(BOOST_PP_CAT(SetConsoleCommand, ORXONOX_VA_NARGS(__VA_ARGS__))(__VA_ARGS__)) 244 /** 245 @brief This macro is executed if you call SetConsoleCommand() with 2 arguments. 246 @param name The name (string) of the console command 247 @param functionpointer The function-pointer of the corresponding command-function 248 */ 46 249 #define SetConsoleCommand2(name, functionpointer) \ 47 250 SetConsoleCommandGeneric("", name, orxonox::createFunctor(functionpointer)) 251 /** 252 @brief This macro is executed if you call SetConsoleCommand() with 3 arguments. 253 @param group The group (string) of the console command 254 @param name The name (string) of the console command 255 @param functionpointer The function-pointer of the corresponding command-function 256 */ 48 257 #define SetConsoleCommand3(group, name, functionpointer) \ 49 258 SetConsoleCommandGeneric(group, name, orxonox::createFunctor(functionpointer)) 259 /** 260 @brief This macro is executed if you call SetConsoleCommand() with 4 arguments. 261 @param group The group (string) of the console command 262 @param name The name (string) of the console command 263 @param functionpointer The function-pointer of the corresponding command-function 264 @param object The object that will be assigned to the command. Used for member-functions. 265 */ 50 266 #define SetConsoleCommand4(group, name, functionpointer, object) \ 51 267 SetConsoleCommandGeneric(group, name, orxonox::createFunctor(functionpointer, object)) 52 268 269 /// Internal macro 53 270 #define SetConsoleCommandGeneric(group, name, functor) \ 54 271 static orxonox::ConsoleCommand& BOOST_PP_CAT(__consolecommand_, __LINE__) = (*orxonox::createConsoleCommand(group, name, orxonox::createExecutor(functor))) 55 272 56 273 274 /** 275 @brief Declares a console command. The macro is overloaded for 2-3 parameters. 276 277 This is an overloaded macro. Depending on the number of arguments a different 278 overloaded implementation of the macro will be chosen. 279 280 Console commands created with DeclareConsoleCommand() don't use the the given 281 function-pointer to execute the command, it is only used to define the header 282 of the future command-function. The command is inactive until you manually 283 set a function with orxonox::ModifyConsoleCommand(). You can use a different 284 function-pointer than in the final command, as long as it has the same header. 285 */ 57 286 #define DeclareConsoleCommand(...) \ 58 287 BOOST_PP_EXPAND(BOOST_PP_CAT(DeclareConsoleCommand, ORXONOX_VA_NARGS(__VA_ARGS__))(__VA_ARGS__)) 288 /** 289 @brief This macro is executed if you call DeclareConsoleCommand() with 2 arguments. 290 @param name The name (string) of the console command 291 @param functionpointer The function-pointer of an arbitrary function that has the same header as the final function 292 */ 59 293 #define DeclareConsoleCommand2(name, functionpointer) \ 60 294 DeclareConsoleCommandGeneric("", name, orxonox::createFunctor(functionpointer)) 295 /** 296 @brief This macro is executed if you call DeclareConsoleCommand() with 3 arguments. 297 @param group The group (string) of the console command 298 @param name The name (string) of the console command 299 @param functionpointer The function-pointer of an arbitrary function that has the same header as the final function 300 */ 61 301 #define DeclareConsoleCommand3(group, name, functionpointer) \ 62 302 DeclareConsoleCommandGeneric(group, name, orxonox::createFunctor(functionpointer)) 63 #define DeclareConsoleCommand4(group, name, functionpointer, object) \ 64 DeclareConsoleCommandGeneric(group, name, orxonox::createFunctor(functionpointer, object)) 65 303 304 /// Internal macro 66 305 #define DeclareConsoleCommandGeneric(group, name, functor) \ 67 306 static orxonox::ConsoleCommand& BOOST_PP_CAT(__consolecommand_, __LINE__) = (*orxonox::createConsoleCommand(group, name, orxonox::createExecutor(functor), false)) … … 70 309 namespace orxonox 71 310 { 311 /** 312 @brief A small collection of functions that can be used in DeclareConsoleCommand() if 313 you don't want to use the real function-pointer. 314 */ 72 315 namespace prototype 73 316 { … … 78 321 namespace AccessLevel 79 322 { 323 /** 324 @brief Possible access levels: A command can only be executed if the program is in the state which is requested by the access level. 325 */ 80 326 enum Enum 81 327 { … … 91 337 } 92 338 339 /** 340 @brief The ConsoleCommand class stores all information about a console command which can be executed by CommandExecutor. 341 342 Console commands can be entered by the user into the shell, called in scripts, or 343 used for key-bindings. They are simple text strings that can be executed by 344 CommandExecutor. CommandExecutor will search for a ConsoleCommand with the given 345 group and name and will execute it's Executor (which again calls the Functor and 346 this finally calls the command-function). 347 348 @see See @ref ConsoleCommandExample "ConsoleCommand.h" for more information and some examples. 349 */ 93 350 class _CoreExport ConsoleCommand 94 351 { 95 352 friend struct ConsoleCommandManipulator; 96 353 354 /** 355 @brief Helper class that is used to put the current state of the ConsoleCommand on a stack. 356 */ 97 357 struct Command 98 358 { 99 ExecutorPtr executor_; 100 FunctorPtr functor_; 101 std::vector<void*> objectStack_; 359 ExecutorPtr executor_; ///< The executor 360 FunctorPtr functor_; ///< The function that is used with the executor - has to be stored separatley because the executor is often used with different functors 361 std::vector<void*> objectStack_; ///< The object stack 102 362 }; 103 363 104 364 public: 365 /** 366 @brief Helper class that is used to manipulate console commands. 367 368 An instance of this class is returned if you call the ModifyConsoleCommand macro. 369 This class provides an interface which wraps some functions of ConsoleCommand. It 370 allows access to some private functions like setFunction() (that can't be called 371 right after SetConsoleCommand()) but it also hides some functions that shouln't be 372 called after the static declaration like addShortcut() or description(). 373 374 @see See @ref ConsoleCommandExample "ConsoleCommand.h" for more information and examples. 375 */ 105 376 struct ConsoleCommandManipulator 106 377 { 107 378 public: 379 /// Constructor: Creates a manipulator for a given ConsoleCommand. 108 380 ConsoleCommandManipulator(const ConsoleCommand* command) : command_(const_cast<ConsoleCommand*>(command)) {} 109 381 382 /// Changes the current function of the command. @param function The new function-pointer @param bForce If true, the new function-pointer is always assigned, even if the headers don't match 110 383 template <class F> 111 384 inline ConsoleCommandManipulator& setFunction(F function, bool bForce = false) … … 113 386 if (this->command_) 114 387 { 388 // check if the headers match. If they do, only change the function-pointer of the current Functor instead of creating a new Functor 115 389 if (this->command_->getExecutor() && this->command_->getExecutor()->getFunctor() && this->command_->getExecutor()->getFunctor()->getFullIdentifier() == typeid(F)) 116 390 { … … 123 397 return *this; 124 398 } 399 /// Changes the current function of the command. @param function The new function-pointer @param object The new object-pointer (for member-functions) @param bForce If true, the new function-pointer is always assigned, even if the headers don't match 125 400 template <class F, class O> 126 401 inline ConsoleCommandManipulator& setFunction(F function, O* object, bool bForce = false) … … 128 403 if (this->command_) 129 404 { 405 // check if the headers match. If they do, only change the function-pointer of the current Functor instead of creating a new Functor 130 406 if (this->command_->getExecutor() && this->command_->getExecutor()->getFunctor() && this->command_->getExecutor()->getFunctor()->getFullIdentifier() == typeid(F)) 131 407 { … … 139 415 return *this; 140 416 } 417 /// Changes the current Functor of the command. @param functor The new Functor @param bForce If true, the new Functor is always assigned, even if the headers don't match 141 418 inline ConsoleCommandManipulator& setFunction(const FunctorPtr& functor, bool bForce = false) 142 419 { if (this->command_) { this->command_->setFunction(functor, bForce); } return *this; } 420 /// Changes the current Executor of the command. @param executor The new Executor @param bForce If true, the new Executor is always assigned, even if the headers don't match 143 421 inline ConsoleCommandManipulator& setFunction(const ExecutorPtr& executor, bool bForce = false) 144 422 { if (this->command_) { this->command_->setFunction(executor, bForce); } return *this; } 145 423 424 /// Pushes a copy of the current Executor on the command-stack, that can be altered without changing the old Executor. @details This function is especially useful if you don't wan't to change the function, but only the default values of the executor. 146 425 inline ConsoleCommandManipulator& pushFunction() 147 426 { if (this->command_) { this->command_->pushFunction(); } return *this; } 427 /// Pushes a new function on the command-stack. @param function The new function-pointer @param bForce If true, the new function-pointer is always assigned, even if the headers don't match 148 428 template <class F> 149 429 inline ConsoleCommandManipulator& pushFunction(F function, bool bForce = false) 150 430 { if (this->command_) { this->command_->pushFunction(createFunctor(function), bForce); } return *this; } 431 /// Pushes a new function on the command-stack. @param function The new function-pointer @param object The new object-pointer (for member-functions) @param bForce If true, the new function-pointer is always assigned, even if the headers don't match 151 432 template <class F, class O> 152 433 inline ConsoleCommandManipulator& pushFunction(F function, O* object, bool bForce = false) 153 434 { if (this->command_) { this->command_->pushFunction(createFunctor(function, object), bForce); } return *this; } 435 /// Pushes a new Functor on the command-stack. @param functor The new Functor @param bForce If true, the new Functor is always assigned, even if the headers don't match 154 436 inline ConsoleCommandManipulator& pushFunction(const FunctorPtr& functor, bool bForce = false) 155 437 { if (this->command_) { this->command_->pushFunction(functor, bForce); } return *this; } 438 /// Pushes a new Executor on the command-stack. @param executor The new Executor @param bForce If true, the new Executor is always assigned, even if the headers don't match 156 439 inline ConsoleCommandManipulator& pushFunction(const ExecutorPtr& executor, bool bForce = false) 157 440 { if (this->command_) { this->command_->pushFunction(executor, bForce); } return *this; } 158 441 442 /// Removes the current function from the stack and restores the old state. If there's no other function on the stack, the command is deactivated. 159 443 inline ConsoleCommandManipulator& popFunction() 160 444 { if (this->command_) { this->command_->popFunction(); } return *this; } 161 445 446 /// Sets the current function-pointer to NULL, which also deactivates the command. 162 447 inline ConsoleCommandManipulator& resetFunction() 163 448 { if (this->command_) { this->command_->resetFunction(); } return *this; } 164 449 450 /// Changes the current object (used for member-functions). 165 451 inline ConsoleCommandManipulator& setObject(void* object) 166 452 { if (this->command_) { this->command_->setObject(object); } return *this; } 453 /// Pushes a new object on the object-stack. 167 454 inline ConsoleCommandManipulator& pushObject(void* object) 168 455 { if (this->command_) { this->command_->pushObject(object); } return *this; } 456 /// Removes the current object from the object-stack and restores the old object (or NULL if there's no object left on the stack). 169 457 inline ConsoleCommandManipulator& popObject() 170 458 { if (this->command_) { this->command_->popObject(); } return *this; } 171 459 460 /// Changes the activity of the command. 172 461 inline ConsoleCommandManipulator& setActive(bool bActive) 173 462 { if (this->command_) { this->command_->setActive(bActive); } return *this; } 463 /// Activates the command. 174 464 inline ConsoleCommandManipulator& activate() 175 465 { return this->setActive(true); } 466 /// Deactivates the command. 176 467 inline ConsoleCommandManipulator& deactivate() 177 468 { return this->setActive(false); } 178 469 470 /// Changes the visibility of the command. 179 471 inline ConsoleCommandManipulator& setHidden(bool bHidden) 180 472 { if (this->command_) { this->command_->setHidden(bHidden); } return *this; } 473 /// Hides the command (can still be executed, but is not visible in the list of available commands). 181 474 inline ConsoleCommandManipulator& hide() 182 475 { return this->setHidden(true); } 476 /// Makes the command visible. 183 477 inline ConsoleCommandManipulator& show() 184 478 { return this->setHidden(false); } 185 479 186 inline ConsoleCommandManipulator& defaultValues(const MultiType& param1) 187 { if (this->command_) { this->command_->defaultValues(param1); } return *this; } 188 inline ConsoleCommandManipulator& defaultValues(const MultiType& param1, const MultiType& param2) 189 { if (this->command_) { this->command_->defaultValues(param1, param2); } return *this; } 190 inline ConsoleCommandManipulator& defaultValues(const MultiType& param1, const MultiType& param2, const MultiType& param3) 191 { if (this->command_) { this->command_->defaultValues(param1, param2, param3); } return *this; } 192 inline ConsoleCommandManipulator& defaultValues(const MultiType& param1, const MultiType& param2, const MultiType& param3, const MultiType& param4) 193 { if (this->command_) { this->command_->defaultValues(param1, param2, param3, param4); } return *this; } 194 inline ConsoleCommandManipulator& defaultValues(const MultiType& param1, const MultiType& param2, const MultiType& param3, const MultiType& param4, const MultiType& param5) 195 { if (this->command_) { this->command_->defaultValues(param1, param2, param3, param4, param5); } return *this; } 196 inline ConsoleCommandManipulator& defaultValue(unsigned int index, const MultiType& param) 197 { if (this->command_) { this->command_->defaultValue(index, param); } return *this; } 198 480 /// Changes the default values of the current executor (doesn't modify executors on deeper levels of the command-stack). 481 inline ConsoleCommandManipulator& defaultValues(const MultiType& arg1) 482 { if (this->command_) { this->command_->defaultValues(arg1); } return *this; } 483 /// Changes the default values of the current executor (doesn't modify executors on deeper levels of the command-stack). 484 inline ConsoleCommandManipulator& defaultValues(const MultiType& arg1, const MultiType& arg2) 485 { if (this->command_) { this->command_->defaultValues(arg1, arg2); } return *this; } 486 /// Changes the default values of the current executor (doesn't modify executors on deeper levels of the command-stack). 487 inline ConsoleCommandManipulator& defaultValues(const MultiType& arg1, const MultiType& arg2, const MultiType& arg3) 488 { if (this->command_) { this->command_->defaultValues(arg1, arg2, arg3); } return *this; } 489 /// Changes the default values of the current executor (doesn't modify executors on deeper levels of the command-stack). 490 inline ConsoleCommandManipulator& defaultValues(const MultiType& arg1, const MultiType& arg2, const MultiType& arg3, const MultiType& arg4) 491 { if (this->command_) { this->command_->defaultValues(arg1, arg2, arg3, arg4); } return *this; } 492 /// Changes the default values of the current executor (doesn't modify executors on deeper levels of the command-stack). 493 inline ConsoleCommandManipulator& defaultValues(const MultiType& arg1, const MultiType& arg2, const MultiType& arg3, const MultiType& arg4, const MultiType& arg5) 494 { if (this->command_) { this->command_->defaultValues(arg1, arg2, arg3, arg4, arg5); } return *this; } 495 /// Changes the default value of the argument with given index of the current executor (doesn't modify executors on deeper levels of the command-stack). 496 inline ConsoleCommandManipulator& defaultValue(unsigned int index, const MultiType& arg) 497 { if (this->command_) { this->command_->defaultValue(index, arg); } return *this; } 498 499 /// Changes the access level of the command. 199 500 inline ConsoleCommandManipulator& accessLevel(AccessLevel::Enum level) 200 501 { if (this->command_) { this->command_->accessLevel(level); } return *this; } 201 502 202 inline ConsoleCommandManipulator& argumentCompleter(unsigned int param, ArgumentCompleter* completer) 203 { if (this->command_) { this->command_->argumentCompleter(param, completer); } return *this; } 204 503 /// Changes the argument completer for the given parameter. 504 inline ConsoleCommandManipulator& argumentCompleter(unsigned int index, ArgumentCompleter* completer) 505 { if (this->command_) { this->command_->argumentCompleter(index, completer); } return *this; } 506 507 /// Defines the command to be an input command. 205 508 inline ConsoleCommandManipulator& setAsInputCommand() 206 509 { if (this->command_) { this->command_->setAsInputCommand(); } return *this; } 510 /// Changes the keybind mode of the command. 207 511 inline ConsoleCommandManipulator& keybindMode(KeybindMode::Value mode) 208 512 { if (this->command_) { this->command_->keybindMode(mode); } return *this; } 513 /// Sets the input configured param to the given index. 209 514 inline ConsoleCommandManipulator& inputConfiguredParam(int index) 210 515 { if (this->command_) { this->command_->inputConfiguredParam(index); } return *this; } 211 516 212 517 private: 213 ConsoleCommand* command_; 518 ConsoleCommand* command_; ///< The command which is being manipulated by this object 214 519 }; 215 520 … … 223 528 ConsoleCommand& addGroup(const std::string& group, const std::string& name); 224 529 530 /// Returns the name that was first used for this command. 225 531 inline const std::string& getName() const 226 532 { return this->baseName_; } 227 533 228 534 const ExecutorPtr& getExecutor() const; 535 /// Returns the functor that defines the required header for this command (but isn't necessarily executed). 229 536 inline const FunctorPtr& getBaseFunctor() const 230 537 { return this->baseFunctor_; } 231 538 539 /// Changes the activity of the command. 232 540 inline ConsoleCommand& setActive(bool bActive) 233 541 { this->bActive_ = bActive; return *this; } 542 /// Activates the command. 234 543 inline ConsoleCommand& activate() 235 544 { return this->setActive(true); } 545 /// Deactivates the command. 236 546 inline ConsoleCommand& deactivate() 237 547 { return this->setActive(false); } 238 548 549 /// Changes the visibility of the command. 239 550 inline ConsoleCommand& setHidden(bool bHidden) 240 551 { this->bHidden_ = bHidden; return *this; } 552 /// Hides the command (can still be executed, but is not visible in the list of available commands). 241 553 inline ConsoleCommand& hide() 242 554 { return this->setHidden(true); } 555 /// Makes the command visible. 243 556 inline ConsoleCommand& show() 244 557 { return this->setHidden(false); } … … 246 559 bool isActive() const; 247 560 bool hasAccess() const; 561 /// Returns true if the command is currently hidden. 248 562 inline bool isHidden() const 249 563 { return this->bHidden_; } … … 252 566 const std::string& getDescription() const; 253 567 254 ConsoleCommand& descriptionParam(unsigned int param, const std::string& description);255 const std::string& getDescriptionParam(unsigned int param) const;568 ConsoleCommand& descriptionParam(unsigned int index, const std::string& description); 569 const std::string& getDescriptionParam(unsigned int index) const; 256 570 257 571 ConsoleCommand& descriptionReturnvalue(const std::string& description); 258 const std::string& getDescriptionReturnvalue(int param) const; 259 260 ConsoleCommand& defaultValues(const MultiType& param1); 261 ConsoleCommand& defaultValues(const MultiType& param1, const MultiType& param2); 262 ConsoleCommand& defaultValues(const MultiType& param1, const MultiType& param2, const MultiType& param3); 263 ConsoleCommand& defaultValues(const MultiType& param1, const MultiType& param2, const MultiType& param3, const MultiType& param4); 264 ConsoleCommand& defaultValues(const MultiType& param1, const MultiType& param2, const MultiType& param3, const MultiType& param4, const MultiType& param5); 265 ConsoleCommand& defaultValue(unsigned int index, const MultiType& param); 266 572 const std::string& getDescriptionReturnvalue(int index) const; 573 574 ConsoleCommand& defaultValues(const MultiType& arg1); 575 ConsoleCommand& defaultValues(const MultiType& arg1, const MultiType& arg2); 576 ConsoleCommand& defaultValues(const MultiType& arg1, const MultiType& arg2, const MultiType& arg3); 577 ConsoleCommand& defaultValues(const MultiType& arg1, const MultiType& arg2, const MultiType& arg3, const MultiType& arg4); 578 ConsoleCommand& defaultValues(const MultiType& arg1, const MultiType& arg2, const MultiType& arg3, const MultiType& arg4, const MultiType& arg5); 579 ConsoleCommand& defaultValue(unsigned int index, const MultiType& arg); 580 581 /// Changes the access level of the command. 267 582 inline ConsoleCommand& accessLevel(AccessLevel::Enum level) 268 583 { this->accessLevel_ = level; return *this; } 584 /// Returns the access level of the command. 269 585 inline AccessLevel::Enum getAccessLevel() const 270 586 { return this->accessLevel_; } 271 587 272 ConsoleCommand& argumentCompleter(unsigned int param, ArgumentCompleter* completer); 273 ArgumentCompleter* getArgumentCompleter(unsigned int param) const; 274 588 ConsoleCommand& argumentCompleter(unsigned int index, ArgumentCompleter* completer); 589 ArgumentCompleter* getArgumentCompleter(unsigned int index) const; 590 591 /// Defines the command to be an input command 275 592 inline ConsoleCommand& setAsInputCommand() 276 593 { … … 281 598 } 282 599 600 /// Changes the keybind mode. 283 601 inline ConsoleCommand& keybindMode(KeybindMode::Value mode) 284 602 { this->keybindMode_ = mode; return *this; } 603 /// Returns the keybind mode 285 604 inline KeybindMode::Value getKeybindMode() const 286 605 { return this->keybindMode_; } 287 606 607 /// Changes the input configured param to the given index. 288 608 inline ConsoleCommand& inputConfiguredParam(int index) 289 609 { this->inputConfiguredParam_ = index; return *this; } 610 /// Returns the input configured param. 290 611 inline int getInputConfiguredParam_() const 291 612 { return this->inputConfiguredParam_; } 292 613 614 /// Returns a manipulator for this command. 293 615 inline ConsoleCommandManipulator getManipulator() const 294 616 { return this; } … … 311 633 void* getObject() const; 312 634 313 bool bActive_; 314 bool bHidden_; 315 AccessLevel::Enum accessLevel_; 316 std::string baseName_; 317 FunctorPtr baseFunctor_; 318 319 ExecutorPtr executor_; 320 std::stack<Command> commandStack_; 321 std::vector<void*> objectStack_; 322 323 ArgumentCompleter* argumentCompleter_[ 5];324 325 KeybindMode::Value keybindMode_; 326 int inputConfiguredParam_; 327 328 LanguageEntryLabel description_; 329 LanguageEntryLabel descriptionReturnvalue_; 330 LanguageEntryLabel descriptionParam_[MAX_FUNCTOR_ARGUMENTS]; 635 bool bActive_; ///< True if the command should be active (it can still be inactive, for example if the function is missing) 636 bool bHidden_; ///< True if the command is hidden (it is still executable, but not visible in the list of available commands) 637 AccessLevel::Enum accessLevel_; ///< The access level (the state of the game in which you can access the command) 638 std::string baseName_; ///< The name that was first assigned to the command 639 FunctorPtr baseFunctor_; ///< The functor that defines the header of the command-function 640 641 ExecutorPtr executor_; ///< The Executor that is used to execute the command 642 std::stack<Command> commandStack_; ///< A stack of commands, used to push and pop different functions 643 std::vector<void*> objectStack_; ///< A stack of objects, used to push and pop different objects for a function 644 645 ArgumentCompleter* argumentCompleter_[MAX_FUNCTOR_ARGUMENTS]; ///< ArgumentCompleter for each argument 646 647 KeybindMode::Value keybindMode_; ///< The keybind mode 648 int inputConfiguredParam_; ///< The input configured param 649 650 LanguageEntryLabel description_; ///< The description of the command 651 LanguageEntryLabel descriptionReturnvalue_; ///< A description of the return-value 652 LanguageEntryLabel descriptionParam_[MAX_FUNCTOR_ARGUMENTS]; ///< A description for each argument 331 653 332 654 public: 655 /// Returns the map with all groups and commands. 333 656 static inline const std::map<std::string, std::map<std::string, ConsoleCommand*> >& getCommands() 334 657 { return ConsoleCommand::getCommandMap(); } 658 /// Returns the map with all groups and commands in lowercase. 335 659 static inline const std::map<std::string, std::map<std::string, ConsoleCommand*> >& getCommandsLC() 336 660 { return ConsoleCommand::getCommandMapLC(); } 337 661 662 /// Returns a command (shortcut) with given name. @param name The name of the command shortcut @param bPrintError If true, an error is printed if the command doesn't exist 338 663 static inline const ConsoleCommand* getCommand(const std::string& name, bool bPrintError = false) 339 664 { return ConsoleCommand::getCommand("", name, bPrintError); } 665 /// Returns a command (shortcut) with given name in lowercase. @param name The lowercase name of the command shortcut @param bPrintError If true, an error is printed if the command doesn't exist 340 666 static inline const ConsoleCommand* getCommandLC(const std::string& name, bool bPrintError = false) 341 667 { return ConsoleCommand::getCommandLC("", name, bPrintError); } … … 354 680 }; 355 681 682 /** 683 @brief Creates a new ConsoleCommand. 684 @param name The name of the command 685 @param executor The executor of the command 686 @param bInitialized If true, the command is ready to be executed, otherwise it has to be activated first. 687 */ 356 688 inline ConsoleCommand* createConsoleCommand(const std::string& name, const ExecutorPtr& executor, bool bInitialized = true) 357 689 { return new ConsoleCommand("", name, executor, bInitialized); } 690 /** 691 @brief Creates a new ConsoleCommand. 692 @param group The group of the command 693 @param name The name of the command 694 @param executor The executor of the command 695 @param bInitialized If true, the command is ready to be executed, otherwise it has to be activated first. 696 */ 358 697 inline ConsoleCommand* createConsoleCommand(const std::string& group, const std::string& name, const ExecutorPtr& executor, bool bInitialized = true) 359 698 { return new ConsoleCommand(group, name, executor, bInitialized); } 360 699 700 701 /** 702 @brief Returns a manipulator for a command with the given name. 703 704 @note If the command doesn't exist, the manipulator contains a NULL pointer to the command, 705 but it can still be used without checks, because all functions of ConsoleCommandManipulator 706 check internally if the command exists. 707 */ 361 708 inline ConsoleCommand::ConsoleCommandManipulator ModifyConsoleCommand(const std::string& name) 362 709 { return ConsoleCommand::getCommand(name, true); } 710 /** 711 @brief Returns a manipulator for a command with the given group and name. 712 713 @note If the command doesn't exist, the manipulator contains a NULL pointer to the command, 714 but it can still be used without checks, because all functions of ConsoleCommandManipulator 715 check internally if the command exists. 716 */ 363 717 inline ConsoleCommand::ConsoleCommandManipulator ModifyConsoleCommand(const std::string& group, const std::string& name) 364 718 { return ConsoleCommand::getCommand(group, name, true); } -
code/trunk/src/libraries/core/command/ConsoleCommandCompilation.cc
r7284 r7401 26 26 * 27 27 */ 28 29 /** 30 @file 31 @brief Implementation of some console commands. 32 */ 28 33 29 34 #include "ConsoleCommandCompilation.h" … … 51 56 SetConsoleCommand("calculate", calculate); 52 57 58 /** 59 @brief Reads the content of a file and executes the commands in it line by line. 60 */ 53 61 void source(const std::string& filename) 54 62 { … … 86 94 } 87 95 96 /** 97 @brief Simply returns the arguments. 98 */ 88 99 std::string echo(const std::string& text) 89 100 { … … 91 102 } 92 103 104 /** 105 @brief Writes text to the console, depending on the first argument with or without a line-break after it. 106 */ 93 107 void puts(bool newline, const std::string& text) 94 108 { … … 103 117 } 104 118 119 /** 120 @brief Writes text to a file. 121 */ 105 122 void write(const std::string& filename, const std::string& text) 106 123 { … … 118 135 } 119 136 137 /** 138 @brief Appends text to a file. 139 */ 120 140 void append(const std::string& filename, const std::string& text) 121 141 { … … 133 153 } 134 154 155 /** 156 @brief Reads text from a file 157 */ 135 158 std::string read(const std::string& filename) 136 159 { … … 158 181 } 159 182 183 /** 184 @brief Parses the mathematical expression and returns the result. 185 */ 160 186 float calculate(const std::string& calculation) 161 187 { -
code/trunk/src/libraries/core/command/ConsoleCommandCompilation.h
r7284 r7401 27 27 */ 28 28 29 /** 30 @file 31 @ingroup Command ConsoleCommand 32 @brief Declaration of some console commands. 33 */ 34 29 35 #ifndef _ConsoleCommandCompilation_H__ 30 36 #define _ConsoleCommandCompilation_H__ -
code/trunk/src/libraries/core/command/Executor.cc
r7284 r7401 27 27 * Inspiration: Executor by Benjamin Grauer 28 28 */ 29 30 /** 31 @file 32 @brief Implementation of orxonox::Executor 33 */ 29 34 30 35 #include "Executor.h" … … 40 45 namespace orxonox 41 46 { 47 /** 48 @brief Constructor: Creates an executor. 49 @param functor The wrapped functor 50 @param name The name of the executor (optional, used mostly for debug output) 51 */ 42 52 Executor::Executor(const FunctorPtr& functor, const std::string& name) 43 53 { … … 46 56 } 47 57 58 /** 59 @brief Copy-constructor: Creates a new executor with the same values and a clone of the wrapped Functor. 60 */ 48 61 Executor::Executor(const Executor& other) : name_(other.name_) 49 62 { … … 53 66 } 54 67 68 /** 69 @brief Destructor 70 */ 55 71 Executor::~Executor() 56 72 { 57 73 } 58 74 75 /** 76 @brief Calls the wrapped function with arguments that are passed in a string. 77 @param arguments The arguments that should be passed to the function, separated by @a delimiter 78 @param error A pointer to a variable (or NULL) that is used to store the error code (see @ref CommandExecutorErrorCodes "CommandExecutor error codes") 79 @param delimiter The delimiter that is used to separate the arguments in the string @a arguments 80 @param bPrintError If true, errors are printed to the console if the function couldn't be executed with the given arguments 81 @return Returns the return value of the function (or MT_Type::Null if there is no return value) 82 */ 59 83 MultiType Executor::parse(const std::string& arguments, int* error, const std::string& delimiter, bool bPrintError) const 60 84 { … … 62 86 } 63 87 88 /** 89 @brief Calls the wrapped function with arguments that are passed as tokens in a SubString 90 @param arguments The arguments that should be passed to the function 91 @param error A pointer to a variable (or NULL) that is used to store the error code (see @ref CommandExecutorErrorCodes "CommandExecutor error codes") 92 @param delimiter The delimiter that was used to separate the arguments in the SubString @a arguments (used to join the surplus arguments) 93 @param bPrintError If true, errors are printed to the console if the function couldn't be executed with the given arguments 94 @return Returns the return value of the function (or MT_Type::Null if there is no return value) 95 */ 64 96 MultiType Executor::parse(const SubString& arguments, int* error, const std::string& delimiter, bool bPrintError) const 65 97 { 66 MultiType param[MAX_FUNCTOR_ARGUMENTS]; 67 unsigned int paramCount = this->evaluateParams(arguments, param, error, delimiter); 68 98 // evaluate the arguments 99 MultiType arg[MAX_FUNCTOR_ARGUMENTS]; 100 unsigned int argCount = this->evaluateArguments(arguments, arg, error, delimiter); 101 102 // check if an error occurred 69 103 if (error && *error) 70 104 { 71 105 if (bPrintError) 72 COUT(2) << "Warning: Can't call executor " << this->name_ << " through parser: Not enough parameters or default values given (input: " << arguments.join() << ")." << std::endl;106 COUT(2) << "Warning: Can't call executor " << this->name_ << " through parser: Not enough arguments or default values given (input: " << arguments.join() << ")." << std::endl; 73 107 return MT_Type::Null; 74 108 } 75 109 76 COUT(5) << "Executor::parse: \"" << arguments.join(delimiter) << "\" -> " << paramCount << " params: " << param[0] << " / " << param[1] << " / " << param[2] << " / " << param[3] << " / " << param[4] << std::endl; 77 78 switch (paramCount) 110 COUT(5) << "Executor::parse: \"" << arguments.join(delimiter) << "\" -> " << argCount << " arguments: " << arg[0] << " / " << arg[1] << " / " << arg[2] << " / " << arg[3] << " / " << arg[4] << std::endl; 111 112 // execute the function with the evaluated arguments (the default values of the executor are also included in these arguments) 113 switch (argCount) 79 114 { 80 115 case 0: return (*this->functor_)(); 81 case 1: return (*this->functor_)( param[0]);82 case 2: return (*this->functor_)( param[0], param[1]);83 case 3: return (*this->functor_)( param[0], param[1], param[2]);84 case 4: return (*this->functor_)( param[0], param[1], param[2], param[3]);116 case 1: return (*this->functor_)(arg[0]); 117 case 2: return (*this->functor_)(arg[0], arg[1]); 118 case 3: return (*this->functor_)(arg[0], arg[1], arg[2]); 119 case 4: return (*this->functor_)(arg[0], arg[1], arg[2], arg[3]); 85 120 case 5: 86 default: return (*this->functor_)( param[0], param[1], param[2], param[3], param[4]);121 default: return (*this->functor_)(arg[0], arg[1], arg[2], arg[3], arg[4]); 87 122 } 88 123 } 89 124 90 int Executor::evaluateParams(const SubString& arguments, MultiType param[MAX_FUNCTOR_ARGUMENTS], int* error, const std::string& delimiter) const 125 /** 126 @brief Converts the arguments in a SubString to the right type, so they can be used to execute the function without further conversions. 127 @param arguments The arguments that should be converted 128 @param arg An array of MultiType where the converted arguments will be stored 129 @param error A pointer to a variable (or NULL) that is used to store the error code (see @ref CommandExecutorErrorCodes "CommandExecutor error codes") 130 @param delimiter The delimiter that was used to separate the arguments in the SubString @a arguments (used to join the surplus arguments) 131 @return Returns the number of evaluated arguments 132 */ 133 int Executor::evaluateArguments(const SubString& arguments, MultiType arg[MAX_FUNCTOR_ARGUMENTS], int* error, const std::string& delimiter) const 91 134 { 92 135 unsigned int paramCount = this->functor_->getParamCount(); … … 106 149 // assign all given arguments to the multitypes 107 150 for (unsigned int i = 0; i < std::min(std::min(argumentCount, paramCount), MAX_FUNCTOR_ARGUMENTS); i++) 108 param[i] = arguments[i];151 arg[i] = arguments[i]; 109 152 110 153 // fill the remaining multitypes with default values 111 154 for (unsigned int i = argumentCount; i < std::min(paramCount, MAX_FUNCTOR_ARGUMENTS); i++) 112 param[i] = this->defaultValue_[i];155 arg[i] = this->defaultValue_[i]; 113 156 114 157 // assign the remaining arguments all to the last parameter if it is a string 115 158 if ((paramCount <= MAX_FUNCTOR_ARGUMENTS) &&(argumentCount > paramCount) && (paramCount == 1 || this->functor_->getTypenameParam(paramCount - 1) == "string")) 116 param[paramCount - 1] = arguments.subSet(paramCount - 1).join(delimiter);117 118 // evaluate the param types through the functor159 arg[paramCount - 1] = arguments.subSet(paramCount - 1).join(delimiter); 160 161 // evaluate the parameter types through the functor 119 162 for (unsigned int i = 0; i < std::min(paramCount, MAX_FUNCTOR_ARGUMENTS); i++) 120 this->functor_->evaluate Param(i, param[i]);163 this->functor_->evaluateArgument(i, arg[i]); 121 164 122 165 if (error) … … 125 168 } 126 169 127 void Executor::setDefaultValues(const MultiType& param1) 128 { 129 this->defaultValue_[0] = param1; 130 } 131 132 void Executor::setDefaultValues(const MultiType& param1, const MultiType& param2) 133 { 134 this->defaultValue_[0] = param1; 135 this->defaultValue_[1] = param2; 136 } 137 138 void Executor::setDefaultValues(const MultiType& param1, const MultiType& param2, const MultiType& param3) 139 { 140 this->defaultValue_[0] = param1; 141 this->defaultValue_[1] = param2; 142 this->defaultValue_[2] = param3; 143 } 144 145 void Executor::setDefaultValues(const MultiType& param1, const MultiType& param2, const MultiType& param3, const MultiType& param4) 146 { 147 this->defaultValue_[0] = param1; 148 this->defaultValue_[1] = param2; 149 this->defaultValue_[2] = param3; 150 this->defaultValue_[3] = param4; 151 } 152 153 void Executor::setDefaultValues(const MultiType& param1, const MultiType& param2, const MultiType& param3, const MultiType& param4, const MultiType& param5) 154 { 155 this->defaultValue_[0] = param1; 156 this->defaultValue_[1] = param2; 157 this->defaultValue_[2] = param3; 158 this->defaultValue_[3] = param4; 159 this->defaultValue_[4] = param5; 160 } 161 162 void Executor::setDefaultValue(unsigned int index, const MultiType& param) 170 /// Defines the default value for the first parameter. 171 void Executor::setDefaultValues(const MultiType& arg1) 172 { 173 this->defaultValue_[0] = arg1; 174 } 175 176 /// Defines the default value for the first two parameters. 177 void Executor::setDefaultValues(const MultiType& arg1, const MultiType& arg2) 178 { 179 this->defaultValue_[0] = arg1; 180 this->defaultValue_[1] = arg2; 181 } 182 183 /// Defines the default value for the first three parameters. 184 void Executor::setDefaultValues(const MultiType& arg1, const MultiType& arg2, const MultiType& arg3) 185 { 186 this->defaultValue_[0] = arg1; 187 this->defaultValue_[1] = arg2; 188 this->defaultValue_[2] = arg3; 189 } 190 191 /// Defines the default value for the first four parameters. 192 void Executor::setDefaultValues(const MultiType& arg1, const MultiType& arg2, const MultiType& arg3, const MultiType& arg4) 193 { 194 this->defaultValue_[0] = arg1; 195 this->defaultValue_[1] = arg2; 196 this->defaultValue_[2] = arg3; 197 this->defaultValue_[3] = arg4; 198 } 199 200 /// Defines the default value for the first five parameters. 201 void Executor::setDefaultValues(const MultiType& arg1, const MultiType& arg2, const MultiType& arg3, const MultiType& arg4, const MultiType& arg5) 202 { 203 this->defaultValue_[0] = arg1; 204 this->defaultValue_[1] = arg2; 205 this->defaultValue_[2] = arg3; 206 this->defaultValue_[3] = arg4; 207 this->defaultValue_[4] = arg5; 208 } 209 210 /// Defines the default value for a parameter with given index (the first parameter has index 0). 211 void Executor::setDefaultValue(unsigned int index, const MultiType& arg) 163 212 { 164 213 if (index < MAX_FUNCTOR_ARGUMENTS) 165 this->defaultValue_[index] = param; 166 } 167 214 this->defaultValue_[index] = arg; 215 } 216 217 /// Returns true if the executor has a default value for each parameter of the wrapped function, so it can be called without passing additional arguments. 168 218 bool Executor::allDefaultValuesSet() const 169 219 { -
code/trunk/src/libraries/core/command/Executor.h
r7284 r7401 28 28 */ 29 29 30 /** 31 @defgroup FunctorExecutor Functor and Executor 32 @ingroup Command 33 */ 34 35 /** 36 @file 37 @ingroup Command FunctorExecutor 38 @brief Declaration of the orxonox::Executor class and the createExecutor() functions. 39 40 @anchor ExecutorExample 41 42 orxonox::Executor is used to wrap an orxonox::Functor and to store default values for 43 its parameters. Usually one uses the function createExecutor() to create a new executor. 44 This function returns an orxonox::ExecutorPtr which is a typedef of @ref orxonox::SharedPtr 45 "SharedPtr<Executor>", used to manage the pointer to the executor. 46 47 Executors are mostly used to execute callbacks. Because some callback functions need arguments, 48 Executor provides an easy interface to store these arguments as default values, so the 49 executor can also be executed without arguments because it will use these default values. 50 51 The Executor doesn't contain the function-pointer directly. Instead it wraps an instance 52 of orxonox::Functor. See @ref FunctorExample "Functor.h" for more information and some 53 examples. 54 55 Example: 56 @code 57 void myFunction(int a, int b) // declare a static function 58 { 59 COUT(0) << "The sum is " << (a + b) << std::endl; // print the sum of a and b to the console 60 } 61 62 FunctorPtr functor = createFunctor(&myFunction); // create a functor that wraps the function-pointer 63 ExecutorPtr executor = createExecutor(functor); // create an executor that wraps the functor 64 65 (*executor)(2, 5); // calls the executor with arguments 2 and 5, prints "The sum is 7" to the console 66 67 executor->setDefaultValue(1, 10); // sets the default-value for the second parameter (note: paramters start at index 0) to 10 68 69 (*executor)(2); // calls the executor with argument 2 and default-value 10, prints "The sum is 12" 70 71 executor->setDefaultValue(0, 5); // sets the default-value for the first parameter to 5 72 73 (*executor)(); // calls the executor with default-values only, prints "The sum is 15" 74 @endcode 75 76 Because executors that were created with createExecutor() are managed by an orxonox::SharedPtr, 77 they don't need to be deleted after usage. 78 */ 79 30 80 #ifndef _Executor_H__ 31 81 #define _Executor_H__ … … 40 90 namespace orxonox 41 91 { 92 /** 93 @brief This class is used to wrap a Functor and to store default values for any of its parameters. 94 95 @see See @ref ExecutorExample "Executor.h" for an example. 96 */ 42 97 class _CoreExport Executor 43 98 { … … 47 102 virtual ~Executor(); 48 103 104 /// Calls the wrapped function with 0 arguments. If the function needs more arguments, the executor's default values are used. 49 105 inline MultiType operator()() const 50 106 { return (*this->functor_)(this->defaultValue_[0], this->defaultValue_[1], this->defaultValue_[2], this->defaultValue_[3], this->defaultValue_[4]); } 51 inline MultiType operator()(const MultiType& param1) const 52 { return (*this->functor_)(param1, this->defaultValue_[1], this->defaultValue_[2], this->defaultValue_[3], this->defaultValue_[4]); } 53 inline MultiType operator()(const MultiType& param1, const MultiType& param2) const 54 { return (*this->functor_)(param1, param2, this->defaultValue_[2], this->defaultValue_[3], this->defaultValue_[4]); } 55 inline MultiType operator()(const MultiType& param1, const MultiType& param2, const MultiType& param3) const 56 { return (*this->functor_)(param1, param2, param3, this->defaultValue_[3], this->defaultValue_[4]); } 57 inline MultiType operator()(const MultiType& param1, const MultiType& param2, const MultiType& param3, const MultiType& param4) const 58 { return (*this->functor_)(param1, param2, param3, param4, this->defaultValue_[4]); } 59 inline MultiType operator()(const MultiType& param1, const MultiType& param2, const MultiType& param3, const MultiType& param4, const MultiType& param5) const 60 { return (*this->functor_)(param1, param2, param3, param4, param5); } 107 /// Calls the wrapped function with 1 argument. If the function needs more arguments, the executor's default values are used. 108 inline MultiType operator()(const MultiType& arg1) const 109 { return (*this->functor_)(arg1, this->defaultValue_[1], this->defaultValue_[2], this->defaultValue_[3], this->defaultValue_[4]); } 110 /// Calls the wrapped function with 2 arguments. If the function needs more arguments, the executor's default values are used. 111 inline MultiType operator()(const MultiType& arg1, const MultiType& arg2) const 112 { return (*this->functor_)(arg1, arg2, this->defaultValue_[2], this->defaultValue_[3], this->defaultValue_[4]); } 113 /// Calls the wrapped function with 3 arguments. If the function needs more arguments, the executor's default values are used. 114 inline MultiType operator()(const MultiType& arg1, const MultiType& arg2, const MultiType& arg3) const 115 { return (*this->functor_)(arg1, arg2, arg3, this->defaultValue_[3], this->defaultValue_[4]); } 116 /// Calls the wrapped function with 4 arguments. If the function needs more arguments, the executor's default values are used. 117 inline MultiType operator()(const MultiType& arg1, const MultiType& arg2, const MultiType& arg3, const MultiType& arg4) const 118 { return (*this->functor_)(arg1, arg2, arg3, arg4, this->defaultValue_[4]); } 119 /// Calls the wrapped function with 5 arguments. If the function needs more arguments, the executor's default values are used. 120 inline MultiType operator()(const MultiType& arg1, const MultiType& arg2, const MultiType& arg3, const MultiType& arg4, const MultiType& arg5) const 121 { return (*this->functor_)(arg1, arg2, arg3, arg4, arg5); } 61 122 62 123 MultiType parse(const std::string& arguments, int* error = 0, const std::string& delimiter = " ", bool bPrintError = false) const; 63 124 MultiType parse(const SubString& arguments, int* error = 0, const std::string& delimiter = " ", bool bPrintError = false) const; 64 125 65 int evaluateParams(const SubString& arguments, MultiType param[MAX_FUNCTOR_ARGUMENTS], int* error = 0, const std::string& delimiter = " ") const; 66 126 int evaluateArguments(const SubString& arguments, MultiType arg[MAX_FUNCTOR_ARGUMENTS], int* error = 0, const std::string& delimiter = " ") const; 127 128 /// Changes the functor. 67 129 inline void setFunctor(const FunctorPtr& functor) 68 130 { this->functor_ = functor; } 131 /// Returns the functor. 69 132 inline const FunctorPtr& getFunctor() const 70 133 { return this->functor_; } 71 134 135 /// Changes the name of the executor. 72 136 inline void setName(const std::string& name) 73 137 { this->name_ = name; } 138 /// Returns the name of the executor. 74 139 inline const std::string& getName() const 75 140 { return this->name_; } 76 141 142 /// Returns the number of parameters of the wrapped function. 77 143 inline unsigned int getParamCount() const 78 144 { return this->functor_->getParamCount(); } 145 /// Returns true if the wrapped function returns a value. 79 146 inline bool hasReturnvalue() const 80 147 { return this->functor_->hasReturnvalue(); } 148 /// Returns the type of the wrapped function (static or member). 81 149 inline Functor::Type::Enum getType() const 82 150 { return this->functor_->getType(); } 151 /// Returns the name of the type of a parameter with given index (the first parameter has index 0). 83 152 inline std::string getTypenameParam(unsigned int param) const 84 153 { return this->functor_->getTypenameParam(param); } 154 /// Returns the name of the type of the return value. 85 155 inline std::string getTypenameReturnvalue() const 86 156 { return this->functor_->getTypenameReturnvalue(); } 87 157 88 void setDefaultValues(const MultiType& param1); 89 void setDefaultValues(const MultiType& param1, const MultiType& param2); 90 void setDefaultValues(const MultiType& param1, const MultiType& param2, const MultiType& param3); 91 void setDefaultValues(const MultiType& param1, const MultiType& param2, const MultiType& param3, const MultiType& param4); 92 void setDefaultValues(const MultiType& param1, const MultiType& param2, const MultiType& param3, const MultiType& param4, const MultiType& param5); 93 void setDefaultValue(unsigned int index, const MultiType& param); 94 158 void setDefaultValues(const MultiType& arg1); 159 void setDefaultValues(const MultiType& arg1, const MultiType& arg2); 160 void setDefaultValues(const MultiType& arg1, const MultiType& arg2, const MultiType& arg3); 161 void setDefaultValues(const MultiType& arg1, const MultiType& arg2, const MultiType& arg3, const MultiType& arg4); 162 void setDefaultValues(const MultiType& arg1, const MultiType& arg2, const MultiType& arg3, const MultiType& arg4, const MultiType& arg5); 163 void setDefaultValue(unsigned int index, const MultiType& arg); 164 165 /// Returns the default value for a parameter with given index (the first parameter has index 0). 95 166 inline MultiType getDefaultValue(unsigned int index) const 96 167 { … … 102 173 103 174 bool allDefaultValuesSet() const; 175 176 /// Returns true if the executor contains a default value for the parameter with given index (the first parameter has index 0). 104 177 inline bool defaultValueSet(unsigned int index) const 105 178 { … … 111 184 112 185 protected: 113 FunctorPtr functor_; 114 std::string name_; 115 MultiType defaultValue_[MAX_FUNCTOR_ARGUMENTS]; 186 FunctorPtr functor_; ///< The underlying Functor that wraps a function 187 std::string name_; ///< The name of the executor 188 MultiType defaultValue_[MAX_FUNCTOR_ARGUMENTS]; ///< The default values, one for each parameter 116 189 }; 117 190 191 /** 192 @brief A child class of Executor, used to distinguish executors that wrap static functions from executors that wrap member-functions. 193 194 Behaves exactly like Executor, because static functions need no special treatment. 195 */ 118 196 class _CoreExport ExecutorStatic : public Executor 119 197 { 120 198 public: 199 /// Constructor: Initializes the parent class 121 200 ExecutorStatic(const FunctorStaticPtr& functor, const std::string& name = "") : Executor(functor, name) {} 201 /// Destructor 122 202 virtual ~ExecutorStatic() {} 123 203 }; 124 204 205 /** 206 @brief A child class of Executor, used for easier handling of non-static member-functions. 207 208 Overloads some functions that call the underlying FunctorMember and additionally pass 209 an object-pointer that is needed for non-static member-functions. 210 */ 125 211 template <class T> 126 212 class ExecutorMember : public Executor 127 213 { 128 214 public: 215 /// Constructor: Initializes the parent class and the pointer to the member-functor. 129 216 ExecutorMember(const FunctorMemberPtr<T>& functor, const std::string& name = "") : Executor(functor, name), functorMember_(functor) {} 217 /// Destructor 130 218 virtual ~ExecutorMember() {} 131 219 132 220 using Executor::operator(); 133 221 222 /// Calls the wrapped function with 0 arguments and an object-pointer. If the function needs more arguments, the executor's default values are used. 134 223 inline MultiType operator()(T* object) const 135 224 { return (*this->functorMember_)(object, this->defaultValue_[0], this->defaultValue_[1], this->defaultValue_[2], this->defaultValue_[3], this->defaultValue_[4]); } 136 inline MultiType operator()(T* object, const MultiType& param1) const 137 { return (*this->functorMember_)(object, param1, this->defaultValue_[1], this->defaultValue_[2], this->defaultValue_[3], this->defaultValue_[4]); } 138 inline MultiType operator()(T* object, const MultiType& param1, const MultiType& param2) const 139 { return (*this->functorMember_)(object, param1, param2, this->defaultValue_[2], this->defaultValue_[3], this->defaultValue_[4]); } 140 inline MultiType operator()(T* object, const MultiType& param1, const MultiType& param2, const MultiType& param3) const 141 { return (*this->functorMember_)(object, param1, param2, param3, this->defaultValue_[3], this->defaultValue_[4]); } 142 inline MultiType operator()(T* object, const MultiType& param1, const MultiType& param2, const MultiType& param3, const MultiType& param4) const 143 { return (*this->functorMember_)(object, param1, param2, param3, param4, this->defaultValue_[4]); } 144 inline MultiType operator()(T* object, const MultiType& param1, const MultiType& param2, const MultiType& param3, const MultiType& param4, const MultiType& param5) const 145 { return (*this->functorMember_)(object, param1, param2, param3, param4, param5); } 146 147 148 inline MultiType operator()(const T* object) const 149 { return (*this->functorMember_)(object, this->defaultValue_[0], this->defaultValue_[1], this->defaultValue_[2], this->defaultValue_[3], this->defaultValue_[4]); } 150 inline MultiType operator()(const T* object, const MultiType& param1) const 151 { return (*this->functorMember_)(object, param1, this->defaultValue_[1], this->defaultValue_[2], this->defaultValue_[3], this->defaultValue_[4]); } 152 inline MultiType operator()(const T* object, const MultiType& param1, const MultiType& param2) const 153 { return (*this->functorMember_)(object, param1, param2, this->defaultValue_[2], this->defaultValue_[3], this->defaultValue_[4]); } 154 inline MultiType operator()(const T* object, const MultiType& param1, const MultiType& param2, const MultiType& param3) const 155 { return (*this->functorMember_)(object, param1, param2, param3, this->defaultValue_[3], this->defaultValue_[4]); } 156 inline MultiType operator()(const T* object, const MultiType& param1, const MultiType& param2, const MultiType& param3, const MultiType& param4) const 157 { return (*this->functorMember_)(object, param1, param2, param3, param4, this->defaultValue_[4]); } 158 inline MultiType operator()(const T* object, const MultiType& param1, const MultiType& param2, const MultiType& param3, const MultiType& param4, const MultiType& param5) const 159 { return (*this->functorMember_)(object, param1, param2, param3, param4, param5); } 160 225 /// Calls the wrapped function with 1 argument and an object-pointer. If the function needs more arguments, the executor's default values are used. 226 inline MultiType operator()(T* object, const MultiType& arg1) const 227 { return (*this->functorMember_)(object, arg1, this->defaultValue_[1], this->defaultValue_[2], this->defaultValue_[3], this->defaultValue_[4]); } 228 /// Calls the wrapped function with 2 arguments and an object-pointer. If the function needs more arguments, the executor's default values are used. 229 inline MultiType operator()(T* object, const MultiType& arg1, const MultiType& arg2) const 230 { return (*this->functorMember_)(object, arg1, arg2, this->defaultValue_[2], this->defaultValue_[3], this->defaultValue_[4]); } 231 /// Calls the wrapped function with 3 arguments and an object-pointer. If the function needs more arguments, the executor's default values are used. 232 inline MultiType operator()(T* object, const MultiType& arg1, const MultiType& arg2, const MultiType& arg3) const 233 { return (*this->functorMember_)(object, arg1, arg2, arg3, this->defaultValue_[3], this->defaultValue_[4]); } 234 /// Calls the wrapped function with 4 arguments and an object-pointer. If the function needs more arguments, the executor's default values are used. 235 inline MultiType operator()(T* object, const MultiType& arg1, const MultiType& arg2, const MultiType& arg3, const MultiType& arg4) const 236 { return (*this->functorMember_)(object, arg1, arg2, arg3, arg4, this->defaultValue_[4]); } 237 /// Calls the wrapped function with 5 arguments and an object-pointer. If the function needs more arguments, the executor's default values are used. 238 inline MultiType operator()(T* object, const MultiType& arg1, const MultiType& arg2, const MultiType& arg3, const MultiType& arg4, const MultiType& arg5) const 239 { return (*this->functorMember_)(object, arg1, arg2, arg3, arg4, arg5); } 240 241 /// Changes the object-pointer of the underlying FunctorMember. 161 242 inline void setObject(T* object) const 162 243 { this->functorMember_->setObject(object); } 163 inline void setObject(const T* object) const 164 { this->functorMember_->setObject(object); } 244 /// Returns the object-pointer of the underlying FunctorMember. 245 inline T* getObject() const 246 { return this->functorMember_->getObject(); } 165 247 166 248 using Executor::parse; 167 249 168 MultiType parse(T* object, const std::string& params, int* error = 0, const std::string& delimiter = " ", bool bPrintError = false) const 250 /// Overloads Executor::parse() with an additional object-pointer. 251 MultiType parse(T* object, const std::string& arguments, int* error = 0, const std::string& delimiter = " ", bool bPrintError = false) const 169 252 { 170 253 T* oldobject = this->functorMember_->getObject(); 171 254 172 255 this->functorMember_->setObject(object); 173 const MultiType& result = this->Executor::parse( params, error, delimiter, bPrintError);256 const MultiType& result = this->Executor::parse(arguments, error, delimiter, bPrintError); 174 257 this->functorMember_->setObject(oldobject); 175 258 … … 177 260 } 178 261 179 MultiType parse(const T* object, const std::string& params, int* error = 0, const std::string& delimiter = " ", bool bPrintError = false) const180 {181 T* oldobject = this->functorMember_->getObject();182 183 this->functorMember_->setObject(object);184 const MultiType& result = this->Executor::parse(params, error, delimiter, bPrintError);185 this->functorMember_->setObjects(oldobject);186 187 return result;188 }189 190 262 protected: 191 FunctorMemberPtr<T> functorMember_; 263 FunctorMemberPtr<T> functorMember_; ///< A pointer to the FunctorMember is stored separately to avoid casting when executing the function. 192 264 }; 193 265 266 /// Creates a new Executor that wraps a given Functor. 194 267 inline ExecutorPtr createExecutor(const FunctorPtr& functor, const std::string& name = "") 195 268 { … … 197 270 } 198 271 272 /// Creates a new ExecutorMember that wraps a given FunctorMember. 199 273 template <class T> 200 274 inline ExecutorMemberPtr<T> createExecutor(const FunctorMemberPtr<T>& functor, const std::string& name = "") … … 203 277 } 204 278 279 /// Creates a new ExecutorStatic that wraps a given FunctorStatic. 205 280 inline ExecutorStaticPtr createExecutor(const FunctorStaticPtr& functor, const std::string& name = "") 206 281 { -
code/trunk/src/libraries/core/command/ExecutorPtr.h
r7284 r7401 27 27 */ 28 28 29 /** 30 @file 31 @ingroup Command FunctorExecutor 32 @brief Typedefs and definitions of ExecutorPtr, ExecutorStaticPtr, and ExecutorMemberPtr 33 34 Instances of orxonox::Executor are usually managed by an orxonox::SharedPtr. This ensures 35 that Executors will be destroyed after usage. To make things easier, there's a typedef 36 that defines ExecutorPtr as SharedPtr<Executor>. 37 38 Because there's not only orxonox::Executor, but also orxonox::ExecutorStatic, and 39 orxonox::ExecutorMember, the shared pointers need to store them all and also reflect 40 their hierarchy - ExecutorStatic and ExecutorMember should not be mixed, but both can 41 be converted to Executor. This is achieved by using orxonox::SharedChildPtr. 42 43 Because it's not possible to use a typedef for a template, we have to define the 44 helper class ExecutorMemberPtr<T> that makes it easier to use ExecutorMember. 45 */ 46 29 47 #ifndef _ExecutorPtr_H__ 30 48 #define _ExecutorPtr_H__ … … 35 53 namespace orxonox 36 54 { 55 /// ExecutorPtr is just a typedef of SharedPtr 37 56 typedef SharedPtr<Executor> ExecutorPtr; 38 57 58 /// ExecutorStaticPtr is just a typedef of SharedChildPtr 39 59 typedef SharedChildPtr<ExecutorStatic, ExecutorPtr> ExecutorStaticPtr; 40 60 61 /// It's not possible to use a typedef for ExecutorMemberPtr<T>, so we have to create a child-class instead. It inherits all functions from SharedChildPtr, but needs to (re-)implement some constructors. 41 62 template <class T> 42 63 class ExecutorMemberPtr : public SharedChildPtr<ExecutorMember<T>, ExecutorPtr> -
code/trunk/src/libraries/core/command/Functor.h
r7284 r7401 27 27 */ 28 28 29 /** 30 @file 31 @ingroup Command FunctorExecutor 32 @brief Definition of orxonox::Functor and its specialized subclasses, as well as the createFunctor() functions. 33 34 @anchor FunctorExample 35 36 Functors can be used to wrap function-pointers. While function-pointers have a very 37 complicated syntax in C++, Functors are always the same and you can call the wrapped 38 function-pointer independently of its parameter with arguments of type MultiType. These 39 arguments are then automatically converted to the right type. 40 41 To create a Functor, the helper function createFunctor() is used. It returns an instance 42 of orxonox::FunctorPtr which is simply a typedef of @ref orxonox::SharedPtr "SharedPtr<Functor>". 43 This means you don't have to delete the Functor after using it, because it is managed 44 by the SharedPtr. 45 46 Example: 47 @code 48 int myStaticFunction(int value) // Definition of a static function 49 { 50 return (value * 2); // Return the double of the value 51 } 52 53 FunctorPtr functor = createFunctor(&myStaticFunction); // Create a Functor 54 55 int result = (*functor)(5); // Calls the functor with value = 5, result == 10 56 57 int result = (*functor)("7"); // Calls the functor with a string which is converted to an integer, result == 14 58 @endcode 59 60 Functors can also be used if you work with member-functions. In this case createFunctor() 61 returns an instance of orxonox::FunctorMemberPtr - this allows you to define the object 62 that will be used to call the function. 63 64 Example: 65 @code 66 class MyClass // Define a class 67 { 68 public: 69 MyClass(const std::string& text) // Constructor 70 { 71 this->text_ = text; 72 } 73 74 bool contains(const std::string& word) // Function that searches for "word" in "text" 75 { 76 return (this->text_.find(word) != std::string::npos); 77 } 78 79 private: 80 std::string text_; // Member variable 81 }; 82 83 MyClass* object = new MyClass("Hello World"); // Create an object of type MyClass and set its text to "Hello World" 84 85 FunctorPtr functor = createFunctor(&MyClass:contains, object); // Create a Functor (note the object!) 86 87 bool result = (*functor)("World"); // result == true 88 bool result = (*functor)("test"); // result == false 89 @endcode 90 91 Instead of assigning the object directly to the functor when creating it, you can also define 92 it at any later point or when you call the functor. Note however that this works only with 93 orxonox::FunctorMember. 94 95 @code 96 MyClass* object1 = new MyClass("Hello World"); // Create an object 97 MyClass* object2 = new MyClass("this is a test"); // Create another object 98 99 FunctorMemberPtr functor = createFunctor(&MyClass:contains); // Create a FunctorMember (note: no object this time) 100 101 bool result = (*functor)("World"); // result == false and an error: "Error: Can't execute FunctorMember, no object set." 102 103 bool result = (*functor)(object1, "World"); // result == true 104 bool result = (*functor)(object1, "test"); // result == false 105 bool result = (*functor)(object2, "test"); // result == true 106 107 functor->setObject(object1); // Assign an object to the FunctorMember 108 109 bool result = (*functor)("World"); // result == true (no error this time, because the object was set using setObject()) 110 @endcode 111 */ 112 29 113 #ifndef _Functor_H__ 30 114 #define _Functor_H__ … … 40 124 namespace orxonox 41 125 { 42 const unsigned int MAX_FUNCTOR_ARGUMENTS = 5; 43 126 const unsigned int MAX_FUNCTOR_ARGUMENTS = 5; ///< The maximum number of parameters of a function that is supported by Functor 127 128 namespace detail 129 { 130 template <class T> 131 inline std::string _typeToString() { return "unknown"; } 132 133 template <> inline std::string _typeToString<void>() { return "void"; } 134 template <> inline std::string _typeToString<int>() { return "int"; } 135 template <> inline std::string _typeToString<unsigned int>() { return "uint"; } 136 template <> inline std::string _typeToString<char>() { return "char"; } 137 template <> inline std::string _typeToString<unsigned char>() { return "uchar"; } 138 template <> inline std::string _typeToString<short>() { return "short"; } 139 template <> inline std::string _typeToString<unsigned short>() { return "ushort"; } 140 template <> inline std::string _typeToString<long>() { return "long"; } 141 template <> inline std::string _typeToString<unsigned long>() { return "ulong"; } 142 template <> inline std::string _typeToString<long long>() { return "longlong"; } 143 template <> inline std::string _typeToString<unsigned long long>() { return "ulonglong"; } 144 template <> inline std::string _typeToString<float>() { return "float"; } 145 template <> inline std::string _typeToString<double>() { return "double"; } 146 template <> inline std::string _typeToString<long double>() { return "longdouble"; } 147 template <> inline std::string _typeToString<bool>() { return "bool"; } 148 template <> inline std::string _typeToString<std::string>() { return "string"; } 149 template <> inline std::string _typeToString<Vector2>() { return "Vector2"; } 150 template <> inline std::string _typeToString<Vector3>() { return "Vector3"; } 151 template <> inline std::string _typeToString<Quaternion>() { return "Quaternion"; } 152 template <> inline std::string _typeToString<ColourValue>() { return "ColourValue"; } 153 template <> inline std::string _typeToString<Radian>() { return "Radian"; } 154 template <> inline std::string _typeToString<Degree>() { return "Degree"; } 155 } 156 157 /// Returns the name of type @a T as string. 44 158 template <class T> 45 inline std::string _typeToString() { return "unknown"; } 46 47 template <> inline std::string _typeToString<void>() { return ""; } 48 template <> inline std::string _typeToString<int>() { return "int"; } 49 template <> inline std::string _typeToString<unsigned int>() { return "uint"; } 50 template <> inline std::string _typeToString<char>() { return "char"; } 51 template <> inline std::string _typeToString<unsigned char>() { return "uchar"; } 52 template <> inline std::string _typeToString<short>() { return "short"; } 53 template <> inline std::string _typeToString<unsigned short>() { return "ushort"; } 54 template <> inline std::string _typeToString<long>() { return "long"; } 55 template <> inline std::string _typeToString<unsigned long>() { return "ulong"; } 56 template <> inline std::string _typeToString<long long>() { return "longlong"; } 57 template <> inline std::string _typeToString<unsigned long long>() { return "ulonglong"; } 58 template <> inline std::string _typeToString<float>() { return "float"; } 59 template <> inline std::string _typeToString<double>() { return "double"; } 60 template <> inline std::string _typeToString<long double>() { return "longdouble"; } 61 template <> inline std::string _typeToString<bool>() { return "bool"; } 62 template <> inline std::string _typeToString<std::string>() { return "string"; } 63 template <> inline std::string _typeToString<Vector2>() { return "Vector2"; } 64 template <> inline std::string _typeToString<Vector3>() { return "Vector3"; } 65 template <> inline std::string _typeToString<Quaternion>() { return "Quaternion"; } 66 template <> inline std::string _typeToString<ColourValue>() { return "ColourValue"; } 67 template <> inline std::string _typeToString<Radian>() { return "Radian"; } 68 template <> inline std::string _typeToString<Degree>() { return "Degree"; } 69 70 template <class T> 71 inline std::string typeToString() { return _typeToString<typename Loki::TypeTraits<T>::UnqualifiedReferredType>(); } 72 159 inline std::string typeToString() { return detail::_typeToString<typename Loki::TypeTraits<T>::UnqualifiedReferredType>(); } 160 161 /** 162 @brief The Functor classes are used to wrap function pointers. 163 164 Function-pointers in C++ have a pretty complicated syntax and you can't store 165 and call them unless you know the exact type. A Functor can be used to wrap 166 a function-pointer and to store it independent of its type. You can also call 167 it independently of its parameters by passing the arguments as MultiType. They 168 are converted automatically to the right type. 169 170 Functor is a pure virtual base class. 171 172 @see See @ref FunctorExample "Functor.h" for some examples. 173 */ 73 174 class _CoreExport Functor 74 175 { … … 76 177 struct Type 77 178 { 179 /// Defines the type of a function (static or member) 78 180 enum Enum 79 181 { … … 84 186 85 187 public: 188 /// Calls the function-pointer with up to five arguments. In case of a member-function, the assigned object-pointer is used to call the function. @return Returns the return-value of the function (if any; MT_Type::Null otherwise) 86 189 virtual MultiType operator()(const MultiType& param1 = MT_Type::Null, const MultiType& param2 = MT_Type::Null, const MultiType& param3 = MT_Type::Null, const MultiType& param4 = MT_Type::Null, const MultiType& param5 = MT_Type::Null) = 0; 87 190 191 /// Creates a new instance of Functor with the same values like this (used instead of a copy-constructor) 88 192 virtual FunctorPtr clone() = 0; 89 193 194 /// Returns the type of the function: static or member. 90 195 virtual Type::Enum getType() const = 0; 196 /// Returns the number of parameters of the function. 91 197 virtual unsigned int getParamCount() const = 0; 198 /// Returns true if the function has a return-value. 92 199 virtual bool hasReturnvalue() const = 0; 93 200 94 virtual std::string getTypenameParam(unsigned int param) const = 0; 201 /// Returns the type-name of the parameter with given index (the first parameter has index 0). 202 virtual std::string getTypenameParam(unsigned int index) const = 0; 203 /// Returns the type-name of the return-value. 95 204 virtual std::string getTypenameReturnvalue() const = 0; 96 205 97 virtual void evaluateParam(unsigned int index, MultiType& param) const = 0; 98 99 virtual void setRawObjectPointer(void* object) {} 100 virtual void* getRawObjectPointer() const { return 0; } 101 102 template <class F> 103 inline bool setFunction(F* function) 104 { 105 if (this->getFullIdentifier() == typeid(F*)) 106 { 107 modifyFunctor(this, function); 108 return true; 109 } 110 return false; 111 } 112 206 /// Converts a given argument to the type of the parameter with given index (the first parameter has index 0). 207 virtual void evaluateArgument(unsigned int index, MultiType& argument) const = 0; 208 209 /// Assigns an object-pointer to the functor which is used to execute a member-function. 210 virtual void setRawObjectPointer(void* object) = 0; 211 /// Returns the object-pointer. 212 virtual void* getRawObjectPointer() const = 0; 213 214 /// Returns the full identifier of the function-pointer which is defined as typeid(@a F), where @a F is the type of the stored function-pointer. Used to compare functors. 113 215 virtual const std::type_info& getFullIdentifier() const = 0; 216 /// Returns an identifier of the header of the function (doesn't include the function's class). Used to compare functors. 114 217 virtual const std::type_info& getHeaderIdentifier() const = 0; 218 /// Returns an identifier of the header of the function (doesn't include the function's class), but regards only the first @a params parameters. Used to compare functions if an Executor provides default-values for the other parameters. 115 219 virtual const std::type_info& getHeaderIdentifier(unsigned int params) const = 0; 116 220 }; … … 118 222 namespace detail 119 223 { 224 // helper class to determine if a functor is static or not 120 225 template <class O> 121 226 struct FunctorTypeStatic … … 126 231 } 127 232 233 /** 234 @brief FunctorMember is a child class of Functor and expands it with an object-pointer, that 235 is used for member-functions, as well as an overloaded execution operator. 236 237 @param O The type of the function's class (or void if it's a static function) 238 239 Note that FunctorMember is also used for static functions, but with T = void. FunctorStatic 240 is a typedef of FunctorMember<void>. The void* object-pointer is ignored in this case. 241 242 @see See @ref FunctorExample "Functor.h" for some examples. 243 */ 128 244 template <class O> 129 245 class FunctorMember : public Functor 130 246 { 131 247 public: 248 /// Constructor: Stores the object-pointer. 132 249 FunctorMember(O* object = 0) : object_(object) {} 133 250 251 /// Calls the function-pointer with up to five arguments and an object. In case of a static-function, the object can be NULL. @return Returns the return-value of the function (if any; MT_Type::Null otherwise) 134 252 virtual MultiType operator()(O* object, const MultiType& param1 = MT_Type::Null, const MultiType& param2 = MT_Type::Null, const MultiType& param3 = MT_Type::Null, const MultiType& param4 = MT_Type::Null, const MultiType& param5 = MT_Type::Null) = 0; 135 253 254 // see Functor::operator()() 136 255 MultiType operator()(const MultiType& param1 = MT_Type::Null, const MultiType& param2 = MT_Type::Null, const MultiType& param3 = MT_Type::Null, const MultiType& param4 = MT_Type::Null, const MultiType& param5 = MT_Type::Null) 137 256 { 257 // call the function if it is static or if an object was assigned 138 258 if (detail::FunctorTypeStatic<O>::result || this->object_) 139 259 return (*this)(this->object_, param1, param2, param3, param4, param5); … … 145 265 } 146 266 267 // see Functor::getType() 147 268 Functor::Type::Enum getType() const 148 269 { return detail::FunctorTypeStatic<O>::result ? Functor::Type::Static : Functor::Type::Member; } 149 270 271 /// Assigns an object-pointer to the functor which is used to execute a member-function. 150 272 inline void setObject(O* object) 151 273 { this->object_ = object;} 274 /// Returns the object-pointer. 152 275 inline O* getObject() const 153 276 { return this->object_; } 154 277 278 // see Functor::setRawObjectPointer() 155 279 inline void setRawObjectPointer(void* object) 156 280 { this->object_ = (O*)object; } 281 // see Functor::getRawObjectPointer() 157 282 inline void* getRawObjectPointer() const 158 283 { return this->object_; } 159 284 160 285 protected: 161 O* object_; 286 O* object_; ///< The stored object-pointer, used to execute a member-function (or NULL for static functions) 162 287 }; 163 288 289 /// FunctorStatic is just a typedef of FunctorMember with @a T = void. 164 290 typedef FunctorMember<void> FunctorStatic; 165 291 292 /** 293 @brief FunctorPointer is a child class of FunctorMember and expands it with a function-pointer. 294 @param F The type of the function-pointer 295 @param O The type of the function's class (or void if it's a static function) 296 297 The template FunctorPointer has an additional template parameter that defines the type 298 of the function-pointer. This can be handy if you want to get or set the function-pointer. 299 You can then use a static_cast to cast a Functor to FunctorPointer if you know the type 300 of the function-pointer. 301 302 However FunctorPointer is not aware of the types of the different parameters or the 303 return value. 304 */ 166 305 template <class F, class O = void> 167 306 class FunctorPointer : public FunctorMember<O> 168 307 { 169 308 public: 309 /// Constructor: Initializes the base class and stores the function-pointer. 170 310 FunctorPointer(F functionPointer, O* object = 0) : FunctorMember<O>(object), functionPointer_(functionPointer) {} 171 311 312 /// Changes the function-pointer. 172 313 inline void setFunction(F functionPointer) 173 314 { this->functionPointer_ = functionPointer; } 315 /// Returns the function-pointer. 174 316 inline F getFunction() const 175 317 { return this->functionPointer_; } 176 318 319 // see Functor::getFullIdentifier() 177 320 const std::type_info& getFullIdentifier() const 178 321 { return typeid(F); } 179 322 180 323 protected: 181 F functionPointer_; 324 F functionPointer_; ///< The stored function-pointer 182 325 }; 183 326 184 327 namespace detail 185 328 { 329 // Helper class to get the type of the function pointer with the given class, parameters, return-value, and constness 186 330 template <class R, class O, bool isconst, class P1, class P2, class P3, class P4, class P5> struct FunctionPointer { typedef R (O::*Type)(P1, P2, P3, P4, P5); }; 187 331 template <class R, class O, class P1, class P2, class P3, class P4, class P5> struct FunctionPointer<R, O, false, P1, P2, P3, P4, P5> { typedef R (O::*Type)(P1, P2, P3, P4, P5); }; … … 204 348 template <class R> struct FunctionPointer<R, void, false, void, void, void, void, void> { typedef R (*Type)(); }; 205 349 350 // Helper class, used to call a function-pointer with a given object and parameters and to return its return-value (if available) 206 351 template <class R, class O, bool isconst, class P1, class P2, class P3, class P4, class P5> struct FunctorCaller { static inline MultiType call(typename detail::FunctionPointer<R, O, isconst, P1, P2, P3, P4, P5>::Type functionPointer, O* object, const MultiType& param1, const MultiType& param2, const MultiType& param3, const MultiType& param4, const MultiType& param5) { return (object->*functionPointer)(param1, param2, param3, param4, param5); } }; 207 352 template <class R, class O, bool isconst, class P1, class P2, class P3, class P4> struct FunctorCaller<R, O, isconst, P1, P2, P3, P4, void> { static inline MultiType call(typename detail::FunctionPointer<R, O, isconst, P1, P2, P3, P4, void>::Type functionPointer, O* object, const MultiType& param1, const MultiType& param2, const MultiType& param3, const MultiType& param4, const MultiType& param5) { return (object->*functionPointer)(param1, param2, param3, param4); } }; … … 229 374 template <bool isconst> struct FunctorCaller<void, void, isconst, void, void, void, void, void> { static inline MultiType call(typename detail::FunctionPointer<void, void, isconst, void, void, void, void, void>::Type functionPointer, void*, const MultiType& param1, const MultiType& param2, const MultiType& param3, const MultiType& param4, const MultiType& param5) { (*functionPointer)(); return MT_Type::Null; } }; 230 375 376 // Helper class, used to identify the header of a function-pointer (independent of its class) 231 377 template <class R, class P1, class P2, class P3, class P4, class P5> 232 378 struct FunctorHeaderIdentifier 233 379 {}; 234 380 381 // Helper class to determine if a function has a returnvalue 235 382 template <class T> 236 383 struct FunctorHasReturnvalue … … 240 387 { enum { result = false }; }; 241 388 389 // Helper class to count the number of parameters 242 390 template <class P1, class P2, class P3, class P4, class P5> 243 391 struct FunctorParamCount … … 260 408 } 261 409 410 /** 411 @brief FunctorTemplate is a child class of FunctorPointer and implements all functions 412 that need to know the exact types of the parameters, return-value, and class. 413 414 @param R The type of the return-value of the function 415 @param O The class of the function 416 @param isconst True if the function is a const member-function 417 @param P1 The type of the first parameter 418 @param P2 The type of the second parameter 419 @param P3 The type of the third parameter 420 @param P4 The type of the fourth parameter 421 @param P5 The type of the fifth parameter 422 423 This template has many parameters and is usually not used directly. It is created by 424 createFunctor(), but only the base-classes Functor, FunctorMember, and FunctorPointer 425 are used directly. It implements all the virtual functions that are declared by its 426 base classes. 427 428 All template arguments can be void. 429 */ 262 430 template <class R, class O, bool isconst, class P1, class P2, class P3, class P4, class P5> 263 431 class FunctorTemplate : public FunctorPointer<typename detail::FunctionPointer<R, O, isconst, P1, P2, P3, P4, P5>::Type, O> 264 432 { 265 433 public: 434 /// Constructor: Initializes the base class. 266 435 FunctorTemplate(typename detail::FunctionPointer<R, O, isconst, P1, P2, P3, P4, P5>::Type functionPointer, O* object = 0) : FunctorPointer<typename detail::FunctionPointer<R, O, isconst, P1, P2, P3, P4, P5>::Type, O>(functionPointer, object) {} 267 436 437 // see FunctorMember::operator()() 268 438 MultiType operator()(O* object, const MultiType& param1 = MT_Type::Null, const MultiType& param2 = MT_Type::Null, const MultiType& param3 = MT_Type::Null, const MultiType& param4 = MT_Type::Null, const MultiType& param5 = MT_Type::Null) 269 439 { … … 271 441 } 272 442 443 // see Functor::clone() 273 444 FunctorPtr clone() 274 445 { … … 276 447 } 277 448 278 void evaluateParam(unsigned int index, MultiType& param) const 449 // see Functor::evaluateArgument() 450 void evaluateArgument(unsigned int index, MultiType& argument) const 279 451 { 280 452 switch (index) 281 453 { 282 case 0: param.convert<P1>(); break;283 case 1: param.convert<P2>(); break;284 case 2: param.convert<P3>(); break;285 case 3: param.convert<P4>(); break;286 case 4: param.convert<P5>(); break;454 case 0: argument.convert<P1>(); break; 455 case 1: argument.convert<P2>(); break; 456 case 2: argument.convert<P3>(); break; 457 case 3: argument.convert<P4>(); break; 458 case 4: argument.convert<P5>(); break; 287 459 } 288 460 } 289 461 462 // see Functor::getParamCount() 290 463 unsigned int getParamCount() const 291 464 { … … 293 466 } 294 467 468 // see Functor::hasReturnvalue() 295 469 bool hasReturnvalue() const 296 470 { … … 298 472 } 299 473 300 std::string getTypenameParam(unsigned int param) const 301 { 302 switch (param) 474 // see Functor::getTypenameParam() 475 std::string getTypenameParam(unsigned int index) const 476 { 477 switch (index) 303 478 { 304 479 case 0: return typeToString<P1>(); … … 311 486 } 312 487 488 // see Functor::getTypenameReturnvalue() 313 489 std::string getTypenameReturnvalue() const 314 490 { … … 316 492 } 317 493 494 // see Functor::getHeaderIdentifier() 318 495 const std::type_info& getHeaderIdentifier() const 319 496 { … … 321 498 } 322 499 500 // see Functor::getHeaderIdentifier(unsigned int) 323 501 const std::type_info& getHeaderIdentifier(unsigned int params) const 324 502 { … … 335 513 }; 336 514 337 template <class R, class O, class OO, class P1, class P2, class P3, class P4, class P5> inline FunctorMemberPtr<O> createFunctor(R (O::*functionPointer)(P1, P2, P3, P4, P5), OO* object) { return new FunctorTemplate<R, O, false, P1, P2, P3, P4, P5>(functionPointer, object); } 338 template <class R, class O, class OO, class P1, class P2, class P3, class P4> inline FunctorMemberPtr<O> createFunctor(R (O::*functionPointer)(P1, P2, P3, P4), OO* object) { return new FunctorTemplate<R, O, false, P1, P2, P3, P4, void>(functionPointer, object); } 339 template <class R, class O, class OO, class P1, class P2, class P3> inline FunctorMemberPtr<O> createFunctor(R (O::*functionPointer)(P1, P2, P3), OO* object) { return new FunctorTemplate<R, O, false, P1, P2, P3, void, void>(functionPointer, object); } 340 template <class R, class O, class OO, class P1, class P2> inline FunctorMemberPtr<O> createFunctor(R (O::*functionPointer)(P1, P2), OO* object) { return new FunctorTemplate<R, O, false, P1, P2, void, void, void>(functionPointer, object); } 341 template <class R, class O, class OO, class P1> inline FunctorMemberPtr<O> createFunctor(R (O::*functionPointer)(P1), OO* object) { return new FunctorTemplate<R, O, false, P1, void, void, void, void>(functionPointer, object); } 342 template <class R, class O, class OO> inline FunctorMemberPtr<O> createFunctor(R (O::*functionPointer)(), OO* object) { return new FunctorTemplate<R, O, false, void, void, void, void, void>(functionPointer, object); } 343 template <class R, class O, class OO, class P1, class P2, class P3, class P4, class P5> inline FunctorMemberPtr<O> createFunctor(R (O::*functionPointer)(P1, P2, P3, P4, P5) const, OO* object) { return new FunctorTemplate<R, O, true, P1, P2, P3, P4, P5>(functionPointer, object); } 344 template <class R, class O, class OO, class P1, class P2, class P3, class P4> inline FunctorMemberPtr<O> createFunctor(R (O::*functionPointer)(P1, P2, P3, P4) const, OO* object) { return new FunctorTemplate<R, O, true, P1, P2, P3, P4, void>(functionPointer, object); } 345 template <class R, class O, class OO, class P1, class P2, class P3> inline FunctorMemberPtr<O> createFunctor(R (O::*functionPointer)(P1, P2, P3) const, OO* object) { return new FunctorTemplate<R, O, true, P1, P2, P3, void, void>(functionPointer, object); } 346 template <class R, class O, class OO, class P1, class P2> inline FunctorMemberPtr<O> createFunctor(R (O::*functionPointer)(P1, P2) const, OO* object) { return new FunctorTemplate<R, O, true, P1, P2, void, void, void>(functionPointer, object); } 347 template <class R, class O, class OO, class P1> inline FunctorMemberPtr<O> createFunctor(R (O::*functionPointer)(P1) const, OO* object) { return new FunctorTemplate<R, O, true, P1, void, void, void, void>(functionPointer, object); } 348 template <class R, class O, class OO> inline FunctorMemberPtr<O> createFunctor(R (O::*functionPointer)() const, OO* object) { return new FunctorTemplate<R, O, true, void, void, void, void, void>(functionPointer, object); } 349 350 template <class R, class O, class P1, class P2, class P3, class P4, class P5> inline FunctorMemberPtr<O> createFunctor(R (O::*functionPointer)(P1, P2, P3, P4, P5)) { return new FunctorTemplate<R, O, false, P1, P2, P3, P4, P5>(functionPointer); } 351 template <class R, class O, class P1, class P2, class P3, class P4> inline FunctorMemberPtr<O> createFunctor(R (O::*functionPointer)(P1, P2, P3, P4)) { return new FunctorTemplate<R, O, false, P1, P2, P3, P4, void>(functionPointer); } 352 template <class R, class O, class P1, class P2, class P3> inline FunctorMemberPtr<O> createFunctor(R (O::*functionPointer)(P1, P2, P3)) { return new FunctorTemplate<R, O, false, P1, P2, P3, void, void>(functionPointer); } 353 template <class R, class O, class P1, class P2> inline FunctorMemberPtr<O> createFunctor(R (O::*functionPointer)(P1, P2)) { return new FunctorTemplate<R, O, false, P1, P2, void, void, void>(functionPointer); } 354 template <class R, class O, class P1> inline FunctorMemberPtr<O> createFunctor(R (O::*functionPointer)(P1)) { return new FunctorTemplate<R, O, false, P1, void, void, void, void>(functionPointer); } 355 template <class R, class O> inline FunctorMemberPtr<O> createFunctor(R (O::*functionPointer)()) { return new FunctorTemplate<R, O, false, void, void, void, void, void>(functionPointer); } 356 template <class R, class O, class P1, class P2, class P3, class P4, class P5> inline FunctorMemberPtr<O> createFunctor(R (O::*functionPointer)(P1, P2, P3, P4, P5) const) { return new FunctorTemplate<R, O, true, P1, P2, P3, P4, P5>(functionPointer); } 357 template <class R, class O, class P1, class P2, class P3, class P4> inline FunctorMemberPtr<O> createFunctor(R (O::*functionPointer)(P1, P2, P3, P4) const) { return new FunctorTemplate<R, O, true, P1, P2, P3, P4, void>(functionPointer); } 358 template <class R, class O, class P1, class P2, class P3> inline FunctorMemberPtr<O> createFunctor(R (O::*functionPointer)(P1, P2, P3) const) { return new FunctorTemplate<R, O, true, P1, P2, P3, void, void>(functionPointer); } 359 template <class R, class O, class P1, class P2> inline FunctorMemberPtr<O> createFunctor(R (O::*functionPointer)(P1, P2) const) { return new FunctorTemplate<R, O, true, P1, P2, void, void, void>(functionPointer); } 360 template <class R, class O, class P1> inline FunctorMemberPtr<O> createFunctor(R (O::*functionPointer)(P1) const) { return new FunctorTemplate<R, O, true, P1, void, void, void, void>(functionPointer); } 361 template <class R, class O> inline FunctorMemberPtr<O> createFunctor(R (O::*functionPointer)() const) { return new FunctorTemplate<R, O, true, void, void, void, void, void>(functionPointer); } 362 363 template <class R, class P1, class P2, class P3, class P4, class P5> inline FunctorStaticPtr createFunctor(R (*functionPointer)(P1, P2, P3, P4, P5)) { return new FunctorTemplate<R, void, false, P1, P2, P3, P4, P5>(functionPointer); } 364 template <class R, class P1, class P2, class P3, class P4> inline FunctorStaticPtr createFunctor(R (*functionPointer)(P1, P2, P3, P4)) { return new FunctorTemplate<R, void, false, P1, P2, P3, P4, void>(functionPointer); } 365 template <class R, class P1, class P2, class P3> inline FunctorStaticPtr createFunctor(R (*functionPointer)(P1, P2, P3)) { return new FunctorTemplate<R, void, false, P1, P2, P3, void, void>(functionPointer); } 366 template <class R, class P1, class P2> inline FunctorStaticPtr createFunctor(R (*functionPointer)(P1, P2)) { return new FunctorTemplate<R, void, false, P1, P2, void, void, void>(functionPointer); } 367 template <class R, class P1> inline FunctorStaticPtr createFunctor(R (*functionPointer)(P1)) { return new FunctorTemplate<R, void, false, P1, void, void, void, void>(functionPointer); } 368 template <class R> inline FunctorStaticPtr createFunctor(R (*functionPointer)()) { return new FunctorTemplate<R, void, false, void, void, void, void, void>(functionPointer); } 515 template <class R, class O, class OO, class P1, class P2, class P3, class P4, class P5> inline FunctorMemberPtr<O> createFunctor(R (O::*functionPointer)(P1, P2, P3, P4, P5), OO* object) { return new FunctorTemplate<R, O, false, P1, P2, P3, P4, P5>(functionPointer, object); } ///< Creates a new FunctorMember with the given function-pointer and an assigned object 516 template <class R, class O, class OO, class P1, class P2, class P3, class P4> inline FunctorMemberPtr<O> createFunctor(R (O::*functionPointer)(P1, P2, P3, P4), OO* object) { return new FunctorTemplate<R, O, false, P1, P2, P3, P4, void>(functionPointer, object); } ///< Creates a new FunctorMember with the given function-pointer and an assigned object 517 template <class R, class O, class OO, class P1, class P2, class P3> inline FunctorMemberPtr<O> createFunctor(R (O::*functionPointer)(P1, P2, P3), OO* object) { return new FunctorTemplate<R, O, false, P1, P2, P3, void, void>(functionPointer, object); } ///< Creates a new FunctorMember with the given function-pointer and an assigned object 518 template <class R, class O, class OO, class P1, class P2> inline FunctorMemberPtr<O> createFunctor(R (O::*functionPointer)(P1, P2), OO* object) { return new FunctorTemplate<R, O, false, P1, P2, void, void, void>(functionPointer, object); } ///< Creates a new FunctorMember with the given function-pointer and an assigned object 519 template <class R, class O, class OO, class P1> inline FunctorMemberPtr<O> createFunctor(R (O::*functionPointer)(P1), OO* object) { return new FunctorTemplate<R, O, false, P1, void, void, void, void>(functionPointer, object); } ///< Creates a new FunctorMember with the given function-pointer and an assigned object 520 template <class R, class O, class OO> inline FunctorMemberPtr<O> createFunctor(R (O::*functionPointer)(), OO* object) { return new FunctorTemplate<R, O, false, void, void, void, void, void>(functionPointer, object); } ///< Creates a new FunctorMember with the given function-pointer and an assigned object 521 template <class R, class O, class OO, class P1, class P2, class P3, class P4, class P5> inline FunctorMemberPtr<O> createFunctor(R (O::*functionPointer)(P1, P2, P3, P4, P5) const, OO* object) { return new FunctorTemplate<R, O, true, P1, P2, P3, P4, P5>(functionPointer, object); } ///< Creates a new FunctorMember with the given function-pointer and an assigned object 522 template <class R, class O, class OO, class P1, class P2, class P3, class P4> inline FunctorMemberPtr<O> createFunctor(R (O::*functionPointer)(P1, P2, P3, P4) const, OO* object) { return new FunctorTemplate<R, O, true, P1, P2, P3, P4, void>(functionPointer, object); } ///< Creates a new FunctorMember with the given function-pointer and an assigned object 523 template <class R, class O, class OO, class P1, class P2, class P3> inline FunctorMemberPtr<O> createFunctor(R (O::*functionPointer)(P1, P2, P3) const, OO* object) { return new FunctorTemplate<R, O, true, P1, P2, P3, void, void>(functionPointer, object); } ///< Creates a new FunctorMember with the given function-pointer and an assigned object 524 template <class R, class O, class OO, class P1, class P2> inline FunctorMemberPtr<O> createFunctor(R (O::*functionPointer)(P1, P2) const, OO* object) { return new FunctorTemplate<R, O, true, P1, P2, void, void, void>(functionPointer, object); } ///< Creates a new FunctorMember with the given function-pointer and an assigned object 525 template <class R, class O, class OO, class P1> inline FunctorMemberPtr<O> createFunctor(R (O::*functionPointer)(P1) const, OO* object) { return new FunctorTemplate<R, O, true, P1, void, void, void, void>(functionPointer, object); } ///< Creates a new FunctorMember with the given function-pointer and an assigned object 526 template <class R, class O, class OO> inline FunctorMemberPtr<O> createFunctor(R (O::*functionPointer)() const, OO* object) { return new FunctorTemplate<R, O, true, void, void, void, void, void>(functionPointer, object); } ///< Creates a new FunctorMember with the given function-pointer and an assigned object 527 528 template <class R, class O, class P1, class P2, class P3, class P4, class P5> inline FunctorMemberPtr<O> createFunctor(R (O::*functionPointer)(P1, P2, P3, P4, P5)) { return new FunctorTemplate<R, O, false, P1, P2, P3, P4, P5>(functionPointer); } ///< Creates a new FunctorMember with the given function-pointer 529 template <class R, class O, class P1, class P2, class P3, class P4> inline FunctorMemberPtr<O> createFunctor(R (O::*functionPointer)(P1, P2, P3, P4)) { return new FunctorTemplate<R, O, false, P1, P2, P3, P4, void>(functionPointer); } ///< Creates a new FunctorMember with the given function-pointer 530 template <class R, class O, class P1, class P2, class P3> inline FunctorMemberPtr<O> createFunctor(R (O::*functionPointer)(P1, P2, P3)) { return new FunctorTemplate<R, O, false, P1, P2, P3, void, void>(functionPointer); } ///< Creates a new FunctorMember with the given function-pointer 531 template <class R, class O, class P1, class P2> inline FunctorMemberPtr<O> createFunctor(R (O::*functionPointer)(P1, P2)) { return new FunctorTemplate<R, O, false, P1, P2, void, void, void>(functionPointer); } ///< Creates a new FunctorMember with the given function-pointer 532 template <class R, class O, class P1> inline FunctorMemberPtr<O> createFunctor(R (O::*functionPointer)(P1)) { return new FunctorTemplate<R, O, false, P1, void, void, void, void>(functionPointer); } ///< Creates a new FunctorMember with the given function-pointer 533 template <class R, class O> inline FunctorMemberPtr<O> createFunctor(R (O::*functionPointer)()) { return new FunctorTemplate<R, O, false, void, void, void, void, void>(functionPointer); } ///< Creates a new FunctorMember with the given function-pointer 534 template <class R, class O, class P1, class P2, class P3, class P4, class P5> inline FunctorMemberPtr<O> createFunctor(R (O::*functionPointer)(P1, P2, P3, P4, P5) const) { return new FunctorTemplate<R, O, true, P1, P2, P3, P4, P5>(functionPointer); } ///< Creates a new FunctorMember with the given function-pointer 535 template <class R, class O, class P1, class P2, class P3, class P4> inline FunctorMemberPtr<O> createFunctor(R (O::*functionPointer)(P1, P2, P3, P4) const) { return new FunctorTemplate<R, O, true, P1, P2, P3, P4, void>(functionPointer); } ///< Creates a new FunctorMember with the given function-pointer 536 template <class R, class O, class P1, class P2, class P3> inline FunctorMemberPtr<O> createFunctor(R (O::*functionPointer)(P1, P2, P3) const) { return new FunctorTemplate<R, O, true, P1, P2, P3, void, void>(functionPointer); } ///< Creates a new FunctorMember with the given function-pointer 537 template <class R, class O, class P1, class P2> inline FunctorMemberPtr<O> createFunctor(R (O::*functionPointer)(P1, P2) const) { return new FunctorTemplate<R, O, true, P1, P2, void, void, void>(functionPointer); } ///< Creates a new FunctorMember with the given function-pointer 538 template <class R, class O, class P1> inline FunctorMemberPtr<O> createFunctor(R (O::*functionPointer)(P1) const) { return new FunctorTemplate<R, O, true, P1, void, void, void, void>(functionPointer); } ///< Creates a new FunctorMember with the given function-pointer 539 template <class R, class O> inline FunctorMemberPtr<O> createFunctor(R (O::*functionPointer)() const) { return new FunctorTemplate<R, O, true, void, void, void, void, void>(functionPointer); } ///< Creates a new FunctorMember with the given function-pointer 540 541 template <class R, class P1, class P2, class P3, class P4, class P5> inline FunctorStaticPtr createFunctor(R (*functionPointer)(P1, P2, P3, P4, P5)) { return new FunctorTemplate<R, void, false, P1, P2, P3, P4, P5>(functionPointer); } ///< Creates a new Functor with the given function-pointer 542 template <class R, class P1, class P2, class P3, class P4> inline FunctorStaticPtr createFunctor(R (*functionPointer)(P1, P2, P3, P4)) { return new FunctorTemplate<R, void, false, P1, P2, P3, P4, void>(functionPointer); } ///< Creates a new Functor with the given function-pointer 543 template <class R, class P1, class P2, class P3> inline FunctorStaticPtr createFunctor(R (*functionPointer)(P1, P2, P3)) { return new FunctorTemplate<R, void, false, P1, P2, P3, void, void>(functionPointer); } ///< Creates a new Functor with the given function-pointer 544 template <class R, class P1, class P2> inline FunctorStaticPtr createFunctor(R (*functionPointer)(P1, P2)) { return new FunctorTemplate<R, void, false, P1, P2, void, void, void>(functionPointer); } ///< Creates a new Functor with the given function-pointer 545 template <class R, class P1> inline FunctorStaticPtr createFunctor(R (*functionPointer)(P1)) { return new FunctorTemplate<R, void, false, P1, void, void, void, void>(functionPointer); } ///< Creates a new Functor with the given function-pointer 546 template <class R> inline FunctorStaticPtr createFunctor(R (*functionPointer)()) { return new FunctorTemplate<R, void, false, void, void, void, void, void>(functionPointer); } ///< Creates a new Functor with the given function-pointer 369 547 } 370 548 -
code/trunk/src/libraries/core/command/FunctorPtr.h
r7284 r7401 27 27 */ 28 28 29 /** 30 @file 31 @ingroup Command FunctorExecutor 32 @brief Typedefs and definitions of FunctorPtr, FunctorMemberPtr, FunctorStaticPtr, and FunctorPointerPtr 33 34 Instances of orxonox::Functor are usually managed by an orxonox::SharedPtr. This ensures 35 that Functors will be destroyed after usage. To make things easier, there's a typedef 36 that defines FunctorPtr as SharedPtr<Functor>. 37 38 Because there's not only orxonox::Functor, but also orxonox::FunctorStatic, and 39 orxonox::FunctorMember, the shared pointers need to store them all and also reflect 40 their hierarchy - FunctorStatic and FunctorMember should not be mixed, but both can 41 be converted to Functor. This is achieved by using orxonox::SharedChildPtr. 42 43 Because it's not possible to use a typedef for a template, we have to define the 44 helper class FunctorMemberPtr<T> that makes it easier to use FunctorMember. The 45 same is also done for FunctorPointerPtr<T>, which can be converted to both, 46 FunctorMemberPtr<T> as well as FunctorPtr. 47 */ 48 29 49 #ifndef _FunctorPtr_H__ 30 50 #define _FunctorPtr_H__ … … 35 55 namespace orxonox 36 56 { 57 /// FunctorPtr is just a typedef of SharedPtr 37 58 typedef SharedPtr<Functor> FunctorPtr; 38 59 60 /// It's not possible to use a typedef for FunctorMemberPtr<T>, so we have to create a child-class instead. It inherits all functions from SharedChildPtr, but needs to (re-)implement some constructors. 39 61 template <class T> 40 62 class FunctorMemberPtr : public SharedChildPtr<FunctorMember<T>, FunctorPtr> … … 46 68 }; 47 69 70 /// FunctorStaticPtr is just FunctorMemberPtr with @a T = void 48 71 typedef FunctorMemberPtr<void> FunctorStaticPtr; 49 72 73 /// It's not possible to use a typedef for FunctorPointerPtr<T>, so we have to create a child-class instead. It inherits all functions from SharedChildPtr, but needs to (re-)implement some constructors. 50 74 template <class F, class T> 51 75 class FunctorPointerPtr : public SharedChildPtr<FunctorPointer<F, T>, FunctorMemberPtr<T> > -
code/trunk/src/libraries/core/command/IOConsole.h
r7287 r7401 27 27 */ 28 28 29 /** 30 @file 31 @ingroup Command ShellConsole 32 */ 33 29 34 #include "OrxonoxConfig.h" 30 35 -
code/trunk/src/libraries/core/command/IOConsolePOSIX.h
r7287 r7401 27 27 * 28 28 */ 29 30 /** 31 @file 32 @ingroup Command ShellConsole 33 */ 29 34 30 35 #ifndef _IOConsole_H__ -
code/trunk/src/libraries/core/command/IOConsoleWindows.h
r7287 r7401 26 26 * 27 27 */ 28 29 /** 30 @file 31 @ingroup Command ShellConsole 32 */ 28 33 29 34 #ifndef _IOConsole_H__ -
code/trunk/src/libraries/core/command/IRC.cc
r7284 r7401 27 27 */ 28 28 29 /** 30 @file 31 @brief Implementation of the IRC class and the IRC console commands. 32 */ 33 29 34 #include "IRC.h" 30 35 … … 39 44 namespace orxonox 40 45 { 41 static const unsigned int IRC_TCL_THREADID = 1421421421; 46 static const unsigned int IRC_TCL_THREADID = 1421421421; ///< The ID of the thread in TclThreadManager that is used for the IRC connection 42 47 43 48 SetConsoleCommand("IRC", "say", &IRC::say); … … 45 50 SetConsoleCommand("IRC", "nick", &IRC::nick); 46 51 52 /** 53 @brief Returns the only existing instance of IRC. 54 */ 55 IRC& IRC::getInstance() 56 { 57 static IRC instance; 58 return instance; 59 } 60 61 /** 62 @brief Constructor: Doesn't yet connect to IRC nor does it create a Tcl interpreter. 63 The IRC object will automatically connect to the IRC server if one of the registered 64 console commands is used the first time. 65 */ 47 66 IRC::IRC() 48 67 { … … 50 69 } 51 70 71 /** 72 @brief Creates and initializes a new multithreaded Tcl-interpreter and defines some callbacks to display IRC-messages in the console. 73 */ 52 74 void IRC::initialize() 53 75 { … … 70 92 } 71 93 72 IRC& IRC::getInstance() 73 { 74 static IRC instance; 75 return instance; 76 } 77 94 /** 95 @brief Executes a Tcl-command on the Tcl-interpreter. 96 */ 78 97 bool IRC::eval(const std::string& command) 79 98 { … … 96 115 } 97 116 117 /// Console command: Sends a message to the current channel on the IRC server. 98 118 void IRC::say(const std::string& message) 99 119 { … … 102 122 } 103 123 124 /// Console command: Sends a message to a given channel or nickname on the IRC server. 104 125 void IRC::msg(const std::string& channel, const std::string& message) 105 126 { … … 108 129 } 109 130 131 /// Console command: Changes the nickname on the IRC server. 110 132 void IRC::nick(const std::string& nickname) 111 133 { … … 114 136 } 115 137 138 /// Tcl-callback: Prints a message that was received from the current IRC channel to the console. 116 139 void IRC::tcl_say(Tcl::object const &channel, Tcl::object const &nick, Tcl::object const &args) 117 140 { … … 119 142 } 120 143 144 /// Tcl-callback: Prints a private message that was received from a user to the console. 121 145 void IRC::tcl_privmsg(Tcl::object const &query, Tcl::object const &nick, Tcl::object const &args) 122 146 { … … 124 148 } 125 149 150 /// Tcl-callback: Prints an action-message (usually /me ...) that was received from the current IRC channel to the console. 126 151 void IRC::tcl_action(Tcl::object const &channel, Tcl::object const &nick, Tcl::object const &args) 127 152 { … … 129 154 } 130 155 156 /// Tcl-callback: Prints all kinds of information that were received from the IRC server or channel (connection info, join, part, modes, ...) to the console. 131 157 void IRC::tcl_info(Tcl::object const &channel, Tcl::object const &args) 132 158 { -
code/trunk/src/libraries/core/command/IRC.h
r7284 r7401 27 27 */ 28 28 29 /** 30 @file 31 @ingroup Command Tcl 32 @brief Declaration of IRC helper class, used for IRC connections using Tcl. 33 */ 34 29 35 #ifndef _IRC_H__ 30 36 #define _IRC_H__ … … 36 42 namespace orxonox 37 43 { 44 /** 45 @brief The IRC class creates a Tcl-thread (see TclThreadManager) and connects to an IRC server. 46 It provides different console commands to send messages and to perform other actions on the IRC server. 47 */ 38 48 class _CoreExport IRC 39 49 { … … 55 65 56 66 IRC(); 57 IRC(const IRC& other); 58 ~IRC() {} 67 IRC(const IRC& other); ///< Copy-constructor: Not implemented 68 ~IRC() {} ///< Destructor 59 69 60 Tcl::interpreter* interpreter_; 61 std::string nickname_; 70 Tcl::interpreter* interpreter_; ///< The Tcl interpreter that is used for the IRC connection 71 std::string nickname_; ///< The user's nickname on the IRC server 62 72 }; 63 73 } -
code/trunk/src/libraries/core/command/Shell.cc
r7284 r7401 26 26 * 27 27 */ 28 29 /** 30 @file 31 @brief Implementation of the Shell class. 32 */ 28 33 29 34 #include "Shell.h" … … 48 53 unsigned int Shell::cacheSize_s; 49 54 55 /** 56 @brief Constructor: Initializes the values and registers itself at OutputHandler. 57 @param consoleName The name of the shell - used to define the name of the soft-debug-level config-value 58 @param bScrollable If true, the user is allowed to scroll through the output-lines 59 */ 50 60 Shell::Shell(const std::string& consoleName, bool bScrollable) 51 61 : OutputListener(consoleName) … … 88 98 } 89 99 100 /** 101 @brief Destructor: Unregisters the shell from OutputHandler. 102 */ 90 103 Shell::~Shell() 91 104 { … … 94 107 } 95 108 109 /** 110 @brief Defines the config values. 111 */ 96 112 void Shell::setConfigValues() 97 113 { … … 113 129 } 114 130 131 /** 132 @brief Config-value callback: Called when the history offset has changed in the config-file. 133 */ 115 134 void Shell::commandHistoryOffsetChanged() 116 135 { … … 119 138 } 120 139 140 /** 141 @brief Config-value callback: Called when the length of the command history has changed in the config-file. 142 */ 121 143 void Shell::commandHistoryLengthChanged() 122 144 { … … 131 153 } 132 154 155 /** 156 @brief Registers this object as listener for different key-events at the input buffer. 157 */ 133 158 void Shell::configureInputBuffer() 134 159 { … … 159 184 } 160 185 161 /* 162 void Shell::history() 163 { 164 Shell& instance = Shell::getInstance(); 165 166 for (unsigned int i = instance.historyOffset_; i < instance.commandHistory_.size(); ++i) 167 instance.addOutput(instance.commandHistory_[i] + '\n', -1); 168 for (unsigned int i = 0; i < instance.historyOffset_; ++i) 169 instance.addOutput(instance.commandHistory_[i] + '\n', -1); 170 } 171 */ 172 186 /** 187 @brief Registers a shell listener which listens for changes in this shell. 188 */ 173 189 void Shell::registerListener(ShellListener* listener) 174 190 { … … 176 192 } 177 193 194 /** 195 @brief Unregisters a shell listener. 196 */ 178 197 void Shell::unregisterListener(ShellListener* listener) 179 198 { … … 187 206 } 188 207 208 /** 209 @brief Changes the position of the cursor in the input buffer. 210 */ 189 211 void Shell::setCursorPosition(unsigned int cursor) 190 212 { … … 193 215 } 194 216 217 /** 218 @brief Sends output to the internal output buffer. 219 */ 195 220 void Shell::addOutput(const std::string& text, LineType type) 196 221 { … … 199 224 } 200 225 226 /** 227 @brief Clears the list of output-lines. 228 */ 201 229 void Shell::clearOutput() 202 230 { … … 210 238 } 211 239 240 /** 241 @brief Returns an iterator to the newest line of output (except if the user is currently scrolling through the output). 242 */ 212 243 Shell::LineList::const_iterator Shell::getNewestLineIterator() const 213 244 { … … 218 249 } 219 250 251 /** 252 @brief Returns the end() iterator of the list of output-lines. 253 */ 220 254 Shell::LineList::const_iterator Shell::getEndIterator() const 221 255 { … … 223 257 } 224 258 259 /** 260 @brief Adds a command to the history of entered commands and writes it to the config-file. 261 */ 225 262 void Shell::addToHistory(const std::string& command) 226 263 { … … 237 274 } 238 275 276 /** 277 @brief Returns a command from the history of entered commands (usually the most recent history entry, but the user can scroll through the history). 278 */ 239 279 const std::string& Shell::getFromHistory() const 240 280 { … … 246 286 } 247 287 288 /** 289 @brief Called by OutputHandler or internally whenever output was sent to the output buffer. Reads from the buffer and writes the new output-lines to the list. 290 */ 248 291 void Shell::outputChanged(int lineType) 249 292 { … … 251 294 do 252 295 { 296 // get the first line from the buffer 253 297 std::string output; 254 298 std::getline(this->outputBuffer_, output); 255 299 300 // check the state of the buffer 256 301 bool eof = this->outputBuffer_.eof(); 257 302 bool fail = this->outputBuffer_.fail(); 258 303 if (eof) 259 this->outputBuffer_.flush(); 304 this->outputBuffer_.flush(); // check if more output was received in the meantime 260 305 if (eof || fail) 261 this->outputBuffer_.clear(); 306 this->outputBuffer_.clear(); // clear the error flags 307 308 // the line is terminated with a line-break if neither an error occurred nor the end of the file was reached 262 309 newline = (!eof && !fail); 263 310 311 // no output retrieved - break the loop 264 312 if (!newline && output.empty()) 265 313 break; 266 314 315 // check if the last line was terminated with a line-break 267 316 if (this->bFinishedLastLine_) 268 317 { 318 // yes it was - push the new line to the list 269 319 this->outputLines_.push_front(std::make_pair(output, static_cast<LineType>(lineType))); 270 320 321 // adjust the scroll position if needed 271 322 if (this->scrollPosition_) 272 323 this->scrollPosition_++; 273 324 else 274 325 this->scrollIterator_ = this->outputLines_.begin(); 275 276 this->bFinishedLastLine_ = newline;277 326 278 327 if (!this->scrollPosition_) … … 281 330 else 282 331 { 332 // no it wasn't - add the new output to the last line 283 333 this->outputLines_.front().first += output; 284 this->bFinishedLastLine_ = newline;285 334 this->updateListeners<&ShellListener::onlyLastLineChanged>(); 286 335 } 336 337 // remember if the last line was terminated with a line-break 287 338 this->bFinishedLastLine_ = newline; 288 339 289 } while (newline); 290 } 291 340 } while (newline); // loop as long as more lines are in the buffer 341 } 342 343 /** 344 @brief Clears the text in the input buffer. 345 */ 292 346 void Shell::clearInput() 293 347 { … … 298 352 } 299 353 300 void Shell::setPromptPrefix(const std::string& str)301 {302 }303 304 354 305 355 // ########################################## … … 307 357 // ########################################## 308 358 359 /// InputBuffer callback: Called if the input changes. 309 360 void Shell::inputChanged() 310 361 { … … 313 364 } 314 365 366 /// InputBuffer callback: Called if a key was pressed that executes a command (usually [return]). 315 367 void Shell::execute() 316 368 { … … 340 392 } 341 393 394 /// InputBuffer callback: Called if a key was pressed that shows hints and completes a command (usually [tab]). 342 395 void Shell::hintAndComplete() 343 396 { … … 349 402 } 350 403 404 /// InputBuffer callback: Called if a key was pressed that deletes the character before the cursor (usually [backspace]). 351 405 void Shell::backspace() 352 406 { … … 356 410 } 357 411 358 void Shell::exit() 359 { 360 if (this->inputBuffer_->getSize() > 0) 361 { 362 this->clearInput(); 363 return; 364 } 365 366 this->clearInput(); 367 this->scrollPosition_ = 0; 368 this->scrollIterator_ = this->outputLines_.begin(); 369 370 this->updateListeners<&ShellListener::exit>(); 371 } 372 412 /// InputBuffer callback: Called if a key was pressed that deletes the character after the cursor (usually [delete]). 373 413 void Shell::deleteChar() 374 414 { … … 377 417 } 378 418 419 /// InputBuffer callback: Called if a key was pressed that moves the input cursor the right (usually [arrow right]). 379 420 void Shell::cursorRight() 380 421 { … … 383 424 } 384 425 426 /// InputBuffer callback: Called if a key was pressed that moves the input cursor the left (usually [arrow left]). 385 427 void Shell::cursorLeft() 386 428 { … … 389 431 } 390 432 433 /// InputBuffer callback: Called if a key was pressed that moves the input cursor the end of the input line (usually [end]). 391 434 void Shell::cursorEnd() 392 435 { … … 395 438 } 396 439 440 /// InputBuffer callback: Called if a key was pressed that moves the input cursor the beginning of the input line (usually [home]). 397 441 void Shell::cursorHome() 398 442 { … … 401 445 } 402 446 447 /// InputBuffer callback: Called if a key was pressed that scrolls upwards through the history of entered commands (usually [arrow up]). 403 448 void Shell::historyUp() 404 449 { … … 410 455 } 411 456 457 /// InputBuffer callback: Called if a key was pressed that scrolls downwards through the history of entered commands (usually [arrow down]). 412 458 void Shell::historyDown() 413 459 { … … 419 465 } 420 466 467 /// InputBuffer callback: Called if a key was pressed that searches upwards through the history for a command stat starts like the one the user is currently typing (usually [page up]). Only if the shell is not scrollable. 421 468 void Shell::historySearchUp() 422 469 { … … 437 484 } 438 485 486 /// InputBuffer callback: Called if a key was pressed that searches downwards through the history for a command stat starts like the one the user is currently typing (usually [page down]). Only if the shell is not scrollable. 439 487 void Shell::historySearchDown() 440 488 { … … 455 503 } 456 504 505 /// InputBuffer callback: Called if a key was pressed that scrolls upwards through the output history (usually [page up]). Only if the shell is scrollable. 457 506 void Shell::scrollUp() 458 507 { … … 466 515 } 467 516 517 /// InputBuffer callback: Called if a key was pressed that scrolls downwards through the output history (usually [page down]). Only if the shell is scrollable. 468 518 void Shell::scrollDown() 469 519 { … … 476 526 } 477 527 } 528 529 /// InputBuffer callback: Called if a key was pressed that clears the text in the input buffer or closes the shell (usually [esc]). 530 void Shell::exit() 531 { 532 if (this->inputBuffer_->getSize() > 0) 533 { 534 this->clearInput(); 535 return; 536 } 537 538 this->clearInput(); 539 this->scrollPosition_ = 0; 540 this->scrollIterator_ = this->outputLines_.begin(); 541 542 this->updateListeners<&ShellListener::exit>(); 543 } 478 544 } -
code/trunk/src/libraries/core/command/Shell.h
r7284 r7401 27 27 */ 28 28 29 /** 30 @defgroup ShellConsole Shell and console 31 @ingroup Command 32 */ 33 34 /** 35 @file 36 @ingroup Command ShellConsole 37 @brief Declaration of the Shell and ShellListener classes. 38 */ 39 29 40 #ifndef _Shell_H__ 30 41 #define _Shell_H__ … … 43 54 namespace orxonox 44 55 { 56 /** 57 @brief An interface, used to get a notification if the state of the Shell changes. 58 */ 45 59 class _CoreExport ShellListener 46 60 { … … 51 65 52 66 private: 53 virtual void linesChanged() {} 54 virtual void onlyLastLineChanged() {} 55 virtual void lineAdded() {} 56 virtual void inputChanged() {} 57 virtual void cursorChanged() {} 58 virtual void executed() {} 59 virtual void exit() {} 67 virtual void linesChanged() {} ///< Called if all output-lines have changed 68 virtual void onlyLastLineChanged() {} ///< Called if only the last output-line has changed 69 virtual void lineAdded() {} ///< Called if a new line was added to the output 70 virtual void inputChanged() {} ///< Called if the input has changed 71 virtual void cursorChanged() {} ///< Called if the cursor in the input line has changed 72 virtual void executed() {} ///< Called if a command from the input line was executed 73 virtual void exit() {} ///< Called if the console should be closed 60 74 }; 61 75 62 76 77 /** 78 @brief The Shell is the logical component of the console that displays output to the user and allows him to enter commands. 79 80 The Shell gathers output sent from OutputHandler by inheriting from OutputListener. 81 The output-lines are stored in the shell, so they can be displayed in a graphical 82 console. Additionally the Shell has an InputBuffer which is needed by the user to 83 enter commands. 84 85 Different graphical consoles build upon a Shell, for example InGameConsole and IOConsole. 86 */ 63 87 class _CoreExport Shell : virtual public OrxonoxClass, public OutputListener 64 88 { 65 89 public: 90 /// Defines the type of a line of text in the Shell - some types depend on the output level, others are of internal use. 66 91 enum LineType 67 92 { … … 88 113 void unregisterListener(ShellListener* listener); 89 114 115 /// Returns the input buffer which is needed by the user to enter text into the shell. 90 116 inline InputBuffer* getInputBuffer() 91 117 { return this->inputBuffer_; } 92 118 93 119 void setCursorPosition(unsigned int cursor); 120 /// Returns the current position of the cursor in the input buffer. 94 121 inline unsigned int getCursorPosition() const 95 122 { return this->inputBuffer_->getCursorPosition(); } 96 123 124 /// Returns the current content of the input buffer (the text which was entered by the user) 97 125 inline const std::string& getInput() const 98 126 { return this->inputBuffer_->get(); } … … 105 133 void clearOutput(); 106 134 135 /// Returns the number of output-lines that are displayed in the shell. 107 136 inline unsigned int getNumLines() const 108 137 { return this->outputLines_.size(); } 138 /// Returns the line which is currently viewed if the user scrolls through the older output-lines in the shell. 109 139 inline unsigned int getScrollPosition() const 110 140 { return this->scrollPosition_; } 111 141 112 inline const std::string& getPromptPrefix() const { return this->promptPrefix_; } 113 void setPromptPrefix(const std::string& str); 114 142 /// Returns the cache size that is actually used in CommandExecutor, but placed here for better readability of the config file. 115 143 static inline unsigned int getCacheSize() 116 144 { return Shell::cacheSize_s; } … … 145 173 void exit(); 146 174 175 /// Iterates through all registered @ref ShellListener "shell listeners" and calls the function @a F. 147 176 template <void (ShellListener::*F)()> 148 177 void updateListeners() … … 152 181 } 153 182 154 std::list<ShellListener*> listeners_; 155 InputBuffer* inputBuffer_; 156 std::stringstream outputBuffer_; 157 bool bFinishedLastLine_; 158 LineList outputLines_; 159 LineList::const_iterator scrollIterator_; 160 unsigned int scrollPosition_; 161 unsigned int historyPosition_; 162 163 std::string promptPrefix_; 164 const std::string consoleName_; 165 const bool bScrollable_; 183 std::list<ShellListener*> listeners_; ///< The registered shell listeners 184 InputBuffer* inputBuffer_; ///< The input buffer that is needed by the user to enter text 185 std::stringstream outputBuffer_; ///< The output buffer that is used to retrieve lines of output from OutputListener 186 bool bFinishedLastLine_; ///< Stores if the most recent output-line was terminated with a line-break or if more output is expected for this line 187 LineList outputLines_; ///< A list of all output-lines that were displayed in the shell so far 188 LineList::const_iterator scrollIterator_; ///< An iterator to an entry of the list of output-lines, changes if the user scrolls through the output in the shell 189 unsigned int scrollPosition_; ///< The number of the line that is currently being referenced by scrollIterator_ 190 unsigned int historyPosition_; ///< If the user scrolls through the history of entered commands (stored in commandHistory_), this contains the currently viewed history entry 191 192 const std::string consoleName_; ///< The name of this shell - used to define the name of the soft-debug-level config-value 193 const bool bScrollable_; ///< If true, the user can scroll through the output-lines 166 194 167 195 // Config values 168 unsigned int maxHistoryLength_; 169 unsigned int historyOffset_; 170 std::vector<std::string> commandHistory_; 171 int softDebugLevel_; 172 static unsigned int cacheSize_s; 196 unsigned int maxHistoryLength_; ///< The maximum number of saved commands 197 unsigned int historyOffset_; ///< The command history is a circular buffer, this variable defines the current write-offset 198 std::vector<std::string> commandHistory_; ///< The history of commands that were entered by the user 199 int softDebugLevel_; ///< The maximum level of output that is displayed in the shell (will be passed to OutputListener to filter output) 200 static unsigned int cacheSize_s; ///< The maximum cache size of the CommandExecutor - this is stored here for better readability of the config file and because CommandExecutor is no OrxonoxClass 173 201 }; 174 202 } -
code/trunk/src/libraries/core/command/TclBind.cc
r7284 r7401 49 49 TclBind* TclBind::singletonPtr_s = 0; 50 50 51 /** 52 @brief Constructor: Initializes the Tcl-interpreter with a given data path. 53 @param datapath Path to the directory that contains the Orxonox-specific Tcl-files 54 */ 51 55 TclBind::TclBind(const std::string& datapath) 52 56 { … … 56 60 } 57 61 62 /** 63 @brief Destructor: Deletes the Tcl-interpreter. 64 */ 58 65 TclBind::~TclBind() 59 66 { … … 62 69 } 63 70 71 /** 72 @brief Defines the path to the directory that contains the Orxonox-specific Tcl-files and initializes the Tcl-interpreter accordingly. 73 */ 64 74 void TclBind::setDataPath(const std::string& datapath) 65 75 { … … 71 81 } 72 82 83 /** 84 @brief Creates and initializes the Tcl-interpreter by registering all callbacks and defining some useful functions. 85 */ 73 86 void TclBind::initializeTclInterpreter() 74 87 { … … 96 109 } 97 110 111 /** 112 @brief Creates and initializes a new Tcl-interpreter and calls the Orxonox-specific 113 init.tcl script that defines some special functions which are required by Orxonox. 114 */ 98 115 Tcl::interpreter* TclBind::createTclInterpreter() 99 116 { … … 116 133 } 117 134 135 /** 136 @brief Returns the path to the Tcl-library (not the Orxonox-specific Tcl-files). 137 */ 118 138 std::string TclBind::getTclLibraryPath() 119 139 { … … 128 148 } 129 149 150 /** 151 @brief Callback: Used to send an Orxonox-command from Tcl to the CommandExecutor and to send its result back to Tcl. 152 */ 130 153 std::string TclBind::tcl_query(Tcl::object const &args) 131 154 { … … 151 174 } 152 175 176 /** 177 @brief Callback: Used to send an Orxonox-command from Tcl to the CommandExecutor. 178 */ 153 179 void TclBind::tcl_execute(Tcl::object const &args) 154 180 { … … 162 188 } 163 189 190 /** 191 @brief Console command, executes Tcl code. Can be used to bind Tcl-commands to a key, because native 192 Tcl-commands can not be evaluated and are thus not supported by the key-binder. 193 */ 164 194 std::string TclBind::tcl(const std::string& tclcode) 165 195 { … … 182 212 } 183 213 214 /** 215 @brief Console command and implementation of the Tcl-feature "bgerror" which is called if an error 216 occurred in the background of a Tcl-script. 217 */ 184 218 void TclBind::bgerror(const std::string& error) 185 219 { … … 187 221 } 188 222 223 /** 224 @brief Executes Tcl-code and returns the return-value. 225 @param tclcode A string that contains Tcl-code 226 @param error A pointer to an integer (or NULL) that is used to write an error-code (see @ref CommandExecutorErrorCodes "CommandExecutor error codes") 227 @return Returns the return-value of the executed code (or an empty string if there's no return-value) 228 */ 189 229 std::string TclBind::eval(const std::string& tclcode, int* error) 190 230 { … … 194 234 try 195 235 { 236 // execute the code 196 237 return TclBind::getInstance().interpreter_->eval(tclcode); 197 238 } -
code/trunk/src/libraries/core/command/TclBind.h
r7284 r7401 27 27 */ 28 28 29 /** 30 @defgroup Tcl Tcl 31 @ingroup Command 32 */ 33 34 /** 35 @file 36 @ingroup Command Tcl 37 @brief Declaration of the TclBind class. 38 39 @anchor TclBindExample 40 41 orxonox::TclBind is a wrapper class for a Tcl interpreter. It is implemented as 42 singleton, so it can be accessed by everyone, but all share the same static 43 Tcl interpreter. If you need a Tcl interpreter at your own, see orxonox::TclThreadManager 44 for more information. 45 46 orxonox::TclBind is used by orxonox::CommandExecutor to execute Tcl commands. It can 47 also be used to execute Tcl commands from different sources, but note that they may 48 interfer with the ingame console if used improperly. By no means execute blocking 49 commands such as endless loops or the tcl command @c vwait. Use orxonox::TclThreadManager 50 and execute these commands in a multithreaded Tcl interpreter instead. 51 52 TclBind also defines different callback functions to return commands from the 53 Tcl interpreter back to Orxonox. Because of that it's possible to send a mixture 54 of Orxonox- and Tcl-commands to TclBind::eval() and still get the desired behavior. 55 56 Example: 57 @code 58 TclBind::eval("puts \"Hello World\""); // calls the tcl command "puts", prints "Hello World" to the console 59 TclBind::eval("log Hello World"); // calls the orxonox command "log", prints "Hello World" to the console 60 61 TclBind::eval("log [expr 1+1]"); // prints "2" to the console (which is the result of the tcl command "expr") 62 63 TclBind::eval("puts -nonewline Hello; log World"); // prints "HelloWorld" to the console 64 65 TclBind::eval("for {set i 0} {$i < 10} {incr i} {log test: $i}"); // prints "test: 0", ..., "test: 9" to the console 66 @endcode 67 68 Note that @c puts and @c log behave slightly different, even though both can print 69 text to the console. @c puts needs quotation marks around multi-word output, while 70 @c log doesn't. @c puts on the other hand supports the flag @c -nonewline. 71 72 TclBind::eval() can also be used to obtain the return-value of a Tcl command: 73 @code 74 std::string result = TclBind::eval("expr 1+1"); // result == "2" 75 @endcode 76 */ 77 29 78 #ifndef _TclBind_H__ 30 79 #define _TclBind_H__ … … 38 87 namespace orxonox 39 88 { 89 /** 90 @brief A wrapper class for a Tcl interpreter. Used to execute Tcl commands. 91 92 TclBind is used to execute Tcl commands, for example if sent to CommandExecutor::execute(). 93 It also defines different callbacks for Tcl, which allows to combine Orxonox-console-commands 94 and Tcl-function without problems. 95 96 @see See @ref TclBindExample "TclBind.h" for more information and an example. 97 */ 40 98 class _CoreExport TclBind : public Singleton<TclBind> 41 99 { … … 49 107 50 108 void setDataPath(const std::string& datapath); 51 const std::string& getTclDataPath() const { return this->tclDataPath_; }52 109 static std::string getTclLibraryPath(); 110 /// Returns the path to the Orxonox-specific Tcl-files. 111 inline const std::string& getTclDataPath() const 112 { return this->tclDataPath_; } 53 113 54 114 void initializeTclInterpreter(); 55 115 static Tcl::interpreter* createTclInterpreter(); 56 Tcl::interpreter* getTclInterpreter() const { return this->interpreter_; } 116 /// Returns the Tcl-interpreter 117 inline Tcl::interpreter* getTclInterpreter() const 118 { return this->interpreter_; } 57 119 58 120 static std::string tcl_query(Tcl::object const &args); … … 62 124 63 125 private: 64 TclBind(const TclBind& other); 126 TclBind(const TclBind& other); ///< Copy-constructor, not implemented 65 127 66 Tcl::interpreter* interpreter_; 67 std::string tclDataPath_; 68 bool bSetTclDataPath_; 128 Tcl::interpreter* interpreter_; ///< The wrapped Tcl interpreter 129 std::string tclDataPath_; ///< The path to the directory that contains the Orxonox-specific Tcl-files 130 bool bSetTclDataPath_; ///< True if tclDataPath_ was defined (after a call to setDataPath()) 69 131 70 static TclBind* singletonPtr_s; 132 static TclBind* singletonPtr_s; ///< The singleton pointer 71 133 }; 72 134 } -
code/trunk/src/libraries/core/command/TclThreadList.h
r7284 r7401 27 27 */ 28 28 29 /** 30 @file 31 @ingroup Command Tcl 32 @brief Definition of TclThreadList. 33 */ 34 29 35 #ifndef _TclThreadList_H__ 30 36 #define _TclThreadList_H__ … … 40 46 namespace orxonox 41 47 { 48 /** 49 @brief A thread-safe implementation of a message queue, used by TclThreadManager. 50 */ 42 51 template <class T> 43 52 class TclThreadList … … 71 80 72 81 /** 73 @brief Returns a reference to the mutex which might be useful if you want to iterate through the list (see @ref begin and @ref end).82 @brief Returns a reference to the mutex which might be useful if you want to iterate through the list (see @ref getList()). 74 83 */ 75 84 inline boost::shared_mutex& getMutex() const -
code/trunk/src/libraries/core/command/TclThreadManager.cc
r7284 r7401 26 26 * 27 27 */ 28 29 /** 30 @file 31 @brief Implementation of TclThreadManager. 32 */ 28 33 29 34 #include "TclThreadManager.h" … … 251 256 void TclThreadManager::initialize(TclInterpreterBundle* bundle) 252 257 { 253 const std::string& id_string = getConvertedValue<unsigned int,std::string>(bundle->id_);258 const std::string& id_string = multi_cast<std::string>(bundle->id_); 254 259 255 260 // Initialize the new interpreter … … 303 308 /** 304 309 @brief Sends a command to the queue of a given Tcl-interpreter 305 @param id The id of the target interpreter310 @param target_id The id of the target interpreter 306 311 @param command The command to be sent 307 312 */ … … 326 331 @brief This function can be called from Tcl to send a command to the queue of any interpreter. 327 332 @param target_id The id of the target thread 333 @param args Contains the content of the command 328 334 */ 329 335 void TclThreadManager::tcl_crossexecute(int target_id, const Tcl::object& args) … … 334 340 /** 335 341 @brief Sends a command to the queue of a given Tcl-interpreter 336 @param id The id of the target interpreter342 @param target_id The id of the target interpreter 337 343 @param command The command to be sent 338 344 */ … … 347 353 /** 348 354 @brief Sends a query to a given Tcl-interpreter and waits for the result 349 @param id The id of the target interpreter355 @param target_id The id of the target interpreter 350 356 @param command The command to be sent 351 357 @return The result of the command … … 359 365 @brief This function can be called from Tcl to send a query to the main thread. 360 366 @param source_id The id of the calling thread 367 @param args Contains the content of the query 361 368 362 369 A query waits for the result of the command. This means, the calling thread will be blocked until … … 373 380 @param source_id The id of the calling thread 374 381 @param target_id The id of the target thread 382 @param args Contains the content of the query 375 383 */ 376 384 std::string TclThreadManager::tcl_crossquery(int source_id, int target_id, const Tcl::object& args) … … 384 392 @param target_id The id of the target thread 385 393 @param command The command to send as a query 386 @param bUseCommandExecutor Only used if the target_id is 0 (which references the main interpreter). In this case it means if the command should be passed to the CommandExecutor (true) or to the main Tcl interpreter (false). This is true when called by tcl_query and false when called by tcl_crossquery.394 @param bUseCommandExecutor Only used if the target_id is 0 (which references the main interpreter). In this case it means if the command should be passed to the CommandExecutor (true) or to the main Tcl interpreter (false). This is true when called by tcl_query() and false when called by tcl_crossquery(). 387 395 */ 388 396 std::string TclThreadManager::_query(unsigned int source_id, unsigned int target_id, const std::string& command, bool bUseCommandExecutor) … … 400 408 { 401 409 // This query would lead to a deadlock - return with an error 402 TclThreadManager::error("Error: Circular query (" + this->dumpList(source_bundle->queriers_.getList()) + ' ' + getConvertedValue<unsigned int,std::string>(source_bundle->id_) \403 + " -> " + getConvertedValue<unsigned int,std::string>(target_bundle->id_) \404 + "), couldn't query Tcl-interpreter with ID " + getConvertedValue<unsigned int,std::string>(target_bundle->id_) \405 + " from other interpreter with ID " + getConvertedValue<unsigned int,std::string>(source_bundle->id_) + '.');410 TclThreadManager::error("Error: Circular query (" + this->dumpList(source_bundle->queriers_.getList()) + ' ' + multi_cast<std::string>(source_bundle->id_) \ 411 + " -> " + multi_cast<std::string>(target_bundle->id_) \ 412 + "), couldn't query Tcl-interpreter with ID " + multi_cast<std::string>(target_bundle->id_) \ 413 + " from other interpreter with ID " + multi_cast<std::string>(source_bundle->id_) + '.'); 406 414 } 407 415 else … … 469 477 // This happens if the main thread tries to query a busy interpreter 470 478 // To avoid a lock of the main thread, we simply don't proceed with the query in this case 471 TclThreadManager::error("Error: Couldn't query Tcl-interpreter with ID " + getConvertedValue<unsigned int,std::string>(target_bundle->id_) + ", interpreter is busy right now.");479 TclThreadManager::error("Error: Couldn't query Tcl-interpreter with ID " + multi_cast<std::string>(target_bundle->id_) + ", interpreter is busy right now."); 472 480 } 473 481 } … … 515 523 else 516 524 { 517 TclThreadManager::error("Error: No Tcl-interpreter with ID " + getConvertedValue<unsigned int,std::string>(id) + " existing.");525 TclThreadManager::error("Error: No Tcl-interpreter with ID " + multi_cast<std::string>(id) + " existing."); 518 526 return 0; 519 527 } … … 531 539 output += ' '; 532 540 533 output += getConvertedValue<unsigned int,std::string>(*it);541 output += multi_cast<std::string>(*it); 534 542 } 535 543 return output; … … 583 591 if (cc != TCL_OK) 584 592 { 585 TclThreadManager::error("Tcl error (" + action + ", ID " + getConvertedValue<unsigned int,std::string>(bundle->id_) + "): " + static_cast<std::string>(result));593 TclThreadManager::error("Tcl error (" + action + ", ID " + multi_cast<std::string>(bundle->id_) + "): " + static_cast<std::string>(result)); 586 594 return ""; 587 595 } -
code/trunk/src/libraries/core/command/TclThreadManager.h
r7284 r7401 26 26 * 27 27 */ 28 29 /** 30 @file 31 @ingroup Command Tcl 32 @brief Declaration of TclThreadManager, used to create multithreaded Tcl interpreters. 33 */ 28 34 29 35 #ifndef _TclThreadManager_H__ -
code/trunk/src/libraries/core/input/Button.cc
r7284 r7401 176 176 // evaluate the command 177 177 CommandEvaluation eval = CommandExecutor::evaluate(commandStr); 178 if (!eval.isValid() || eval.evaluate Params(true))178 if (!eval.isValid() || eval.evaluateArguments(true)) 179 179 { 180 180 parseError("Command evaluation of \"" + commandStr + "\"failed.", true); -
code/trunk/src/libraries/core/input/InputCommands.cc
r5781 r7401 53 53 if (this->abs_ != 0.0f || this->rel_ != 0.0f) 54 54 { 55 evaluation_.setEvaluated Parameter(paramIndex_, Vector2(abs_, rel_));55 evaluation_.setEvaluatedArgument(paramIndex_, Vector2(abs_, rel_)); 56 56 // reset 57 57 rel_ = 0.0; -
code/trunk/src/libraries/core/input/InputManager.cc
r7284 r7401 140 140 Creates the OIS::InputMananger, the keyboard, the mouse and 141 141 the joys ticks. If either of the first two fail, this method throws an exception. 142 @param windowWidth143 The width of the render window144 @param windowHeight145 The height of the render window146 142 */ 147 143 void InputManager::loadDevices() -
code/trunk/src/libraries/core/input/InputManager.h
r6746 r7401 122 122 @param name 123 123 Unique name of the InputState when referenced as string 124 @param bAlwaysGetsInput 125 InputState always gets the input when activated 126 @param bTransparent 127 InputState will not prevent underlaying state from receiving input 124 128 @param priority 125 129 Priority matters when multiple states are active. You can specify any -
code/trunk/src/libraries/core/input/InputState.h
r7284 r7401 128 128 void resetExpiration() { bExpired_ = false; } 129 129 130 //! Updates one specific device handler with #device#Updated130 //! Updates one specific device handler with deviceUpdated 131 131 void update(float dt, unsigned int device); 132 132 //! Updates all handlers with allDevicesUpdated -
code/trunk/src/libraries/core/input/KeyBinder.cc
r6536 r7401 495 495 @brief 496 496 Event handler for the mouseMoved Event. 497 @param e 498 Mouse state information 497 @param abs_ 498 The absolute position of the mouse 499 @param rel_ 500 The relative movement of the mouse 501 @param clippingSize 502 Mouse screen area in pixels (usually 1024x1024) 499 503 */ 500 504 void KeyBinder::mouseMoved(IntVector2 abs_, IntVector2 rel_, IntVector2 clippingSize) … … 551 555 /** 552 556 @brief Event handler for the mouseScrolled Event. 553 @param e Mouse state information 557 @param abs The absolute position of the scroll wheel 558 @param rel The relative movement of the scroll wheel 554 559 */ 555 560 void KeyBinder::mouseScrolled(int abs, int rel) -
code/trunk/src/libraries/network/ClientInformation.cc
r6417 r7401 230 230 * This function should only be applied to the head of the list 231 231 * @param clientID id to look for 232 * @param look_backwards FIXME - add doc? parameter unused? 232 233 * @return pointer to the last element in the list or 0 if the search was unsuccessfull 233 234 */ … … 244 245 * This function goes forward through the list and looks for an element with clientID 245 246 * This function should only be applied to the head of the list 246 * @param peer peer to look for 247 * @param address peer to look for 248 * @param look_backwards FIXME - add doc? parameter unused? 247 249 * @return pointer to the element in the list 248 250 */ -
code/trunk/src/libraries/network/GamestateClient.cc
r7163 r7401 105 105 * @return iterator pointing to the next object in the list 106 106 */ 107 void GamestateClient::removeObject(ObjectList <Synchronisable>::iterator&it) {108 ObjectList <Synchronisable>::iteratortemp=it;107 void GamestateClient::removeObject(ObjectListIterator<Synchronisable> &it) { 108 ObjectListIterator<Synchronisable> temp=it; 109 109 ++it; 110 110 temp->destroy(); // or delete? -
code/trunk/src/libraries/network/synchronisable/Synchronisable.cc
r7183 r7401 217 217 * length of varx: size saved int syncvarlist 218 218 * @param mem pointer to allocated memory with enough size 219 * @param sizes FIXME - add doc! 219 220 * @param id gamestateid of the gamestate to be saved (important for priorities) 220 221 * @param mode defines the direction in which the data will be send/received … … 288 289 * @param mem pointer to the bytestream 289 290 * @param mode same as in getData 291 * @param forceCallback FIXME - add doc! 290 292 * @return true/false 291 293 */ … … 364 366 * This function determines, wheter the object should be saved to the bytestream (according to its syncmode/direction) 365 367 * @param id gamestate id 368 * @param mode FIXME - add doc! 366 369 * @return true/false 367 370 */ -
code/trunk/src/libraries/tools/ResourceCollection.cc
r5781 r7401 52 52 } 53 53 54 void ResourceCollection::XMLPort(Element& xml Element, XMLPort::Mode mode)54 void ResourceCollection::XMLPort(Element& xmlelement, XMLPort::Mode mode) 55 55 { 56 XMLPortParam(ResourceCollection, "resourceGroup", setResourceGroup, getResourceGroup, xml Element, mode);57 XMLPortObject(ResourceCollection, ResourceLocation, "", addResourceLocation, getResourceLocation, xml Element, mode);56 XMLPortParam(ResourceCollection, "resourceGroup", setResourceGroup, getResourceGroup, xmlelement, mode); 57 XMLPortObject(ResourceCollection, ResourceLocation, "", addResourceLocation, getResourceLocation, xmlelement, mode); 58 58 } 59 59 -
code/trunk/src/libraries/tools/ResourceCollection.h
r6105 r7401 44 44 virtual ~ResourceCollection(); 45 45 46 virtual void XMLPort(Element& xml Element, XMLPort::Mode mode);46 virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode); 47 47 48 48 void setResourceGroup(const std::string& resourceGroup); -
code/trunk/src/libraries/tools/ResourceLocation.cc
r7174 r7401 56 56 } 57 57 58 void ResourceLocation::XMLPort(Element& xml Element, XMLPort::Mode mode)58 void ResourceLocation::XMLPort(Element& xmlelement, XMLPort::Mode mode) 59 59 { 60 XMLPortParam(ResourceLocation, "path", setPath, getPath, xml Element, mode);61 XMLPortParam(ResourceLocation, "archiveType", setArchiveType, getArchiveType, xml Element, mode);62 XMLPortParam(ResourceLocation, "recursive", setRecursive, getRecursive, xml Element, mode);60 XMLPortParam(ResourceLocation, "path", setPath, getPath, xmlelement, mode); 61 XMLPortParam(ResourceLocation, "archiveType", setArchiveType, getArchiveType, xmlelement, mode); 62 XMLPortParam(ResourceLocation, "recursive", setRecursive, getRecursive, xmlelement, mode); 63 63 if (path_.empty()) 64 64 ThrowException(AbortLoading, "ResourceLocation: No path given."); -
code/trunk/src/libraries/tools/ResourceLocation.h
r5781 r7401 46 46 virtual ~ResourceLocation(); 47 47 48 virtual void XMLPort(Element& xml Element, XMLPort::Mode mode);48 virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode); 49 49 50 50 void setPath(const std::string& path) { path_ = path; } -
code/trunk/src/libraries/tools/Timer.cc
r7284 r7401 27 27 */ 28 28 29 /** 30 @file 31 @brief Implementation of the Timer class. 32 */ 33 29 34 #include "Timer.h" 30 35 … … 45 50 46 51 /** 47 @brief C alls a console command after 'delay'seconds.52 @brief Console-command: Calls another console command after @a delay seconds. 48 53 @param delay The delay in seconds 49 54 @param command The console command … … 60 65 61 66 /** 62 @brief Executes the command.63 @param timer The timer to destroy after the command-execution67 @brief Helper function for delay(), executes the command and destroys the timer. 68 @param timer The timer which called this function. 64 69 @param command The command to execute 65 70 */ … … 72 77 73 78 /** 74 @brief Kills all delayed commands.79 @brief Console-command: Kills all scheduled commands that were delayed using delay(). 75 80 */ 76 81 void killdelays() … … 92 97 93 98 /** 94 @brief Constructor: Initializes the Timer with given values. 95 @param interval The timer-interval in seconds 96 @param bLoop If true, the function gets called every 'interval' seconds 97 @param exeuctor A executor of the function to call 99 @brief Constructor: Initializes and starts the timer, which will call an executor after some time. 100 @param interval The timer-interval in seconds 101 @param bLoop If true, the executor gets called every @a interval seconds 102 @param executor The executor that will be called 103 @param bKillAfterCall If true, the timer will be deleted after the executor was called 98 104 */ 99 105 Timer::Timer(float interval, bool bLoop, const ExecutorPtr& executor, bool bKillAfterCall) … … 120 126 121 127 /** 122 @brief Executes the executor.128 @brief Calls the executor and destroys the timer if requested. 123 129 */ 124 130 void Timer::run() -
code/trunk/src/libraries/tools/Timer.h
r7284 r7401 27 27 */ 28 28 29 /*! 29 /** 30 @defgroup Timer Timer 31 @ingroup Tools 32 */ 33 34 /** 30 35 @file 31 @brief Definition and Implementation of the Timer class. 36 @ingroup Timer 37 @brief Declaration of the Timer class, used to call functions after a given time-interval. 32 38 33 The Timer is a callback-object, calling a given function after a given time-interval.39 @anchor TimerExample 34 40 35 Usage: 41 Timer is a helper class that executes a function after a given amount of time. 42 43 Usage: <br> 36 44 header.h: 37 class ClassName 38 { 39 public: 40 ClassName(); 41 void functionName(); 42 Timer myTimer; 43 }; 45 @code 46 class MyClass 47 { 48 public: 49 MyClass(); 50 void functionName(); 51 52 private: 53 Timer myTimer; 54 }; 55 @endcode 44 56 45 57 source.cc: 46 #include "core/command/Executor.h" 58 @code 59 #include "core/command/Executor.h" 47 60 48 ClassName::ClassName()49 50 myTimer.setTimer(interval_in_seconds, bLoop, createExecutor(createFunctor(&ClassName::functionName, this)));51 61 MyClass::MyClass() 62 { 63 myTimer.setTimer(3, false, createExecutor(createFunctor(&ClassName::myFunction, this))); 64 } 52 65 53 void ClassName::functionName() 54 { 55 whateveryouwant(); 56 something(else); 57 } 66 void MyClass::myFunction() 67 { 68 COUT(0) << "Hello World" << std::endl; 69 } 70 @endcode 71 72 The code in this example prints "Hello World" to the console, 3 seconds after creating 73 an instance of MyClass. 58 74 */ 59 75 … … 73 89 void executeDelayedCommand(Timer* timer, const std::string& command); 74 90 75 //! The Timer is a callback-object, calling a given function after a given time-interval. 91 /** 92 @brief Timer is a helper class that executes a function after a given amount of time. 93 94 @see See @ref TimerExample "Timer.h" for an example. 95 */ 76 96 class _ToolsExport Timer : public TimeFactorListener 77 97 { … … 82 102 83 103 /** 84 @brief Initializes the Timer with given values.85 @param interval The timer-interval in seconds86 @param bLoop If true, the function gets called every 'interval'seconds87 @param object The object owning the timer and the function88 @param executor A executor of the function to call104 @brief Initializes and starts the timer, which will call an executor after some time. 105 @param interval The timer-interval in seconds 106 @param bLoop If true, the executor gets called every @a interval seconds 107 @param executor The executor that will be called 108 @param bKillAfterCall If true, the timer will be deleted after the executor was called 89 109 */ 90 110 void setTimer(float interval, bool bLoop, const ExecutorPtr& executor, bool bKillAfterCall = false) … … 101 121 void run(); 102 122 103 / ** @brief Starts the Timer: Function-call after 'interval' seconds. */123 /// Re-starts the Timer: The executor will be called after @a interval seconds. 104 124 inline void startTimer() 105 125 { this->bActive_ = true; this->time_ = this->interval_; } 106 / ** @brief Stops the Timer. */126 /// Stops the Timer. 107 127 inline void stopTimer() 108 128 { this->bActive_ = false; this->time_ = this->interval_; } 109 / ** @brief Pauses the Timer - it will continue with the actual state if you unpause it. */129 /// Pauses the Timer - it will continue with the actual state if you call unpauseTimer(). 110 130 inline void pauseTimer() 111 131 { this->bActive_ = false; } 112 / ** @brief Unpauses the Timer - continues with the given state. */132 /// Unpauses the Timer - continues with the given state. 113 133 inline void unpauseTimer() 114 134 { this->bActive_ = true; } 115 / ** @brief Returns true if the Timer is active (= not stoped, not paused). @return True = Time is active */135 /// Returns true if the Timer is active (neither stoped nor paused). 116 136 inline bool isActive() const 117 137 { return this->bActive_; } 118 / ** @brief Returns the remaining time until the Timer calls the function. @return The remaining time */138 /// Returns the remaining time until the Timer calls the executor. 119 139 inline float getRemainingTime() const 120 140 { return static_cast<float>(this->time_ / 1000000.0f); } 121 / ** @brief Gives the Timer some extra time. @param time The amount of extra time in seconds */141 /// Increases the remaining time of the Timer by the given amount of time (in seconds). 122 142 inline void addTime(float time) 123 143 { if (time > 0.0f) this->time_ += static_cast<long long>(time * 1000000.0f); } 124 / ** @brief Decreases the remaining time of the Timer. @param time The amount of time to remove */144 /// Decreases the remaining time of the Timer by the given amount of time (in seconds) 125 145 inline void removeTime(float time) 126 146 { if (time > 0.0f) this->time_ -= static_cast<long long>(time * 1000000.0f); } 127 / ** @brief Sets the interval of the Timer. @param interval The interval */147 /// Changes the calling interval. 128 148 inline void setInterval(float interval) 129 149 { this->interval_ = static_cast<long long>(interval * 1000000.0f); } 130 / ** @brief Sets bLoop to a given value. @param bLoop True = loop */150 /// Defines if the timer call the executor every @a interval seconds or only once. 131 151 inline void setLoop(bool bLoop) 132 152 { this->bLoop_ = bLoop; } … … 137 157 void init(); 138 158 139 ExecutorPtr executor_; //!< The executor of the function that shouldbe called when the time expires159 ExecutorPtr executor_; //!< The executor of the function that will be called when the time expires 140 160 141 161 long long interval_; //!< The time-interval in micro seconds 142 bool bLoop_; //!< If true, the function gets called every 'interval'seconds143 bool bActive_; //!< If true, the Timer ticks and calls the functionif the time's up144 bool bKillAfterCall_; //!< If true the timer gets deleted after it called the function162 bool bLoop_; //!< If true, the executor gets called every @a interval seconds 163 bool bActive_; //!< If true, the Timer ticks and calls the executor if the time's up 164 bool bKillAfterCall_; //!< If true the timer gets deleted after it expired and called the executor 145 165 146 long long time_; //!< Internal variable, counting the time till the next function-call166 long long time_; //!< Internal variable, counting the time untill the next executor-call 147 167 }; 148 168 } -
code/trunk/src/libraries/util/Clipboard.cc
r6417 r7401 54 54 55 55 /** 56 @brief Puts text into the windows-clipboard 57 @param text The text 56 @brief Puts text into the Windows-clipboard 58 57 @return True if the action was successful 59 58 */ … … 119 118 namespace orxonox 120 119 { 121 static std::string clipboard; // !< Keeps the text of our internal clipboard120 static std::string clipboard; ///< Keeps the text of our internal clipboard 122 121 123 122 /** 124 123 @brief Default implementation if there is no OS-specific implementation or no clipboard. Copies the text into an internal clipboard. 125 @param text The text 126 @return True 124 @see fromClipboard() 127 125 */ 128 126 bool toClipboard(const std::string& text) … … 134 132 /** 135 133 @brief Default implementation if there is no OS-specific implementation or no clipboard. Gets the text from the internal clipboard. 136 @ return The text134 @see toClipboard() 137 135 */ 138 136 std::string fromClipboard() -
code/trunk/src/libraries/util/Clipboard.h
r5781 r7401 29 29 /** 30 30 @file 31 @brief Some functions to exchange text between the OS clipboard and Orxonox. 31 @ingroup Util Command 32 @brief Some functions to exchange text between the OS clipboard and the Shell in Orxonox. 32 33 33 34 Use fromClipboard() to get text from the clipboard (if there is any text) and 34 toClipboard( text) to put text into the clipboard.35 toClipboard() to put text into the clipboard. 35 36 36 Th ose functions can only work properly if there's an OS-specific implementation.37 If an OS isn't supported, the clipboard only works within Orxonox, but exchange38 with other programs isn't possible.37 These functions can only work properly if there's an OS-specific implementation 38 in Clipboard.cc. If a specific OS is not supported, the clipboard only works 39 within Orxonox, but the exchange with other programs is not possible. 39 40 */ 40 41 -
code/trunk/src/libraries/util/Clock.cc
r6417 r7401 45 45 } 46 46 47 /**48 @remarks49 Mind the types! Ogre::Timer::getMicroseconds() will return an unsigned50 long, which will eventually overflow. But if you use the subtraction of51 the current time minus the last time the timer gave us and sum these up to52 a 64 bit integer, we get the desired result.53 Also mind that we don't have to store the last timer's time as unsigned long54 as well because (unsigned long)tickTime_ will do exactly that.55 */56 47 void Clock::capture() 57 48 { -
code/trunk/src/libraries/util/Clock.h
r6417 r7401 27 27 */ 28 28 29 /** 30 @file 31 @ingroup Util 32 */ 33 29 34 #ifndef _Clock_H__ 30 35 #define _Clock_H__ … … 35 40 namespace orxonox 36 41 { 42 /** Simple real time clock based on Ogre::Timer 43 @details 44 The class can be used to both capture the current real time or to 45 incrementally capture the time and then distribute that time information 46 via Clock& references (for instance for the game tick). <br> 47 Precision: <br> 48 @par Precision 49 The maximum precision is given by the Ogre::Timer and that is somewhere 50 in the microsecond range for both Windows and UNIX. 51 @par Remarks for Usage on Windows 52 For proper functionality this class MUST be used in the same thread! <br> 53 Furthermore it might be possible that the Ogre::Timer has a performance 54 caveat because it will only capture the time on the same CPU core. 55 Confining the main thread to one process could speed up the game. 56 See \ref cmdargspage "Ccommandline Argument" 'limitToCPU' (only on Windows) 57 */ 37 58 class _UtilExport Clock 38 59 { 39 60 public: 61 /// Starts the time at 0 40 62 Clock(); 41 63 ~Clock(); 42 64 65 /** Internally captures the time and stays at that particular time 66 @remarks 67 Mind the types! Ogre::Timer::getMicroseconds() will return an unsigned 68 long, which will eventually overflow. But if you use the subtraction of 69 the current time minus the last time the timer gave us and sum these up to 70 a 64 bit integer, we get the desired result. <br> 71 Also mind that we don't have to store the last timer's time as unsigned long 72 as well because (unsigned long)tickTime_ will do exactly that. 73 */ 43 74 void capture(); 44 75 45 unsigned long long getMicroseconds() const { return tickTime_; } 46 unsigned long long getMilliseconds() const { return tickTime_ / 1000; } 47 unsigned long getSeconds() const { return static_cast<long> (tickTime_ / 1000000); } 48 float getSecondsPrecise() const { return static_cast<float>(tickTime_ / 1000000.0f); } 76 /// Returns the last captured absolute time in microseconds 77 unsigned long long getMicroseconds() const 78 { return tickTime_; } 79 /// Returns the last captured absolute time in milliseconds 80 unsigned long long getMilliseconds() const 81 { return tickTime_ / 1000; } 82 /// Returns the last captured absolute time in seconds 83 unsigned long getSeconds() const 84 { return static_cast<long> (tickTime_ / 1000000); } 85 /// Returns the last captured absolute time in seconds as float 86 float getSecondsPrecise() const 87 { return static_cast<float>(tickTime_ / 1000000.0f); } 49 88 50 float getDeltaTime() const { return tickDtFloat_; } 51 long getDeltaTimeMicroseconds() const { return tickDt_; } 89 /// Returns the timespan in seconds between the last two calls to capture() 90 float getDeltaTime() const 91 { return tickDtFloat_; } 92 /// Returns the timespan in microseconds between the last two calls to capture() 93 long getDeltaTimeMicroseconds() const 94 { return tickDt_; } 52 95 96 /** Returns the current real time in microseconds 97 @note 98 This is especially useful to measure execution times because of the 99 high precision. 100 */ 53 101 unsigned long long getRealMicroseconds() const; 54 102 55 103 private: 104 /// Undefined 56 105 Clock(const Clock& instance); 57 106 58 Ogre::Timer* timer_; 59 unsigned long long tickTime_; 60 long tickDt_; 61 float tickDtFloat_; 107 Ogre::Timer* timer_; ///< Ogre timer object 108 unsigned long long tickTime_; ///< Currently captured time 109 long tickDt_; ///< Delta time in microseconds (cache value) 110 float tickDtFloat_; ///< Delta time in seconds (cache value) 62 111 }; 63 112 } -
code/trunk/src/libraries/util/Convert.cc
r7163 r7401 32 32 namespace orxonox 33 33 { 34 //template <class FromType, class ToType>35 34 bool ConverterExplicit<std::string, bool>::convert(bool* output, const std::string& input) 36 35 { -
code/trunk/src/libraries/util/Convert.h
r7305 r7401 28 28 */ 29 29 30 /*! 31 @file 32 @brief Definition and Implementation of the Convert class. 30 /** 31 @defgroup Convert Conversion functions 32 @ingroup Util 33 */ 34 35 /** Functions that convert values between different types. 36 @file 37 @ingroup Convert 38 @par Usage 39 There are three ways to use the conversions depending on what you need. <br> 40 - For simply converting values without having to know whether the conversion 41 was successful (for instance float --> string), use orxonox::multi_cast 42 which effectively works exactly like static_cast, etc. 43 @code 44 float input = 42.0; 45 std::string output = multi_cast<std::string>(input); 46 @endcode 47 - If you care about whether the conversion was successful, 48 use orxonox::convertValue. 49 @code 50 std::string input("3.4"); 51 float output; 52 bool success = convertValue(&output, input); 53 @endcode 54 - If you care about success and if you can also feed a fallback value, 55 use orxonox::convertValue. 56 @code 57 std::string input("3.4"); 58 float output; 59 bool success = convertValue(&output, input, 0.0); 60 @endcode 61 - If success doesn't matter but you can feed a fallback value, 62 use orxonox::getConvertedValue. 63 @code 64 std::string input("3.4"); 65 float output = getConvertedValue(input, 0.0); 66 @endcode 67 @details 68 The back end of these functions are the actual implementations for the 69 specific conversions, for instance from Ogre::Vector3 to std::string and 70 vice versa. Some of them also use the iostream operators. <br> 71 The real deal is evaluating which function is needed for a conversion based 72 on the input and output type. But there are lots of catches in conjunction 73 with templates which explains why there are so many functions in this file. 74 <br> <br> 75 @par Search Order 76 Finding the right function is governed by priority rules: <br> 77 -# (Partial) template specialisation of orxonox::ConverterExplicit::convert() 78 -# An implicit conversion. This includes 'FooBar' to 'int' if FooBar 79 defines operator int() or float(). 80 -# Global or member operators for iostream when converting from or 81 to std::string (and FROM const char*) 82 -# (Partial) template specialisation of orxonox::ConverterFallback::convert() 83 -# Fallback function that displays "Could not convert value" with type 84 information obtained from typeid(). 85 @par Implementing conversion functions 86 To do that you probably need to know a thing or two about the types 87 involved. So, get ready with that. <br> 88 Usually the best way to do it is specialising of the orxonox::ConverterFallback 89 template, like this: 90 @code 91 template <> 92 struct _UtilExport ConverterFallback<std::string, MyType> 93 { 94 static bool convert(MyType* output, const std::string& input) 95 { 96 ... 97 return success; 98 } 99 }; 100 @endcode 101 This piece of code converts an std::string to MyType and returns whether the 102 conversion was successful. You can also use partial specialisation.<br> 103 The advantage with orxonox::ConverterFallback is that it has a low priority 104 meaning that when there is an implicit conversion or an iostream method, that 105 comes first and you don't have to deal with it (and the accompanying 106 function call ambiguity). <br> 107 However sometimes you would like to explicitely replace such a conversion. 108 That's where orxonox::ConverterExplicit comes in handy (for instance we 109 replaced the operator << conversions for Ogre::VectorX with our own functions). 110 @note 111 There has to be an exact type match when using template specialisations. <br> 112 Template specialisations can be defined after including this file. 113 But any implicit cast function or iostream operator has to be included 114 in this file! 115 @par Understanding the Code 116 In order to understand how the templates work, it is probably best to study 117 the functions in order of calling. There are lots of comments explaining 118 what happens, but you'll need to understand a deal about partial template 119 specialisation and function headers are matched in C++. 33 120 */ 34 121 … … 46 133 #include "ImplicitConversion.h" 47 134 48 ////////////////////////////////////49 //// ACTUAL CONVERSION SEQUENCE ////50 ////////////////////////////////////51 /*52 There is a distinct priority when choosing the right conversion function:53 Overwrite:54 1. (Partial) template specialisation of ConverterExplicit::convert()55 Fallbacks:56 2. Any possible implicit conversion. This includes 'FooBar' --> 'int' if FooBar defines operator float().57 3. Global or member operators for stringstream when converting from or to std::string (or FROM const char*)58 4. (Partial) template specialisation of ConverterFallback::convert()59 5. Function that simply displays "Could not convert value" with type information obtained from typeid().60 61 Notes:62 There has to be an exact type match when using template specialisations.63 Template specialisations can be defined after including this file. Any implicit cast function or iostream64 operator has to be declared BEFORE this file gets parsed.65 66 Defining your own functions:67 There are obviously 4 ways to specify a user defined conversion. What should you use?68 69 Usually, ConverterFallback fits quite well. You won't have to deal with the conversion from70 'MyClass' to 'MyClass' by using another explicit template specialisation to avoid ambiguities.71 72 However if you want to overwrite an implicit conversion or an iostream operator, you really need to73 make use of ConverterExplicit. We have to do this for the Ogre classes for instance because they74 define stream operators we don't particulary like.75 */76 77 135 namespace orxonox 78 136 { … … 81 139 /////////////////// 82 140 83 // Default template. No conversion available at all.141 /// Default template. No conversion available at all. 84 142 template <class FromType, class ToType> 85 143 struct ConverterFallback … … 93 151 }; 94 152 95 // If all else fails, try a dynamic_cast for pointer types.153 /// If all else fails, try a dynamic_cast for pointer types. 96 154 template <class FromType, class ToType> 97 155 struct ConverterFallback<FromType*, ToType*> … … 109 167 } 110 168 }; 111 112 ////////////113 // upcast //114 ////////////115 namespace detail116 {117 // perform a static cast if ToType is a base of FromType118 template<class ToType, class FromType>119 FORCEINLINE ToType upcast(FromType input, Loki::Int2Type<true>)120 {121 return static_cast<ToType>(input);122 }123 124 // return zero if ToType is not a base of FromType125 template<class ToType, class FromType>126 FORCEINLINE ToType upcast(FromType input, Loki::Int2Type<false>)127 {128 return 0;129 }130 }131 132 // performs an upcast if ToType is a base of FromType, returns zero otherwise133 template <class ToType, class FromType>134 FORCEINLINE ToType upcast(FromType input)135 {136 enum { probe = ImplicitConversion<FromType, ToType>::exists };137 return detail::upcast<ToType, FromType>(input, Loki::Int2Type<probe>());138 }139 169 } 140 170 … … 144 174 /////////////////////// 145 175 146 // Default template for stringstream 176 /** Fallback template for stringstream 177 @details 178 Neither FromType nor ToType was std::string, therefore 179 delegate to orxonox::ConverterFallback 180 */ 147 181 template <class FromType, class ToType> 148 182 struct ConverterStringStream … … 159 193 ///////////// 160 194 195 /// Extra namespace to avoid exposing the iostream operators in it 161 196 namespace fallbackTemplates 162 197 { 198 /// Fallback operator <<() (delegates to orxonox::ConverterFallback) 163 199 template <class FromType> 164 200 FORCEINLINE bool operator <<(std::ostream& outstream, const FromType& input) … … 175 211 } 176 212 177 // template that evaluates whether we can convert to std::string via ostringstream213 /// Template that evaluates whether we can convert to std::string via ostringstream 178 214 template <class FromType> 179 215 struct ConverterStringStream<FromType, std::string> … … 182 218 { 183 219 using namespace fallbackTemplates; 184 // this operator call only chooses fallbackTemplates::operator<< if there's no other fitting function 220 // this operator call only chooses fallbackTemplates::operator<<() 221 // if there's no other fitting function 185 222 std::ostringstream oss; 223 // Note: std::ostream has operator!() to tell whether any error flag was set 186 224 if (oss << input) 187 225 { … … 201 239 namespace fallbackTemplates 202 240 { 241 /// Fallback operator >>() (delegates to orxonox::ConverterFallback) 203 242 template <class ToType> 204 243 FORCEINLINE bool operator >>(std::istream& instream, ToType& output) 205 244 { 206 return orxonox::ConverterFallback<std::string, ToType>207 ::convert(&output, static_cast<std::istringstream&>(instream).str());245 std::string input(static_cast<std::istringstream&>(instream).str()); 246 return orxonox::ConverterFallback<std::string, ToType>::convert(&output, input); 208 247 } 209 248 } 210 249 211 // template that evaluates whether we can convert from std::string via ostringstream250 /// Template that evaluates whether we can convert from std::string via istringstream 212 251 template <class ToType> 213 252 struct ConverterStringStream<std::string, ToType> … … 216 255 { 217 256 using namespace fallbackTemplates; 257 // this operator call chooses fallbackTemplates::operator>>() 258 // only if there's no other fitting function 218 259 std::istringstream iss(input); 219 // this operator call only chooses fallbackTemplates::operator>> if there's no other fitting function260 // Note: std::istream has operator!() to tell whether any error flag was set 220 261 if (iss >> (*output)) 221 262 { … … 229 270 namespace orxonox 230 271 { 231 232 272 /////////////////// 233 273 // Implicit Cast // 234 274 /////////////////// 235 275 236 // implicit cast not possible, try stringstream conversion next276 /// %Template delegates to ::ConverterStringStream 237 277 template <class FromType, class ToType> 238 278 FORCEINLINE bool convertImplicitely(ToType* output, const FromType& input, Loki::Int2Type<false>) … … 241 281 } 242 282 243 // We can cast implicitely283 /// Makes an implicit cast from \a FromType to \a ToType 244 284 template <class FromType, class ToType> 245 285 FORCEINLINE bool convertImplicitely(ToType* output, const FromType& input, Loki::Int2Type<true>) … … 254 294 //////////////////////////////// 255 295 256 // Default template if no specialisation is available 296 /** Default template if no orxonox::ConverterExplicit is available 297 @details 298 Evaluates whether \a FromType can be implicitly converted to \a ToType 299 by the use the ImplicitConversion magic. 300 */ 257 301 template <class FromType, class ToType> 258 302 struct ConverterExplicit … … 261 305 FORCEINLINE static bool convert(ToType* output, const FromType& input) 262 306 { 263 // Try implict cast and probe first. If a simple cast is not possible, it will not compile 264 // We therefore have to out source it into another template function 307 // Use the probe's value to delegate to the right function 265 308 return convertImplicitely(output, input, Loki::Int2Type<probe>()); 266 309 } … … 275 318 @brief 276 319 Converts any value to any other as long as there exists a conversion. 320 @details 277 321 Otherwise, the conversion will generate a runtime warning and return false. 278 For information about the different conversion methods (user defined too), see the section 279 'Actual conversion sequence' in this file above. 322 @see Convert.h 323 @param output 324 A pointer to the variable where the converted value will be stored 325 @param input 326 The original value 280 327 */ 281 328 template <class FromType, class ToType> … … 291 338 Converts any value to any other as long as there exists a conversion. 292 339 Otherwise, the conversion will generate a runtime warning and return false. 293 For information about the different conversion methods (user defined too), see the section 294 'Actual conversion sequence' in this file above. 295 If the conversion doesn't succeed, 'fallback' is written to '*output'. 340 If the conversion doesn't succeed, \a fallback is written to \a output. 341 @see Convert.h 342 @param output 343 A pointer to the variable where the converted value will be stored 344 @param input 345 The original value 296 346 @param fallback 297 347 A default value that gets written to '*output' if there is no conversion. … … 309 359 } 310 360 311 // Directly returns the converted value, even if the conversion was not successful.361 /// Directly returns the converted value, but uses the fallback on failure. @see convertValue 312 362 template<class FromType, class ToType> 313 FORCEINLINE ToType getConvertedValue(const FromType& input) 363 FORCEINLINE ToType getConvertedValue(const FromType& input, const ToType& fallback) 364 { 365 ToType output; 366 convertValue(&output, input, fallback); 367 return output; 368 } 369 370 /** 371 @brief 372 Converts any value to any other as long as there exists a conversion. 373 @details 374 Use exactly the way you use static_cast, etc. <br> 375 A failed conversion will return a default instance of \a ToType 376 (possibly uninitialised) 377 @see Convert.h 378 @param input 379 The original value 380 */ 381 template<class ToType, class FromType> 382 FORCEINLINE ToType multi_cast(const FromType& input) 314 383 { 315 384 ToType output; … … 318 387 } 319 388 320 // Directly returns the converted value, but uses the fallback on failure.321 template<class FromType, class ToType>322 FORCEINLINE ToType getConvertedValue(const FromType& input, const ToType& fallback)323 {324 ToType output;325 convertValue(&output, input, fallback);326 return output;327 }328 329 // Like getConvertedValue, but the template argument order is in reverse.330 // That means you can call it exactly like static_cast<ToType>(fromTypeValue).331 template<class ToType, class FromType>332 FORCEINLINE ToType multi_cast(const FromType& input)333 {334 ToType output;335 convertValue(&output, input);336 return output;337 }338 339 389 //////////////////////////////// 340 390 // Special string conversions // 341 391 //////////////////////////////// 342 392 343 // Delegateconversion from const char* to std::string393 /// Delegates conversion from const char* to std::string 344 394 template <class ToType> 345 395 struct ConverterExplicit<const char*, ToType> … … 351 401 }; 352 402 353 // These conversions would exhibit ambiguous << or >> operators when using stringstream403 /// Conversion would exhibit ambiguous << or >> operators when using iostream 354 404 template <> 355 405 struct ConverterExplicit<char, std::string> … … 361 411 } 362 412 }; 413 /// Conversion would exhibit ambiguous << or >> operators when using iostream 363 414 template <> 364 415 struct ConverterExplicit<unsigned char, std::string> … … 370 421 } 371 422 }; 423 /// Conversion would exhibit ambiguous << or >> operators when using iostream 372 424 template <> 373 425 struct ConverterExplicit<std::string, char> … … 382 434 } 383 435 }; 436 /// Conversion would exhibit ambiguous << or >> operators when using iostream 384 437 template <> 385 438 struct ConverterExplicit<std::string, unsigned char> … … 396 449 397 450 398 // bool to std::string451 /// Conversion from bool to std::string 399 452 template <> 400 453 struct ConverterExplicit<bool, std::string> … … 410 463 }; 411 464 412 // std::string to bool465 /// Conversion from std::string to bool 413 466 template <> 414 467 struct _UtilExport ConverterExplicit<std::string, bool> -
code/trunk/src/libraries/util/Debug.h
r6443 r7401 29 29 30 30 /** 31 @defgroup COUT COUT(x) output macro 32 @ingroup Util 33 */ 34 35 /** 31 36 @file 37 @ingroup COUT 32 38 @brief 33 Handles different output-levels of errors, warnings, infos and debug information.39 Handles different output-levels of errors, warnings, infos, and debug information. 34 40 35 The COUT(level) macro acts like std::cout, but the output is only performed if the given41 The COUT(level) macro acts like @c std::cout, but the output is only performed if the given 36 42 level is <= the soft debug level. 37 43 … … 39 45 - The hard debug level is used during compile time. It describes the highest allowed output level. 40 46 - The soft debug level is used during runtime and is the maximum of the three configurable 41 output-levels for console, log file and in game shell.47 output-levels for console, log file, and in game shell. 42 48 43 49 The separation between the three devices is done by the OutputHandler. 44 50 51 @anchor COUTlevels 45 52 Possible levels are: 46 0: Very important output47 1: Errors48 2: Warnings49 3: Information50 4: Debug information51 5: More debug information52 6: Crazy debug information53 - 0: Very important output 54 - 1: Errors 55 - 2: Warnings 56 - 3: Information 57 - 4: Debug information 58 - 5: More debug information 59 - 6: Crazy debug information 53 60 54 @example 61 Example: 62 @code 55 63 COUT(0) << "Very important output" << std::endl; 56 64 COUT(1) << "Error: Something went wrong!" << std::endl; … … 58 66 COUT(3) << "Info: It's Monday" << std::endl; 59 67 COUT(4) << "Debug: x is 1.23456" << std::endl; 68 @endcode 60 69 */ 61 70 … … 90 99 /** 91 100 @brief 92 Logs text output: use exactly like std::cout, but specify an output 93 level as argument. 94 @details 95 (a > b ? 0 : c << "text") is equivalent to (a > b ? 0 : (c << "text")) 96 where (a > b ? 0 : ) stands for COUT(x). This should explain how 101 Logs text output: You can use COUT(level) exactly like @c std::cout, but you have to specify an output level as argument. 102 @param level 103 The level of the following output (passed with <tt><< "text"</tt>). Lower levels are more important. See @ref COUTlevels "the description above" for a list of possible output levels. 104 105 Example: 106 @code 107 COUT(3) << "Some info" << std::endl; // Output with level 3 108 @endcode 109 @note 110 <tt>(a > b ? 0 : c << "text")</tt> is equivalent to <tt>(a > b ? 0 : (c << "text")</tt> 111 where <tt>(a > b ? 0 : )</tt> stands for COUT(x). This should explain how 97 112 this macro magic can possibly even work ;) 98 @example 99 COUT(3) << "Some info" << std::endl; 100 @note 101 The ? : operator requires both possible results to have the type of 113 @remarks 114 The <tt>? :</tt> operator requires both possible results to have the type of 102 115 the first. This is achieved by the int conversion operator dummy 103 in the OutputHandler.116 in the @ref orxonox::OutputHandler. 104 117 */ 105 118 #define COUT(level) \ -
code/trunk/src/libraries/util/Exception.cc
r7174 r7401 53 53 { } 54 54 55 /**56 @remarks57 The composed full description gets stored to fullDescription_. But for compliance58 with std::exception, this method has to be const. Hence fullDescription_ is declared59 as mutable.60 */61 55 const std::string& Exception::getFullDescription() const 62 56 { … … 89 83 } 90 84 91 //! Returns the error description92 85 const char* Exception::what() const throw() 93 86 { -
code/trunk/src/libraries/util/Exception.h
r6417 r7401 28 28 29 29 /** 30 @defgroup ExceptionAssertion Exceptions and assertions 31 @ingroup Util 32 */ 33 34 /** 30 35 @file 36 @ingroup ExceptionAssertion 31 37 @brief 32 38 Declaration of facilities to handle exceptions. 39 @details 40 Any exception thrown should inherit from orxonox::Exception. There is a macro 41 \ref CREATE_ORXONOX_EXCEPTION to create a new exception (you can find a list of 42 available exceptions in the docs of this file). <br> 43 Throwing exception is also very simple: 44 @code 45 ThrowException(General, "Something went wrong"); 46 @endcode 47 (\c General is a type of exception, see docs of this file) <br> 48 The exception will automatically contain information about file, line number 49 and function name it occurred in. <br><br> 50 There is also some magic you can do for numbers, etc.: 51 @code 52 ThrowException(General, "Error code: " << myInt << ". more info..."); 53 @endcode 54 It works with an std::ostringstream, so you can feed it all sorts of values. 33 55 */ 34 56 … … 45 67 namespace orxonox 46 68 { 47 /** 48 @brief 49 Base class for all exceptions (derived from std::exception). 69 /** Base class for all exceptions (derived from std::exception). 50 70 @details 51 71 This class provides support for information about the file, the line 52 and the function the error occured. 72 and the function the error occurred. 73 @see Exception.h 53 74 */ 54 75 class _UtilExport Exception : public std::exception … … 60 81 @param description 61 82 Exception description as string. This message is supposed to help developers! 83 @param lineNumber 84 The number of the code-line in which the exception occurred 85 @param filename 86 The file in which the exception occurred 87 @param functionName 88 The function in which the exception occurred 62 89 */ 63 90 Exception(const std::string& description, unsigned int lineNumber, … … 68 95 //! Needed for compatibility with std::exception 69 96 virtual ~Exception() throw() { } 97 //! Returns the error description 70 98 const char* what() const throw(); 71 99 72 //! Returns a full description with type, line, file and function 100 /** Returns a full description with type, line, file and function 101 @remarks 102 The composed full description gets stored to fullDescription_. But for compliance 103 with std::exception, this method has to be const. Hence fullDescription_ is declared 104 as mutable. 105 */ 73 106 virtual const std::string& getFullDescription() const; 74 107 //! Returns the string name of the exception type … … 101 134 }; 102 135 103 //! Creates a new type of exception that inherits from tracker::Exception136 //! Creates a new type of exception that inherits from orxonox::Exception 104 137 #define CREATE_ORXONOX_EXCEPTION(ExceptionName) \ 105 138 class ExceptionName##Exception : public Exception \ … … 123 156 // Creates all possible exception types. 124 157 // If you want to add a new type, simply copy and adjust a new line here. 125 #ifndef DOXYGEN_SHOULD_SKIP_THIS126 158 CREATE_ORXONOX_EXCEPTION(General); 127 159 CREATE_ORXONOX_EXCEPTION(FileNotFound); … … 136 168 CREATE_ORXONOX_EXCEPTION(NoGraphics); 137 169 CREATE_ORXONOX_EXCEPTION(AbortLoading); 138 #endif139 170 140 /** 141 @brief 142 Helper function that forwards an exception and displays the message. 171 /** Helper function that forwards an exception and displays the message. 143 172 @details 144 173 This is necessary because only when using 'throw' the objects storage is managed. … … 152 181 } 153 182 154 /** 155 @brief 156 Throws an exception and logs a message beforehand. 183 /** Throws an exception and logs a message beforehand. 157 184 @param type 158 185 Type of the exception as literal (General, Initialisation, etc.) 159 186 @param description 160 187 Exception description as string 188 @see Exception.h 161 189 */ 162 190 #define ThrowException(type, description) \ -
code/trunk/src/libraries/util/ExprParser.h
r6417 r7401 28 28 29 29 /** 30 @file 31 @brief Declaration of FloatParser 30 @file 31 @ingroup Util 32 @brief Declaration of FloatParser 32 33 */ 33 34 … … 42 43 namespace orxonox 43 44 { 45 /** Parser for expressions like \c "3 * cos(5 + 4) / a" where \a a is a predeclared 46 variable. 47 @par Usage 48 Using it is rather simple: 49 @code 50 std::string str("3 + 4"); 51 ExprParser expr; 52 expr.parse(str); 53 if (expr.getSuccess()) 54 { 55 if (!expr.getRemains().empty()) 56 { 57 COUT(2) << "Warning: Expression could not be parsed to the end! Remains: '" << expr.getRemains() << '\'' << std::endl; 58 } 59 double result = expr.getResult(); 60 } 61 else 62 COUT(1) << "Error: Cannot calculate expression: Parse error." << std::endl; 63 @endcode 64 getRemains() returns the expression after what could be parsed. For instance 65 \c "2*3 text" will return \c "text" as remains. 66 @details 67 The implementation of this class is really old and sort of a trial for 68 a first C++ class by Reto. That explains why it looks more like C than 69 C++... Also some of the variable names are in German. <br> 70 Explaining how it works exactly is probably not possible anymore, but it 71 is based on recursively parsing the expression character by character. 72 That much I can remember. 73 @par Functions, operators and variables supported 74 - Variables: 75 - e 76 - pi 77 - Functions: 78 - sin, asin, sinh, asinh 79 - cos, acos, cosh, acosh 80 - tan, atan, tanh, atanh 81 - int, floor, ceil, abs, sign 82 - pow, sqrt, exp, ln, log 83 - mod, div 84 - min, max 85 - radians, degrees 86 - Operators: 87 - +, -, ! (unary) 88 - +, -, *, /, %, ^, |, &, !, <, >, !=, <=, >=, = 89 @note 90 Operators may not be very consistent with C++ rules, but using the class 91 for plus and minus should be perfectly ok. 92 */ 44 93 class _UtilExport ExprParser 45 94 { -
code/trunk/src/libraries/util/ImplicitConversion.h
r7305 r7401 29 29 /** 30 30 @file 31 @ingroup Util 31 32 @brief Declaration of various helper templates. 32 33 */ -
code/trunk/src/libraries/util/Math.cc
r7284 r7401 91 91 @param mydirection My viewing direction 92 92 @param otherposition The position of the other object 93 @return The angle 94 95 @example96 If the other object is exactly in front of me, the function returns 0.97 If the other object is exactly behind me, the function returns pi.98 If the other object is exactly right/left to me (or above/below), the function returns pi/2.93 @return The angle in radian 94 95 Examples: 96 - If the other object is exactly in front of me, the function returns 0. 97 - If the other object is exactly behind me, the function returns pi. 98 - If the other object is exactly right/left to me (or above/below), the function returns pi/2. 99 99 */ 100 100 float getAngle(const orxonox::Vector3& myposition, const orxonox::Vector3& mydirection, const orxonox::Vector3& otherposition) … … 116 116 @return The viewing direction 117 117 118 @example119 If the other object is exactly in front of me, the function returns Vector2(0, 0).120 If the other object is exactly at my left, the function returns Vector2(-1, 0).121 If the other object is exactly at my right, the function returns Vector2(1, 0).122 If the other object is only a bit at my right, the function still returns Vector2(1, 0).123 If the other object is exactly above me, the function returns Vector2(0, 1).118 Examples: 119 - If the other object is exactly in front of me, the function returns <tt>Vector2(0, 0)</tt>. 120 - If the other object is exactly at my left, the function returns <tt>Vector2(-1, 0)</tt>. 121 - If the other object is exactly at my right, the function returns <tt>Vector2(1, 0)</tt>. 122 - If the other object is only a bit at my right, the function still returns <tt>Vector2(1, 0)</tt>. 123 - If the other object is exactly above me, the function returns <tt>Vector2(0, 1)</tt>. 124 124 */ 125 125 orxonox::Vector2 get2DViewdirection(const orxonox::Vector3& myposition, const orxonox::Vector3& mydirection, const orxonox::Vector3& myorthonormal, const orxonox::Vector3& otherposition) … … 156 156 @return The viewing direction 157 157 158 @example159 If the other object is exactly in front of me, the function returns Vector2(0, 0).160 If the other object is exactly at my left, the function returns Vector2(-0.5, 0).161 If the other object is exactly at my right, the function returns Vector2(0.5, 0).162 If the other object is only a bit at my right, the function still returns Vector2(0.01, 0).163 If the other object is exactly above me, the function returns Vector2(0, 0.5).158 Examples: 159 - If the other object is exactly in front of me, the function returns <tt>Vector2(0, 0)</tt>. 160 - If the other object is exactly at my left, the function returns <tt>Vector2(-0.5, 0)</tt>. 161 - If the other object is exactly at my right, the function returns <tt>Vector2(0.5, 0)</tt>. 162 - If the other object is only a bit at my right, the function still returns <tt>Vector2(0.01, 0)</tt>. 163 - If the other object is exactly above me, the function returns <tt>Vector2(0, 0.5)</tt>. 164 164 */ 165 165 orxonox::Vector2 get2DViewcoordinates(const orxonox::Vector3& myposition, const orxonox::Vector3& mydirection, const orxonox::Vector3& myorthonormal, const orxonox::Vector3& otherposition) … … 220 220 } 221 221 222 /** 223 @brief Returns a unique number. This function will never return the same value twice. 224 */ 222 225 unsigned long getUniqueNumber() 223 226 { -
code/trunk/src/libraries/util/Math.h
r7184 r7401 28 28 29 29 /** 30 @defgroup Math Mathematical functions 31 @ingroup Util 32 */ 33 34 /** 30 35 @file 36 @ingroup Math 31 37 @brief Declaration and implementation of several math-functions, typedefs of some Ogre::Math classes to the orxonox namespace. 32 38 */ … … 62 68 namespace math 63 69 { 64 const float pi = 3.14159265f; 65 const float pi_2 = 1.57079633f; 66 const float pi_4 = 7.85398163e-1f; 67 const float e = 2.71828183f; 68 const float sqrt2 = 1.41421356f; 69 const float sqrt2_2 = 7.07106781e-1f; 70 71 const double pi_d = 3.14159265358979324; 72 const double pi_2_d = 1.57079632679489662; 73 const double pi_4_d = 7.85398163397448310e-1; 74 const double e_d = 2.71828182845904524; 75 const double sqrt2_d = 1.41421356237309505; 76 const double sqrt2_2_d = 7.07106781186547524e-1; 70 const float pi = 3.14159265f; ///< PI 71 const float pi_2 = 1.57079633f; ///< PI / 2 72 const float pi_4 = 7.85398163e-1f; ///< PI / 4 73 const float e = 2.71828183f; ///< e 74 const float sqrt2 = 1.41421356f; ///< sqrt(2) 75 const float sqrt2_2 = 7.07106781e-1f; ///< sqrt(2) / 2 76 77 const double pi_d = 3.14159265358979324; ///< PI (double) 78 const double pi_2_d = 1.57079632679489662; ///< PI / 2 (double) 79 const double pi_4_d = 7.85398163397448310e-1; ///< PI / 4 (double) 80 const double e_d = 2.71828182845904524; ///< e (double) 81 const double sqrt2_d = 1.41421356237309505; ///< sqrt(2) (double) 82 const double sqrt2_2_d = 7.07106781186547524e-1; ///< sqrt(2) / 2 (double) 77 83 } 78 84 … … 101 107 102 108 /** 103 @brief Keeps a value between a lower and an upper limit. 109 @brief Keeps a value between a lower and an upper limit. Values beyond these limits are limited to either @a min or @a max. 104 110 @param x The value 105 111 @param min The lower limit … … 119 125 120 126 /** 121 @brief Returns the square value (x^2).127 @brief Returns the squared value (x^2). 122 128 */ 123 129 template <typename T> … … 128 134 129 135 /** 130 @brief Returns the cube value (x^3).136 @brief Returns the cubed value (x^3). 131 137 */ 132 138 template <typename T> … … 137 143 138 144 /** 139 @brief Rounds the value .145 @brief Rounds the value to the nearest integer. 140 146 */ 141 147 template <typename T> … … 149 155 @param x The value 150 156 @param max The operand 157 158 The built in modulo operator % yields a strange behavior with negative values. 159 This function corrects this - the result is guaranteed to lie always between 160 zero and (max-1). 161 162 Example: 163 @code 164 int var = 11 % 10; // 1 165 int var = -1 % 10; // -1 166 167 int var = mod(11, 10); // 1 168 int var = mod(-1, 10); // 9 169 @endcode 151 170 */ 152 171 template <typename T> … … 159 178 } 160 179 180 /** 181 @brief Returns a "zero" value for the given type. 182 @note This is the default template of the zeroise() function. The template is spezialized for each supported type. 183 184 The exact return value of the function depends on the type. For @c int this is 0, 185 for @c float it's 0.0f. For a @c std::string the function returns "" and for 186 @c Vector3 you get <tt>Vector3(0, 0, 0)</tt>. 187 */ 161 188 template <typename T> 162 189 inline T zeroise() … … 192 219 template <> inline orxonox::Quaternion zeroise<orxonox::Quaternion>() { return orxonox::Quaternion (0, 0, 0, 0); } 193 220 194 //! Provides zero value symbols that can be returned as reference 221 /** 222 @brief Provides zero value symbols that can be returned as reference 223 @see zeroise() 224 */ 195 225 template <typename T> 196 226 struct NilValue … … 207 237 /** 208 238 @brief Interpolates between two values for a time between 0 and 1. 209 @param time The time is a value between 0 and 1 - the function returns start if time is 0 and end if time is 1 and interpolates iftime is between 0 and 1.210 @param start The value at time = 0211 @param end The value at time = 1212 @return The interpolat ionat a given time239 @param time The time is a value between 0 and 1 - the function returns @a start if @a time is 0, @a end if @a time is 1, and interpolates if @a time is between 0 and 1. 240 @param start The value at @a time = 0 241 @param end The value at @a time = 1 242 @return The interpolated value at a given time 213 243 */ 214 244 template <typename T> … … 220 250 /** 221 251 @brief Interpolates smoothly between two values for a time between 0 and 1. The function starts slowly, increases faster and stops slowly again. 222 @param time The time is a value between 0 and 1 - the function returns start if time is 0 and end if time is 1 and interpolates iftime is between 0 and 1.223 @param start The value at time = 0224 @param end The value at time = 1225 @return The smoothed interpolationat a given time252 @param time The time is a value between 0 and 1 - the function returns @a start if @a time is 0, @a end if @a time is 1, and interpolates if @a time is between 0 and 1. 253 @param start The value at @a time = 0 254 @param end The value at @a time = 1 255 @return The interpolated value at a given time 226 256 */ 227 257 template <typename T> … … 232 262 233 263 /** 234 @brief Returns a random number between 0 and almost 1: 0 <= rnd < 1.264 @brief Returns a random number between 0 and almost 1: <tt>0 <= rnd < 1</tt>. 235 265 */ 236 266 inline float rnd() … … 240 270 241 271 /** 242 @brief Returns a random number between 0 and almost max: 0 <= rnd < max.272 @brief Returns a random number between 0 and almost @a max: <tt>0 <= rnd < max</tt>. 243 273 @param max The maximum 244 274 */ … … 249 279 250 280 /** 251 @brief Returns a random number between min and almost max: min <= rnd < max.281 @brief Returns a random number between @a min and almost @a max: <tt>min <= rnd < max</tt>. 252 282 @param min The minimum 253 283 @param max The maximum … … 268 298 _UtilExport unsigned long getUniqueNumber(); 269 299 300 /** 301 @brief A Vector class containing two integers @a x and @a y. 302 */ 270 303 class IntVector2 271 304 { … … 277 310 }; 278 311 312 /** 313 @brief A Vector class containing three integers @a x, @a y, and @a z. 314 */ 279 315 class IntVector3 280 316 { -
code/trunk/src/libraries/util/MathConvert.h
r6417 r7401 28 28 29 29 /** 30 @file 31 @brief 32 Math conversion functions. Definitions are in Math.cc 30 @file 31 @ingroup Convert 32 @brief 33 Conversion functions for Math types like Ogre::Vector3 (definitions are in Math.cc) 33 34 */ 34 35 … … 46 47 //////////////////// 47 48 48 // Vector2 to std::string49 /// Ogre::Vector2 to std::string conversion 49 50 template <> 50 51 struct ConverterExplicit<orxonox::Vector2, std::string> … … 62 63 }; 63 64 64 // Vector3 to std::string65 /// Ogre::Vector3 to std::string conversion 65 66 template <> 66 67 struct ConverterExplicit<orxonox::Vector3, std::string> … … 78 79 }; 79 80 80 // Vector4 to std::string81 /// Ogre::Vector4 to std::string conversion 81 82 template <> 82 83 struct ConverterExplicit<orxonox::Vector4, std::string> … … 94 95 }; 95 96 96 // Quaternion to std::string97 /// Ogre::Quaternion to std::string conversion 97 98 template <> 98 99 struct ConverterExplicit<orxonox::Quaternion, std::string> … … 110 111 }; 111 112 112 // ColourValue to std::string113 /// Ogre::ColourValue to std::string conversion 113 114 template <> 114 115 struct ConverterExplicit<orxonox::ColourValue, std::string> … … 131 132 //////////////////// 132 133 133 // std::string to Vector2134 /// std::string to Ogre::Vector2 conversion 134 135 template <> struct _UtilExport ConverterFallback<std::string, orxonox::Vector2> 135 136 { static bool convert(orxonox::Vector2* output, const std::string& input); }; 136 // std::string to Vector3137 /// std::string to Ogre::Vector3 conversion 137 138 template <> struct _UtilExport ConverterFallback<std::string, orxonox::Vector3> 138 139 { static bool convert(orxonox::Vector3* output, const std::string& input); }; 139 // std::string to Vector4140 /// std::string to Ogre::Vector4 conversion 140 141 template <> struct _UtilExport ConverterFallback<std::string, orxonox::Vector4> 141 142 { static bool convert(orxonox::Vector4* output, const std::string& input); }; 142 // std::string to Quaternion143 /// std::string to Ogre::Quaternion conversion 143 144 template <> struct _UtilExport ConverterFallback<std::string, orxonox::Quaternion> 144 145 { static bool convert(orxonox::Quaternion* output, const std::string& input); }; 145 // std::string to ColourValue146 /// std::string to Ogre::ColourValue conversion 146 147 template <> struct _UtilExport ConverterFallback<std::string, orxonox::ColourValue> 147 148 { static bool convert(orxonox::ColourValue* output, const std::string& input); }; … … 152 153 /////////////////////////////// 153 154 154 // From Radian155 /// Delegates conversions from Radian to conversions from float 155 156 template <class ToType> 156 157 struct ConverterFallback<orxonox::Radian, ToType> … … 162 163 }; 163 164 164 // From Degree165 /// Delegates conversions from Degree to conversions from float 165 166 template <class ToType> 166 167 struct ConverterFallback<orxonox::Degree, ToType> … … 172 173 }; 173 174 174 // To Radian175 /// Delegates conversions to Radian to conversions to float 175 176 template <class FromType> 176 177 struct ConverterFallback<FromType, orxonox::Radian> … … 189 190 }; 190 191 191 // To Degree192 /// Delegates conversions to Degree to conversions to float 192 193 template <class FromType> 193 194 struct ConverterFallback<FromType, orxonox::Degree> -
code/trunk/src/libraries/util/MultiType.cc
r5738 r7401 159 159 } 160 160 161 MultiType::operator char() const { return (this->value_) ? ((this->value_->type_ == MT_Type::Char ) ? (static_cast<MT_Value<char> *>(this->value_))->value_ : (*this->value_)) : 0; } / ** @brief Returns the current value, converted to the requested type. */162 MultiType::operator unsigned char() const { return (this->value_) ? ((this->value_->type_ == MT_Type::UnsignedChar ) ? (static_cast<MT_Value<unsigned char> *>(this->value_))->value_ : (*this->value_)) : 0; } / ** @brief Returns the current value, converted to the requested type. */163 MultiType::operator short() const { return (this->value_) ? ((this->value_->type_ == MT_Type::Short ) ? (static_cast<MT_Value<short> *>(this->value_))->value_ : (*this->value_)) : 0; } / ** @brief Returns the current value, converted to the requested type. */164 MultiType::operator unsigned short() const { return (this->value_) ? ((this->value_->type_ == MT_Type::UnsignedShort ) ? (static_cast<MT_Value<unsigned short> *>(this->value_))->value_ : (*this->value_)) : 0; } / ** @brief Returns the current value, converted to the requested type. */165 MultiType::operator int() const { return (this->value_) ? ((this->value_->type_ == MT_Type::Int ) ? (static_cast<MT_Value<int> *>(this->value_))->value_ : (*this->value_)) : 0; } / ** @brief Returns the current value, converted to the requested type. */166 MultiType::operator unsigned int() const { return (this->value_) ? ((this->value_->type_ == MT_Type::UnsignedInt ) ? (static_cast<MT_Value<unsigned int> *>(this->value_))->value_ : (*this->value_)) : 0; } / ** @brief Returns the current value, converted to the requested type. */167 MultiType::operator long() const { return (this->value_) ? ((this->value_->type_ == MT_Type::Long ) ? (static_cast<MT_Value<long> *>(this->value_))->value_ : (*this->value_)) : 0; } / ** @brief Returns the current value, converted to the requested type. */168 MultiType::operator unsigned long() const { return (this->value_) ? ((this->value_->type_ == MT_Type::UnsignedLong ) ? (static_cast<MT_Value<unsigned long> *>(this->value_))->value_ : (*this->value_)) : 0; } / ** @brief Returns the current value, converted to the requested type. */169 MultiType::operator long long() const { return (this->value_) ? ((this->value_->type_ == MT_Type::LongLong ) ? (static_cast<MT_Value<long long> *>(this->value_))->value_ : (*this->value_)) : 0; } / ** @brief Returns the current value, converted to the requested type. */170 MultiType::operator unsigned long long() const { return (this->value_) ? ((this->value_->type_ == MT_Type::UnsignedLongLong) ? (static_cast<MT_Value<unsigned long long> *>(this->value_))->value_ : (*this->value_)) : 0; } / ** @brief Returns the current value, converted to the requested type. */171 MultiType::operator float() const { return (this->value_) ? ((this->value_->type_ == MT_Type::Float ) ? (static_cast<MT_Value<float> *>(this->value_))->value_ : (*this->value_)) : 0; } / ** @brief Returns the current value, converted to the requested type. */172 MultiType::operator double() const { return (this->value_) ? ((this->value_->type_ == MT_Type::Double ) ? (static_cast<MT_Value<double> *>(this->value_))->value_ : (*this->value_)) : 0; } / ** @brief Returns the current value, converted to the requested type. */173 MultiType::operator long double() const { return (this->value_) ? ((this->value_->type_ == MT_Type::LongDouble ) ? (static_cast<MT_Value<long double> *>(this->value_))->value_ : (*this->value_)) : 0; } / ** @brief Returns the current value, converted to the requested type. */174 MultiType::operator bool() const { return (this->value_) ? ((this->value_->type_ == MT_Type::Bool ) ? (static_cast<MT_Value<bool> *>(this->value_))->value_ : (*this->value_)) : 0; } / ** @brief Returns the current value, converted to the requested type. */175 MultiType::operator void*() const { return (this->value_) ? ((this->value_->type_ == MT_Type::VoidPointer ) ? (static_cast<MT_Value<void*> *>(this->value_))->value_ : (*this->value_)) : 0; } / ** @brief Returns the current value, converted to the requested type. */176 MultiType::operator std::string() const { return (this->value_) ? ((this->value_->type_ == MT_Type::String ) ? (static_cast<MT_Value<std::string> *>(this->value_))->value_ : (*this->value_)) : NilValue<std::string>(); } / ** @brief Returns the current value, converted to the requested type. */177 MultiType::operator orxonox::Vector2() const { return (this->value_) ? ((this->value_->type_ == MT_Type::Vector2 ) ? (static_cast<MT_Value<orxonox::Vector2> *>(this->value_))->value_ : (*this->value_)) : NilValue<orxonox::Vector2>(); } / ** @brief Returns the current value, converted to the requested type. */178 MultiType::operator orxonox::Vector3() const { return (this->value_) ? ((this->value_->type_ == MT_Type::Vector3 ) ? (static_cast<MT_Value<orxonox::Vector3> *>(this->value_))->value_ : (*this->value_)) : NilValue<orxonox::Vector3>(); } / ** @brief Returns the current value, converted to the requested type. */179 MultiType::operator orxonox::Vector4() const { return (this->value_) ? ((this->value_->type_ == MT_Type::Vector4 ) ? (static_cast<MT_Value<orxonox::Vector4> *>(this->value_))->value_ : (*this->value_)) : NilValue<orxonox::Vector4>(); } / ** @brief Returns the current value, converted to the requested type. */180 MultiType::operator orxonox::ColourValue() const { return (this->value_) ? ((this->value_->type_ == MT_Type::ColourValue ) ? (static_cast<MT_Value<orxonox::ColourValue>*>(this->value_))->value_ : (*this->value_)) : NilValue<orxonox::ColourValue>(); } / ** @brief Returns the current value, converted to the requested type. */181 MultiType::operator orxonox::Quaternion() const { return (this->value_) ? ((this->value_->type_ == MT_Type::Quaternion ) ? (static_cast<MT_Value<orxonox::Quaternion> *>(this->value_))->value_ : (*this->value_)) : NilValue<orxonox::Quaternion>(); } / ** @brief Returns the current value, converted to the requested type. */182 MultiType::operator orxonox::Radian() const { return (this->value_) ? ((this->value_->type_ == MT_Type::Radian ) ? (static_cast<MT_Value<orxonox::Radian> *>(this->value_))->value_ : (*this->value_)) : NilValue<orxonox::Radian>(); } / ** @brief Returns the current value, converted to the requested type. */183 MultiType::operator orxonox::Degree() const { return (this->value_) ? ((this->value_->type_ == MT_Type::Degree ) ? (static_cast<MT_Value<orxonox::Degree> *>(this->value_))->value_ : (*this->value_)) : NilValue<orxonox::Degree>(); } / ** @brief Returns the current value, converted to the requested type. */184 185 template <> void MultiType::createNewValueContainer(const char& value) { this->value_ = new MT_Value<char> (value, MT_Type::Char ); } / ** @brief Creates a new value container for the given type. */186 template <> void MultiType::createNewValueContainer(const unsigned char& value) { this->value_ = new MT_Value<unsigned char> (value, MT_Type::UnsignedChar ); } / ** @brief Creates a new value container for the given type. */187 template <> void MultiType::createNewValueContainer(const short& value) { this->value_ = new MT_Value<short> (value, MT_Type::Short ); } / ** @brief Creates a new value container for the given type. */188 template <> void MultiType::createNewValueContainer(const unsigned short& value) { this->value_ = new MT_Value<unsigned short> (value, MT_Type::UnsignedShort ); } / ** @brief Creates a new value container for the given type. */189 template <> void MultiType::createNewValueContainer(const int& value) { this->value_ = new MT_Value<int> (value, MT_Type::Int ); } / ** @brief Creates a new value container for the given type. */190 template <> void MultiType::createNewValueContainer(const unsigned int& value) { this->value_ = new MT_Value<unsigned int> (value, MT_Type::UnsignedInt ); } / ** @brief Creates a new value container for the given type. */191 template <> void MultiType::createNewValueContainer(const long& value) { this->value_ = new MT_Value<long> (value, MT_Type::Long ); } / ** @brief Creates a new value container for the given type. */192 template <> void MultiType::createNewValueContainer(const unsigned long& value) { this->value_ = new MT_Value<unsigned long> (value, MT_Type::UnsignedLong ); } / ** @brief Creates a new value container for the given type. */193 template <> void MultiType::createNewValueContainer(const long long& value) { this->value_ = new MT_Value<long long> (value, MT_Type::LongLong ); } / ** @brief Creates a new value container for the given type. */194 template <> void MultiType::createNewValueContainer(const unsigned long long& value) { this->value_ = new MT_Value<unsigned long long> (value, MT_Type::UnsignedLongLong); } / ** @brief Creates a new value container for the given type. */195 template <> void MultiType::createNewValueContainer(const float& value) { this->value_ = new MT_Value<float> (value, MT_Type::Float ); } / ** @brief Creates a new value container for the given type. */196 template <> void MultiType::createNewValueContainer(const double& value) { this->value_ = new MT_Value<double> (value, MT_Type::Double ); } / ** @brief Creates a new value container for the given type. */197 template <> void MultiType::createNewValueContainer(const long double& value) { this->value_ = new MT_Value<long double> (value, MT_Type::LongDouble ); } / ** @brief Creates a new value container for the given type. */198 template <> void MultiType::createNewValueContainer(const bool& value) { this->value_ = new MT_Value<bool> (value, MT_Type::Bool ); } / ** @brief Creates a new value container for the given type. */199 template <> void MultiType::createNewValueContainer( void* const& value) { this->value_ = new MT_Value<void*> (value, MT_Type::VoidPointer ); } / ** @brief Creates a new value container for the given type. */200 template <> void MultiType::createNewValueContainer(const std::string& value) { this->value_ = new MT_Value<std::string> (value, MT_Type::String ); } / ** @brief Creates a new value container for the given type. */201 template <> void MultiType::createNewValueContainer(const orxonox::Vector2& value) { this->value_ = new MT_Value<orxonox::Vector2> (value, MT_Type::Vector2 ); } / ** @brief Creates a new value container for the given type. */202 template <> void MultiType::createNewValueContainer(const orxonox::Vector3& value) { this->value_ = new MT_Value<orxonox::Vector3> (value, MT_Type::Vector3 ); } / ** @brief Creates a new value container for the given type. */203 template <> void MultiType::createNewValueContainer(const orxonox::Vector4& value) { this->value_ = new MT_Value<orxonox::Vector4> (value, MT_Type::Vector4 ); } / ** @brief Creates a new value container for the given type. */204 template <> void MultiType::createNewValueContainer(const orxonox::ColourValue& value) { this->value_ = new MT_Value<orxonox::ColourValue>(value, MT_Type::ColourValue ); } / ** @brief Creates a new value container for the given type. */205 template <> void MultiType::createNewValueContainer(const orxonox::Quaternion& value) { this->value_ = new MT_Value<orxonox::Quaternion> (value, MT_Type::Quaternion ); } / ** @brief Creates a new value container for the given type. */206 template <> void MultiType::createNewValueContainer(const orxonox::Radian& value) { this->value_ = new MT_Value<orxonox::Radian> (value, MT_Type::Radian ); } / ** @brief Creates a new value container for the given type. */207 template <> void MultiType::createNewValueContainer(const orxonox::Degree& value) { this->value_ = new MT_Value<orxonox::Degree> (value, MT_Type::Degree ); } / ** @brief Creates a new value container for the given type. */161 MultiType::operator char() const { return (this->value_) ? ((this->value_->type_ == MT_Type::Char ) ? (static_cast<MT_Value<char> *>(this->value_))->value_ : (*this->value_)) : 0; } ///< Returns the current value, converted to the requested type. 162 MultiType::operator unsigned char() const { return (this->value_) ? ((this->value_->type_ == MT_Type::UnsignedChar ) ? (static_cast<MT_Value<unsigned char> *>(this->value_))->value_ : (*this->value_)) : 0; } ///< Returns the current value, converted to the requested type. 163 MultiType::operator short() const { return (this->value_) ? ((this->value_->type_ == MT_Type::Short ) ? (static_cast<MT_Value<short> *>(this->value_))->value_ : (*this->value_)) : 0; } ///< Returns the current value, converted to the requested type. 164 MultiType::operator unsigned short() const { return (this->value_) ? ((this->value_->type_ == MT_Type::UnsignedShort ) ? (static_cast<MT_Value<unsigned short> *>(this->value_))->value_ : (*this->value_)) : 0; } ///< Returns the current value, converted to the requested type. 165 MultiType::operator int() const { return (this->value_) ? ((this->value_->type_ == MT_Type::Int ) ? (static_cast<MT_Value<int> *>(this->value_))->value_ : (*this->value_)) : 0; } ///< Returns the current value, converted to the requested type. 166 MultiType::operator unsigned int() const { return (this->value_) ? ((this->value_->type_ == MT_Type::UnsignedInt ) ? (static_cast<MT_Value<unsigned int> *>(this->value_))->value_ : (*this->value_)) : 0; } ///< Returns the current value, converted to the requested type. 167 MultiType::operator long() const { return (this->value_) ? ((this->value_->type_ == MT_Type::Long ) ? (static_cast<MT_Value<long> *>(this->value_))->value_ : (*this->value_)) : 0; } ///< Returns the current value, converted to the requested type. 168 MultiType::operator unsigned long() const { return (this->value_) ? ((this->value_->type_ == MT_Type::UnsignedLong ) ? (static_cast<MT_Value<unsigned long> *>(this->value_))->value_ : (*this->value_)) : 0; } ///< Returns the current value, converted to the requested type. 169 MultiType::operator long long() const { return (this->value_) ? ((this->value_->type_ == MT_Type::LongLong ) ? (static_cast<MT_Value<long long> *>(this->value_))->value_ : (*this->value_)) : 0; } ///< Returns the current value, converted to the requested type. 170 MultiType::operator unsigned long long() const { return (this->value_) ? ((this->value_->type_ == MT_Type::UnsignedLongLong) ? (static_cast<MT_Value<unsigned long long> *>(this->value_))->value_ : (*this->value_)) : 0; } ///< Returns the current value, converted to the requested type. 171 MultiType::operator float() const { return (this->value_) ? ((this->value_->type_ == MT_Type::Float ) ? (static_cast<MT_Value<float> *>(this->value_))->value_ : (*this->value_)) : 0; } ///< Returns the current value, converted to the requested type. 172 MultiType::operator double() const { return (this->value_) ? ((this->value_->type_ == MT_Type::Double ) ? (static_cast<MT_Value<double> *>(this->value_))->value_ : (*this->value_)) : 0; } ///< Returns the current value, converted to the requested type. 173 MultiType::operator long double() const { return (this->value_) ? ((this->value_->type_ == MT_Type::LongDouble ) ? (static_cast<MT_Value<long double> *>(this->value_))->value_ : (*this->value_)) : 0; } ///< Returns the current value, converted to the requested type. 174 MultiType::operator bool() const { return (this->value_) ? ((this->value_->type_ == MT_Type::Bool ) ? (static_cast<MT_Value<bool> *>(this->value_))->value_ : (*this->value_)) : 0; } ///< Returns the current value, converted to the requested type. 175 MultiType::operator void*() const { return (this->value_) ? ((this->value_->type_ == MT_Type::VoidPointer ) ? (static_cast<MT_Value<void*> *>(this->value_))->value_ : (*this->value_)) : 0; } ///< Returns the current value, converted to the requested type. 176 MultiType::operator std::string() const { return (this->value_) ? ((this->value_->type_ == MT_Type::String ) ? (static_cast<MT_Value<std::string> *>(this->value_))->value_ : (*this->value_)) : NilValue<std::string>(); } ///< Returns the current value, converted to the requested type. 177 MultiType::operator orxonox::Vector2() const { return (this->value_) ? ((this->value_->type_ == MT_Type::Vector2 ) ? (static_cast<MT_Value<orxonox::Vector2> *>(this->value_))->value_ : (*this->value_)) : NilValue<orxonox::Vector2>(); } ///< Returns the current value, converted to the requested type. 178 MultiType::operator orxonox::Vector3() const { return (this->value_) ? ((this->value_->type_ == MT_Type::Vector3 ) ? (static_cast<MT_Value<orxonox::Vector3> *>(this->value_))->value_ : (*this->value_)) : NilValue<orxonox::Vector3>(); } ///< Returns the current value, converted to the requested type. 179 MultiType::operator orxonox::Vector4() const { return (this->value_) ? ((this->value_->type_ == MT_Type::Vector4 ) ? (static_cast<MT_Value<orxonox::Vector4> *>(this->value_))->value_ : (*this->value_)) : NilValue<orxonox::Vector4>(); } ///< Returns the current value, converted to the requested type. 180 MultiType::operator orxonox::ColourValue() const { return (this->value_) ? ((this->value_->type_ == MT_Type::ColourValue ) ? (static_cast<MT_Value<orxonox::ColourValue>*>(this->value_))->value_ : (*this->value_)) : NilValue<orxonox::ColourValue>(); } ///< Returns the current value, converted to the requested type. 181 MultiType::operator orxonox::Quaternion() const { return (this->value_) ? ((this->value_->type_ == MT_Type::Quaternion ) ? (static_cast<MT_Value<orxonox::Quaternion> *>(this->value_))->value_ : (*this->value_)) : NilValue<orxonox::Quaternion>(); } ///< Returns the current value, converted to the requested type. 182 MultiType::operator orxonox::Radian() const { return (this->value_) ? ((this->value_->type_ == MT_Type::Radian ) ? (static_cast<MT_Value<orxonox::Radian> *>(this->value_))->value_ : (*this->value_)) : NilValue<orxonox::Radian>(); } ///< Returns the current value, converted to the requested type. 183 MultiType::operator orxonox::Degree() const { return (this->value_) ? ((this->value_->type_ == MT_Type::Degree ) ? (static_cast<MT_Value<orxonox::Degree> *>(this->value_))->value_ : (*this->value_)) : NilValue<orxonox::Degree>(); } ///< Returns the current value, converted to the requested type. 184 185 template <> void MultiType::createNewValueContainer(const char& value) { this->value_ = new MT_Value<char> (value, MT_Type::Char ); } ///< Creates a new value container for the given type. 186 template <> void MultiType::createNewValueContainer(const unsigned char& value) { this->value_ = new MT_Value<unsigned char> (value, MT_Type::UnsignedChar ); } ///< Creates a new value container for the given type. 187 template <> void MultiType::createNewValueContainer(const short& value) { this->value_ = new MT_Value<short> (value, MT_Type::Short ); } ///< Creates a new value container for the given type. 188 template <> void MultiType::createNewValueContainer(const unsigned short& value) { this->value_ = new MT_Value<unsigned short> (value, MT_Type::UnsignedShort ); } ///< Creates a new value container for the given type. 189 template <> void MultiType::createNewValueContainer(const int& value) { this->value_ = new MT_Value<int> (value, MT_Type::Int ); } ///< Creates a new value container for the given type. 190 template <> void MultiType::createNewValueContainer(const unsigned int& value) { this->value_ = new MT_Value<unsigned int> (value, MT_Type::UnsignedInt ); } ///< Creates a new value container for the given type. 191 template <> void MultiType::createNewValueContainer(const long& value) { this->value_ = new MT_Value<long> (value, MT_Type::Long ); } ///< Creates a new value container for the given type. 192 template <> void MultiType::createNewValueContainer(const unsigned long& value) { this->value_ = new MT_Value<unsigned long> (value, MT_Type::UnsignedLong ); } ///< Creates a new value container for the given type. 193 template <> void MultiType::createNewValueContainer(const long long& value) { this->value_ = new MT_Value<long long> (value, MT_Type::LongLong ); } ///< Creates a new value container for the given type. 194 template <> void MultiType::createNewValueContainer(const unsigned long long& value) { this->value_ = new MT_Value<unsigned long long> (value, MT_Type::UnsignedLongLong); } ///< Creates a new value container for the given type. 195 template <> void MultiType::createNewValueContainer(const float& value) { this->value_ = new MT_Value<float> (value, MT_Type::Float ); } ///< Creates a new value container for the given type. 196 template <> void MultiType::createNewValueContainer(const double& value) { this->value_ = new MT_Value<double> (value, MT_Type::Double ); } ///< Creates a new value container for the given type. 197 template <> void MultiType::createNewValueContainer(const long double& value) { this->value_ = new MT_Value<long double> (value, MT_Type::LongDouble ); } ///< Creates a new value container for the given type. 198 template <> void MultiType::createNewValueContainer(const bool& value) { this->value_ = new MT_Value<bool> (value, MT_Type::Bool ); } ///< Creates a new value container for the given type. 199 template <> void MultiType::createNewValueContainer( void* const& value) { this->value_ = new MT_Value<void*> (value, MT_Type::VoidPointer ); } ///< Creates a new value container for the given type. 200 template <> void MultiType::createNewValueContainer(const std::string& value) { this->value_ = new MT_Value<std::string> (value, MT_Type::String ); } ///< Creates a new value container for the given type. 201 template <> void MultiType::createNewValueContainer(const orxonox::Vector2& value) { this->value_ = new MT_Value<orxonox::Vector2> (value, MT_Type::Vector2 ); } ///< Creates a new value container for the given type. 202 template <> void MultiType::createNewValueContainer(const orxonox::Vector3& value) { this->value_ = new MT_Value<orxonox::Vector3> (value, MT_Type::Vector3 ); } ///< Creates a new value container for the given type. 203 template <> void MultiType::createNewValueContainer(const orxonox::Vector4& value) { this->value_ = new MT_Value<orxonox::Vector4> (value, MT_Type::Vector4 ); } ///< Creates a new value container for the given type. 204 template <> void MultiType::createNewValueContainer(const orxonox::ColourValue& value) { this->value_ = new MT_Value<orxonox::ColourValue>(value, MT_Type::ColourValue ); } ///< Creates a new value container for the given type. 205 template <> void MultiType::createNewValueContainer(const orxonox::Quaternion& value) { this->value_ = new MT_Value<orxonox::Quaternion> (value, MT_Type::Quaternion ); } ///< Creates a new value container for the given type. 206 template <> void MultiType::createNewValueContainer(const orxonox::Radian& value) { this->value_ = new MT_Value<orxonox::Radian> (value, MT_Type::Radian ); } ///< Creates a new value container for the given type. 207 template <> void MultiType::createNewValueContainer(const orxonox::Degree& value) { this->value_ = new MT_Value<orxonox::Degree> (value, MT_Type::Degree ); } ///< Creates a new value container for the given type. 208 208 } -
code/trunk/src/libraries/util/MultiType.h
r7284 r7401 28 28 29 29 /** 30 @defgroup MultiType MultiType 31 @ingroup Util 32 */ 33 34 /** 30 35 @file 36 @ingroup MultiType 31 37 @brief Declaration of the MultiType and some helper constructs. 32 38 39 @anchor MultiTypeExamples 40 33 41 The MultiType can hold a value of one of the following types: 34 - all primitives 35 - all pointers 36 - st ring42 - all primitives (int, float, bool, etc.) 43 - all pointers (void* and T*) 44 - std::string 37 45 - Vector2, Vector3, Vector4 38 46 - Quaternion … … 40 48 - Radian, Degree 41 49 42 The MultiType has a "type" determined by the first assigned value, either through 43 - the constructor, 44 - the assignment operator= or 45 - setValue(value). 46 If you assign another value of another type, the MultiType keeps "it's" type and 47 converts the new value to this type. 50 The MultiType has an internal "type" determined by the first assigned value, using one of these ways: 51 - @ref orxonox::MultiType::MultiType "The constructor" 52 - The assignment operator= (orxonox::MultiType::operator=()) 53 - @ref orxonox::MultiType::setValue() "setValue(value)" 54 55 If you assign another value of another type, the MultiType keeps "its" type and 56 converts the new value to the old type. 48 57 49 58 If you want to change the type, there are three possibilities: 50 - convert<T>() set's the type to T and converts the currently assigned value51 - setType<T>() set's the type to T and resets the value59 - @ref orxonox::MultiType::convert "convert<T>()" sets the type to T and converts the currently assigned value 60 - @ref orxonox::MultiType::setType "setType<T>()" sets the type to T and resets the value to zero using zeroise<T>() 52 61 - setValue<T>(value) assigns a new value and changes the type to T. 53 62 54 @example 55 MultiType a = 10;; // a has now the type int and the value 10 63 Examples: 64 @code 65 MultiType a = 10; // a has now the type int and the value 10 56 66 a.setValue("3.14"); // a has still the type int and "3.14" gets converted, therefore the value is now 3 57 a.setValue<float>("3.14"); // a has now the type float and "3.14" gets converted to 3.14 58 a.convert<bool>(); // converts 3.14 to bool, which is true67 a.setValue<float>("3.14"); // a has now the type float and "3.14" gets converted to 3.14f 68 a.convert<bool>(); // converts 3.14f to bool, which is true 59 69 a = false; // assigns false, this is equivalent to a.setValue(false) 70 @endcode 71 72 You can pass a MultiType to a function as an argument, even if the argument is 73 not of type MultiType. This works, because the MultiType is automatically converted 74 to the right type. 75 76 Example: 77 @code 78 void myfunction(int value) 79 { 80 COUT(0) << "doubled value is " << (2 * value) << std::endl; 81 } 82 83 MultiType a = "50"; // Note: We assigned a string 84 myfunction(a); // a is converted to int and passed to the function, which prints "value is 100" 85 @endcode 86 87 Note however that it is of course quite expensive to convert values, especially std::string <-> value. 88 So if you can, always assign a value with the right type to avoid conversion. 60 89 61 90 @note … … 127 156 - Radian, Degree 128 157 129 The internal type of a MultiType is determined by the first assigned value, but can be 130 changed by using setType<T>(), convert<T>() or setValue<T>(value). If a value gets assigned 131 the normal way (operator=, setValue(value)), the value gets converted to the current internal 132 type of the MultiType. 158 For more information and some examples see the description @ref MultiTypeExamples "here". 159 160 @see MultiType.h 133 161 */ 134 162 class _UtilExport MultiType … … 153 181 virtual bool assimilate(const MultiType& other) = 0; 154 182 155 / ** @brief Returns the type of the current value. */183 /// Returns the type of the current value. 156 184 const MT_Type::Value& getType() const { return this->type_; } 157 185 158 / ** @brief Checks whether the value is a default one. */186 /// Checks whether the value is a default one. 159 187 bool hasDefaultValue() const { return this->bHasDefaultValue_; } 160 188 … … 237 265 virtual uint8_t getSize() const=0; 238 266 239 MT_Type::Value type_; // !< The type of the current value240 bool bHasDefaultValue_; // !< True if the last conversion wasn't successful267 MT_Type::Value type_; ///< The type of the current value 268 bool bHasDefaultValue_; ///< True if the last conversion wasn't successful 241 269 }; 242 270 243 271 public: 244 inline MultiType() : value_(0) {} / ** @brief Default constructor: Assigns no value and no type. The type will be determined by the first assignment of a value. */245 inline MultiType(const char& value) : value_(0) { this->assignValue(value); } / ** @brief Constructor: Assigns the given value and sets the type. */246 inline MultiType(const unsigned char& value) : value_(0) { this->assignValue(value); } / ** @brief Constructor: Assigns the given value and sets the type. */247 inline MultiType(const short& value) : value_(0) { this->assignValue(value); } / ** @brief Constructor: Assigns the given value and sets the type. */248 inline MultiType(const unsigned short& value) : value_(0) { this->assignValue(value); } / ** @brief Constructor: Assigns the given value and sets the type. */249 inline MultiType(const int& value) : value_(0) { this->assignValue(value); } / ** @brief Constructor: Assigns the given value and sets the type. */250 inline MultiType(const unsigned int& value) : value_(0) { this->assignValue(value); } / ** @brief Constructor: Assigns the given value and sets the type. */251 inline MultiType(const long& value) : value_(0) { this->assignValue(value); } / ** @brief Constructor: Assigns the given value and sets the type. */252 inline MultiType(const unsigned long& value) : value_(0) { this->assignValue(value); } / ** @brief Constructor: Assigns the given value and sets the type. */253 inline MultiType(const long long& value) : value_(0) { this->assignValue(value); } / ** @brief Constructor: Assigns the given value and sets the type. */254 inline MultiType(const unsigned long long& value) : value_(0) { this->assignValue(value); } / ** @brief Constructor: Assigns the given value and sets the type. */255 inline MultiType(const float& value) : value_(0) { this->assignValue(value); } / ** @brief Constructor: Assigns the given value and sets the type. */256 inline MultiType(const double& value) : value_(0) { this->assignValue(value); } / ** @brief Constructor: Assigns the given value and sets the type. */257 inline MultiType(const long double& value) : value_(0) { this->assignValue(value); } / ** @brief Constructor: Assigns the given value and sets the type. */258 inline MultiType(const bool& value) : value_(0) { this->assignValue(value); } / ** @brief Constructor: Assigns the given value and sets the type. */259 inline MultiType( void* const& value) : value_(0) { this->assignValue(value); } / ** @brief Constructor: Assigns the given value and sets the type. */260 inline MultiType(const std::string& value) : value_(0) { this->assignValue(value); } / ** @brief Constructor: Assigns the given value and sets the type. */261 inline MultiType(const orxonox::Vector2& value) : value_(0) { this->assignValue(value); } / ** @brief Constructor: Assigns the given value and sets the type. */262 inline MultiType(const orxonox::Vector3& value) : value_(0) { this->assignValue(value); } / ** @brief Constructor: Assigns the given value and sets the type. */263 inline MultiType(const orxonox::Vector4& value) : value_(0) { this->assignValue(value); } / ** @brief Constructor: Assigns the given value and sets the type. */264 inline MultiType(const orxonox::ColourValue& value) : value_(0) { this->assignValue(value); } / ** @brief Constructor: Assigns the given value and sets the type. */265 inline MultiType(const orxonox::Quaternion& value) : value_(0) { this->assignValue(value); } / ** @brief Constructor: Assigns the given value and sets the type. */266 inline MultiType(const orxonox::Radian& value) : value_(0) { this->assignValue(value); } / ** @brief Constructor: Assigns the given value and sets the type. */267 inline MultiType(const orxonox::Degree& value) : value_(0) { this->assignValue(value); } / ** @brief Constructor: Assigns the given value and sets the type. */268 inline MultiType(const orxonox::mbool& value) : value_(0) { this->assignValue((bool)value); } / ** @brief Constructor: Assigns the given mbool and converts it to bool. */269 inline MultiType(const char* value) : value_(0) { this->setValue(std::string(value)); } / ** @brief Constructor: Converts the char array to a std::string, assigns the value and sets the type. */270 inline MultiType(const MultiType& other) : value_(0) { this->setValue(other); } / ** @brief Copyconstructor: Assigns value and type of the other MultiType. */271 inline MultiType(MT_Type::Value type) : value_(0) { this->setType(type); } / ** @brief Constructor: Sets the type, the next assignment will determine the value. */272 273 / ** @brief Destructor: Deletes the MT_Value. */272 inline MultiType() : value_(0) {} ///< Default constructor: Assigns no value and no type. The type will be determined by the first assignment of a value. 273 inline MultiType(const char& value) : value_(0) { this->assignValue(value); } ///< Constructor: Assigns the given value and sets the type. 274 inline MultiType(const unsigned char& value) : value_(0) { this->assignValue(value); } ///< Constructor: Assigns the given value and sets the type. 275 inline MultiType(const short& value) : value_(0) { this->assignValue(value); } ///< Constructor: Assigns the given value and sets the type. 276 inline MultiType(const unsigned short& value) : value_(0) { this->assignValue(value); } ///< Constructor: Assigns the given value and sets the type. 277 inline MultiType(const int& value) : value_(0) { this->assignValue(value); } ///< Constructor: Assigns the given value and sets the type. 278 inline MultiType(const unsigned int& value) : value_(0) { this->assignValue(value); } ///< Constructor: Assigns the given value and sets the type. 279 inline MultiType(const long& value) : value_(0) { this->assignValue(value); } ///< Constructor: Assigns the given value and sets the type. 280 inline MultiType(const unsigned long& value) : value_(0) { this->assignValue(value); } ///< Constructor: Assigns the given value and sets the type. 281 inline MultiType(const long long& value) : value_(0) { this->assignValue(value); } ///< Constructor: Assigns the given value and sets the type. 282 inline MultiType(const unsigned long long& value) : value_(0) { this->assignValue(value); } ///< Constructor: Assigns the given value and sets the type. 283 inline MultiType(const float& value) : value_(0) { this->assignValue(value); } ///< Constructor: Assigns the given value and sets the type. 284 inline MultiType(const double& value) : value_(0) { this->assignValue(value); } ///< Constructor: Assigns the given value and sets the type. 285 inline MultiType(const long double& value) : value_(0) { this->assignValue(value); } ///< Constructor: Assigns the given value and sets the type. 286 inline MultiType(const bool& value) : value_(0) { this->assignValue(value); } ///< Constructor: Assigns the given value and sets the type. 287 inline MultiType( void* const& value) : value_(0) { this->assignValue(value); } ///< Constructor: Assigns the given value and sets the type. 288 inline MultiType(const std::string& value) : value_(0) { this->assignValue(value); } ///< Constructor: Assigns the given value and sets the type. 289 inline MultiType(const orxonox::Vector2& value) : value_(0) { this->assignValue(value); } ///< Constructor: Assigns the given value and sets the type. 290 inline MultiType(const orxonox::Vector3& value) : value_(0) { this->assignValue(value); } ///< Constructor: Assigns the given value and sets the type. 291 inline MultiType(const orxonox::Vector4& value) : value_(0) { this->assignValue(value); } ///< Constructor: Assigns the given value and sets the type. 292 inline MultiType(const orxonox::ColourValue& value) : value_(0) { this->assignValue(value); } ///< Constructor: Assigns the given value and sets the type. 293 inline MultiType(const orxonox::Quaternion& value) : value_(0) { this->assignValue(value); } ///< Constructor: Assigns the given value and sets the type. 294 inline MultiType(const orxonox::Radian& value) : value_(0) { this->assignValue(value); } ///< Constructor: Assigns the given value and sets the type. 295 inline MultiType(const orxonox::Degree& value) : value_(0) { this->assignValue(value); } ///< Constructor: Assigns the given value and sets the type. 296 inline MultiType(const orxonox::mbool& value) : value_(0) { this->assignValue((bool)value); } ///< Constructor: Assigns the given mbool and converts it to bool. 297 inline MultiType(const char* value) : value_(0) { this->setValue(std::string(value)); } ///< Constructor: Converts the char array to a std::string, assigns the value and sets the type. 298 inline MultiType(const MultiType& other) : value_(0) { this->setValue(other); } ///< Copyconstructor: Assigns value and type of the other MultiType. 299 inline MultiType(MT_Type::Value type) : value_(0) { this->setType(type); } ///< Constructor: Sets the type, the next assignment will determine the value. 300 301 /// Destructor: Deletes the MT_Value. 274 302 inline ~MultiType() { if (this->value_) { delete this->value_; } } 275 303 276 template <typename V> inline MultiType& operator=(const V& value) { this->setValue(value); return (*this); } / ** @brief Assigns a new value. The value will be converted to the current type of the MultiType. */277 template <typename V> inline MultiType& operator=(V* value) { this->setValue(value); return (*this); } / ** @brief Assigns a pointer. */278 inline MultiType& operator=(const MultiType& other) { this->setValue(other); return (*this); } / ** @brief Assigns the value of the other MultiType and converts it to the current type of the MultiType. */279 inline MultiType& operator=(MT_Type::Value type) { this->setType(type); return (*this); } / ** @brief Resets the value and changes the type. */304 template <typename V> inline MultiType& operator=(const V& value) { this->setValue(value); return (*this); } ///< Assigns a new value. The value will be converted to the current type of the MultiType. 305 template <typename V> inline MultiType& operator=(V* value) { this->setValue(value); return (*this); } ///< Assigns a pointer. 306 inline MultiType& operator=(const MultiType& other) { this->setValue(other); return (*this); } ///< Assigns the value of the other MultiType and converts it to the current type of the MultiType. 307 inline MultiType& operator=(MT_Type::Value type) { this->setType(type); return (*this); } ///< Resets the value and changes the type. 280 308 281 309 inline bool setValue(const char& value); … … 303 331 inline bool setValue(const orxonox::Degree& value); 304 332 inline bool setValue(const char* value); 305 / ** @brief Assigns a pointer. */333 /// Assigns a pointer. 306 334 template <typename V> inline bool setValue(V* value) 307 335 { … … 311 339 return this->assignValue (static_cast<void*>(const_cast<typename Loki::TypeTraits<V>::UnqualifiedType*>(value))); 312 340 } 313 / ** @brief Assigns the value of the other MultiType and converts it to the current type. */341 /// Assigns the value of the other MultiType and converts it to the current type. 314 342 bool setValue(const MultiType& other) { if (this->value_) { return this->value_->assimilate(other); } else { if (other.value_) { this->value_ = other.value_->clone(); } return true; } } 315 / ** @brief Changes the type to T and assigns the new value (which might be of another type than T - it gets converted). */343 /// Changes the type to T and assigns the new value (which might be of another type than T - it gets converted). 316 344 template <typename T, typename V> inline bool setValue(const V& value) { this->setType<T>(); return this->setValue(value); } 317 345 318 346 319 / ** @brief Copies the other MultiType by assigning value and type. */347 /// Copies the other MultiType by assigning value and type. 320 348 inline void copy(const MultiType& other) { if (this == &other) { return; } if (this->value_) { delete this->value_; } this->value_ = (other.value_) ? other.value_->clone() : 0; } 321 349 322 template <typename T> inline bool convert() { return this->setValue<T>((typename Loki::TypeTraits<T>::UnqualifiedReferredType)(*this)); } /** @brief Converts the current value to type T. */ 323 inline bool convert(const MultiType& other) { return this->convert(other.getType()); } /** @brief Converts the current value to the type of the other MultiType. */ 350 /// Converts the current value to type T. 351 template <typename T> inline bool convert() { return this->setValue<T>((typename Loki::TypeTraits<T>::UnqualifiedReferredType)(*this)); } 352 /// Converts the current value to the type of the other MultiType. 353 inline bool convert(const MultiType& other) { return this->convert(other.getType()); } 324 354 bool convert(MT_Type::Value type); 325 355 326 / ** @brief Current content gets deleted. New type is MT_Type::Null */356 /// Current content gets deleted. New type is MT_Type::Null 327 357 inline void reset() { if (this->value_) delete this->value_; this->value_ = 0; } 328 / ** @brief Current content gets overridden with default zero value */358 /// Current content gets overridden with default zero value 329 359 inline void resetValue() { if (this->value_) this->value_->reset(); } 330 360 331 template <typename T> inline void setType() { this->assignValue(typename Loki::TypeTraits<T>::UnqualifiedReferredType()); } /** @brief Resets the value and changes the internal type to T. */ 332 inline void setType(const MultiType& other) { this->setType(other.getType()); } /** @brief Resets the value and changes the internal type to the type of the other MultiType. */ 333 inline void setType(MT_Type::Value type) { this->reset(); this->convert(type); this->resetValue(); } /** @brief Resets the value and changes the internal type to the given type. */ 334 335 /** @brief Returns the current type. */ 361 /// Resets the value and changes the internal type to T. 362 template <typename T> inline void setType() { this->assignValue(typename Loki::TypeTraits<T>::UnqualifiedReferredType()); } 363 /// Resets the value and changes the internal type to the type of the other MultiType. 364 inline void setType(const MultiType& other) { this->setType(other.getType()); } 365 /// Resets the value and changes the internal type to the given type. 366 inline void setType(MT_Type::Value type) { this->reset(); this->convert(type); this->resetValue(); } 367 368 /// Returns the current type. 336 369 inline MT_Type::Value getType() const { return (this->value_) ? this->value_->type_ : MT_Type::Null; } 337 / ** @brief Returns true if the current type equals the given type. */370 /// Returns true if the current type equals the given type. 338 371 inline bool isType(MT_Type::Value type) const { return (this->value_) ? (this->value_->type_ == type) : (type == MT_Type::Null); } 339 / ** @brief Returns true if the current type is T. */372 /// Returns true if the current type is T. 340 373 template <typename T> inline bool isType() const { return false; } // Only works for specialized values - see below 341 374 std::string getTypename() const; 342 375 343 / ** @brief Saves the value of the MT to a bytestream (pointed at by mem) and increases mem pointer by size of MT */376 /// Saves the value of the MT to a bytestream (pointed at by mem) and increases mem pointer by size of MT 344 377 inline void exportData(uint8_t*& mem) const { assert(sizeof(MT_Type::Value)<=8); *static_cast<uint8_t*>(mem) = this->getType(); mem+=sizeof(uint8_t); this->value_->exportData(mem); } 345 / ** @brief Loads the value of the MT from a bytestream (pointed at by mem) and increases mem pointer by size of MT */378 /// Loads the value of the MT from a bytestream (pointed at by mem) and increases mem pointer by size of MT 346 379 inline void importData(uint8_t*& mem) { assert(sizeof(MT_Type::Value)<=8); this->setType(static_cast<MT_Type::Value>(*static_cast<uint8_t*>(mem))); mem+=sizeof(uint8_t); this->value_->importData(mem); } 347 / ** @brief Saves the value of the MT to a bytestream and increases pointer to bytestream by size of MT */380 /// Saves the value of the MT to a bytestream and increases pointer to bytestream by size of MT 348 381 inline uint8_t*& operator << (uint8_t*& mem) { importData(mem); return mem; } 349 / ** @brief Loads the value of the MT to a bytestream and increases pointer to bytestream by size of MT */382 /// Loads the value of the MT to a bytestream and increases pointer to bytestream by size of MT 350 383 inline void operator >> (uint8_t*& mem) const { exportData(mem); } 351 384 inline uint32_t getNetworkSize() const { assert(this->value_); return this->value_->getSize() + sizeof(uint8_t); } 352 385 353 / ** @brief Checks whether the value is a default one. */386 /// Checks whether the value is a default one (assigned after a failed conversion) 354 387 bool hasDefaultValue() const { return this->value_->hasDefaultValue(); } 355 388 356 / ** @brief Checks if the MT contains no value. */389 /// Checks if the MT contains no value. 357 390 bool null() const { return (!this->value_); } 358 391 … … 380 413 operator orxonox::Radian() const; 381 414 operator orxonox::Degree() const; 382 / ** @brief Returns the current value, converted to a T* pointer. */415 /// Returns the current value, converted to a T* pointer. 383 416 template <class T> operator T*() const { return (static_cast<T*>(this->operator void*())); } 384 417 385 inline bool getValue(char* value) const { if (this->value_) { return this->value_->getValue(value); } return false; } / ** @brief Assigns the value to the given pointer. The value gets converted if the types don't match. */386 inline bool getValue(unsigned char* value) const { if (this->value_) { return this->value_->getValue(value); } return false; } / ** @brief Assigns the value to the given pointer. The value gets converted if the types don't match. */387 inline bool getValue(short* value) const { if (this->value_) { return this->value_->getValue(value); } return false; } / ** @brief Assigns the value to the given pointer. The value gets converted if the types don't match. */388 inline bool getValue(unsigned short* value) const { if (this->value_) { return this->value_->getValue(value); } return false; } / ** @brief Assigns the value to the given pointer. The value gets converted if the types don't match. */389 inline bool getValue(int* value) const { if (this->value_) { return this->value_->getValue(value); } return false; } / ** @brief Assigns the value to the given pointer. The value gets converted if the types don't match. */390 inline bool getValue(unsigned int* value) const { if (this->value_) { return this->value_->getValue(value); } return false; } / ** @brief Assigns the value to the given pointer. The value gets converted if the types don't match. */391 inline bool getValue(long* value) const { if (this->value_) { return this->value_->getValue(value); } return false; } / ** @brief Assigns the value to the given pointer. The value gets converted if the types don't match. */392 inline bool getValue(unsigned long* value) const { if (this->value_) { return this->value_->getValue(value); } return false; } / ** @brief Assigns the value to the given pointer. The value gets converted if the types don't match. */393 inline bool getValue(long long* value) const { if (this->value_) { return this->value_->getValue(value); } return false; } / ** @brief Assigns the value to the given pointer. The value gets converted if the types don't match. */394 inline bool getValue(unsigned long long* value) const { if (this->value_) { return this->value_->getValue(value); } return false; } / ** @brief Assigns the value to the given pointer. The value gets converted if the types don't match. */395 inline bool getValue(float* value) const { if (this->value_) { return this->value_->getValue(value); } return false; } / ** @brief Assigns the value to the given pointer. The value gets converted if the types don't match. */396 inline bool getValue(double* value) const { if (this->value_) { return this->value_->getValue(value); } return false; } / ** @brief Assigns the value to the given pointer. The value gets converted if the types don't match. */397 inline bool getValue(long double* value) const { if (this->value_) { return this->value_->getValue(value); } return false; } / ** @brief Assigns the value to the given pointer. The value gets converted if the types don't match. */398 inline bool getValue(bool* value) const { if (this->value_) { return this->value_->getValue(value); } return false; } / ** @brief Assigns the value to the given pointer. The value gets converted if the types don't match. */399 inline bool getValue(void** value) const { if (this->value_) { return this->value_->getValue(value); } return false; } / ** @brief Assigns the value to the given pointer. The value gets converted if the types don't match. */400 inline bool getValue(std::string* value) const { if (this->value_) { return this->value_->getValue(value); } return false; } / ** @brief Assigns the value to the given pointer. The value gets converted if the types don't match. */401 inline bool getValue(orxonox::Vector2* value) const { if (this->value_) { return this->value_->getValue(value); } return false; } / ** @brief Assigns the value to the given pointer. The value gets converted if the types don't match. */402 inline bool getValue(orxonox::Vector3* value) const { if (this->value_) { return this->value_->getValue(value); } return false; } / ** @brief Assigns the value to the given pointer. The value gets converted if the types don't match. */403 inline bool getValue(orxonox::Vector4* value) const { if (this->value_) { return this->value_->getValue(value); } return false; } / ** @brief Assigns the value to the given pointer. The value gets converted if the types don't match. */404 inline bool getValue(orxonox::ColourValue* value) const { if (this->value_) { return this->value_->getValue(value); } return false; } / ** @brief Assigns the value to the given pointer. The value gets converted if the types don't match. */405 inline bool getValue(orxonox::Quaternion* value) const { if (this->value_) { return this->value_->getValue(value); } return false; } / ** @brief Assigns the value to the given pointer. The value gets converted if the types don't match. */406 inline bool getValue(orxonox::Radian* value) const { if (this->value_) { return this->value_->getValue(value); } return false; } / ** @brief Assigns the value to the given pointer. The value gets converted if the types don't match. */407 inline bool getValue(orxonox::Degree* value) const { if (this->value_) { return this->value_->getValue(value); } return false; } / ** @brief Assigns the value to the given pointer. The value gets converted if the types don't match. */408 409 inline char getChar() const { return this->operator char(); } / ** @brief Returns the current value, converted to the requested type. */410 inline unsigned char getUnsignedChar() const { return this->operator unsigned char(); } / ** @brief Returns the current value, converted to the requested type. */411 inline short getShort() const { return this->operator short(); } / ** @brief Returns the current value, converted to the requested type. */412 inline unsigned short getUnsignedShort() const { return this->operator unsigned short(); } / ** @brief Returns the current value, converted to the requested type. */413 inline int getInt() const { return this->operator int(); } / ** @brief Returns the current value, converted to the requested type. */414 inline unsigned int getUnsignedInt() const { return this->operator unsigned int(); } / ** @brief Returns the current value, converted to the requested type. */415 inline long getLong() const { return this->operator long(); } / ** @brief Returns the current value, converted to the requested type. */416 inline unsigned long getUnsignedLong() const { return this->operator unsigned long(); } / ** @brief Returns the current value, converted to the requested type. */417 inline long long getLongLong() const { return this->operator long long(); } / ** @brief Returns the current value, converted to the requested type. */418 inline unsigned long long getUnsignedLongLong() const { return this->operator unsigned long long(); } / ** @brief Returns the current value, converted to the requested type. */419 inline float getFloat() const { return this->operator float(); } / ** @brief Returns the current value, converted to the requested type. */420 inline double getDouble() const { return this->operator double(); } / ** @brief Returns the current value, converted to the requested type. */421 inline long double getLongDouble() const { return this->operator long double(); } / ** @brief Returns the current value, converted to the requested type. */422 inline bool getBool() const { return this->operator bool(); } / ** @brief Returns the current value, converted to the requested type. */423 inline void* getVoid() const { return this->operator void*(); } / ** @brief Returns the current value, converted to the requested type. */424 inline std::string getString() const { return this->operator std::string(); } / ** @brief Returns the current value, converted to the requested type. */425 inline orxonox::Vector2 getVector2() const { return this->operator orxonox::Vector2(); } / ** @brief Returns the current value, converted to the requested type. */426 inline orxonox::Vector3 getVector3() const { return this->operator orxonox::Vector3(); } / ** @brief Returns the current value, converted to the requested type. */427 inline orxonox::Vector4 getVector4() const { return this->operator orxonox::Vector4(); } / ** @brief Returns the current value, converted to the requested type. */428 inline orxonox::ColourValue getColourValue() const { return this->operator orxonox::ColourValue(); } / ** @brief Returns the current value, converted to the requested type. */429 inline orxonox::Quaternion getQuaternion() const { return this->operator orxonox::Quaternion(); } / ** @brief Returns the current value, converted to the requested type. */430 inline orxonox::Radian getRadian() const { return this->operator orxonox::Radian(); } / ** @brief Returns the current value, converted to the requested type. */431 inline orxonox::Degree getDegree() const { return this->operator orxonox::Degree(); } / ** @brief Returns the current value, converted to the requested type. */432 template <typename T> inline T* getPointer() const { return static_cast<T*>(this->getVoid()); } / ** @brief Returns the current value, converted to a T* pointer. */418 inline bool getValue(char* value) const { if (this->value_) { return this->value_->getValue(value); } return false; } ///< Assigns the value to the given pointer. The value gets converted if the types don't match. 419 inline bool getValue(unsigned char* value) const { if (this->value_) { return this->value_->getValue(value); } return false; } ///< Assigns the value to the given pointer. The value gets converted if the types don't match. 420 inline bool getValue(short* value) const { if (this->value_) { return this->value_->getValue(value); } return false; } ///< Assigns the value to the given pointer. The value gets converted if the types don't match. 421 inline bool getValue(unsigned short* value) const { if (this->value_) { return this->value_->getValue(value); } return false; } ///< Assigns the value to the given pointer. The value gets converted if the types don't match. 422 inline bool getValue(int* value) const { if (this->value_) { return this->value_->getValue(value); } return false; } ///< Assigns the value to the given pointer. The value gets converted if the types don't match. 423 inline bool getValue(unsigned int* value) const { if (this->value_) { return this->value_->getValue(value); } return false; } ///< Assigns the value to the given pointer. The value gets converted if the types don't match. 424 inline bool getValue(long* value) const { if (this->value_) { return this->value_->getValue(value); } return false; } ///< Assigns the value to the given pointer. The value gets converted if the types don't match. 425 inline bool getValue(unsigned long* value) const { if (this->value_) { return this->value_->getValue(value); } return false; } ///< Assigns the value to the given pointer. The value gets converted if the types don't match. 426 inline bool getValue(long long* value) const { if (this->value_) { return this->value_->getValue(value); } return false; } ///< Assigns the value to the given pointer. The value gets converted if the types don't match. 427 inline bool getValue(unsigned long long* value) const { if (this->value_) { return this->value_->getValue(value); } return false; } ///< Assigns the value to the given pointer. The value gets converted if the types don't match. 428 inline bool getValue(float* value) const { if (this->value_) { return this->value_->getValue(value); } return false; } ///< Assigns the value to the given pointer. The value gets converted if the types don't match. 429 inline bool getValue(double* value) const { if (this->value_) { return this->value_->getValue(value); } return false; } ///< Assigns the value to the given pointer. The value gets converted if the types don't match. 430 inline bool getValue(long double* value) const { if (this->value_) { return this->value_->getValue(value); } return false; } ///< Assigns the value to the given pointer. The value gets converted if the types don't match. 431 inline bool getValue(bool* value) const { if (this->value_) { return this->value_->getValue(value); } return false; } ///< Assigns the value to the given pointer. The value gets converted if the types don't match. 432 inline bool getValue(void** value) const { if (this->value_) { return this->value_->getValue(value); } return false; } ///< Assigns the value to the given pointer. The value gets converted if the types don't match. 433 inline bool getValue(std::string* value) const { if (this->value_) { return this->value_->getValue(value); } return false; } ///< Assigns the value to the given pointer. The value gets converted if the types don't match. 434 inline bool getValue(orxonox::Vector2* value) const { if (this->value_) { return this->value_->getValue(value); } return false; } ///< Assigns the value to the given pointer. The value gets converted if the types don't match. 435 inline bool getValue(orxonox::Vector3* value) const { if (this->value_) { return this->value_->getValue(value); } return false; } ///< Assigns the value to the given pointer. The value gets converted if the types don't match. 436 inline bool getValue(orxonox::Vector4* value) const { if (this->value_) { return this->value_->getValue(value); } return false; } ///< Assigns the value to the given pointer. The value gets converted if the types don't match. 437 inline bool getValue(orxonox::ColourValue* value) const { if (this->value_) { return this->value_->getValue(value); } return false; } ///< Assigns the value to the given pointer. The value gets converted if the types don't match. 438 inline bool getValue(orxonox::Quaternion* value) const { if (this->value_) { return this->value_->getValue(value); } return false; } ///< Assigns the value to the given pointer. The value gets converted if the types don't match. 439 inline bool getValue(orxonox::Radian* value) const { if (this->value_) { return this->value_->getValue(value); } return false; } ///< Assigns the value to the given pointer. The value gets converted if the types don't match. 440 inline bool getValue(orxonox::Degree* value) const { if (this->value_) { return this->value_->getValue(value); } return false; } ///< Assigns the value to the given pointer. The value gets converted if the types don't match. 441 442 inline char getChar() const { return this->operator char(); } ///< Returns the current value, converted to the requested type. 443 inline unsigned char getUnsignedChar() const { return this->operator unsigned char(); } ///< Returns the current value, converted to the requested type. 444 inline short getShort() const { return this->operator short(); } ///< Returns the current value, converted to the requested type. 445 inline unsigned short getUnsignedShort() const { return this->operator unsigned short(); } ///< Returns the current value, converted to the requested type. 446 inline int getInt() const { return this->operator int(); } ///< Returns the current value, converted to the requested type. 447 inline unsigned int getUnsignedInt() const { return this->operator unsigned int(); } ///< Returns the current value, converted to the requested type. 448 inline long getLong() const { return this->operator long(); } ///< Returns the current value, converted to the requested type. 449 inline unsigned long getUnsignedLong() const { return this->operator unsigned long(); } ///< Returns the current value, converted to the requested type. 450 inline long long getLongLong() const { return this->operator long long(); } ///< Returns the current value, converted to the requested type. 451 inline unsigned long long getUnsignedLongLong() const { return this->operator unsigned long long(); } ///< Returns the current value, converted to the requested type. 452 inline float getFloat() const { return this->operator float(); } ///< Returns the current value, converted to the requested type. 453 inline double getDouble() const { return this->operator double(); } ///< Returns the current value, converted to the requested type. 454 inline long double getLongDouble() const { return this->operator long double(); } ///< Returns the current value, converted to the requested type. 455 inline bool getBool() const { return this->operator bool(); } ///< Returns the current value, converted to the requested type. 456 inline void* getVoid() const { return this->operator void*(); } ///< Returns the current value, converted to the requested type. 457 inline std::string getString() const { return this->operator std::string(); } ///< Returns the current value, converted to the requested type. 458 inline orxonox::Vector2 getVector2() const { return this->operator orxonox::Vector2(); } ///< Returns the current value, converted to the requested type. 459 inline orxonox::Vector3 getVector3() const { return this->operator orxonox::Vector3(); } ///< Returns the current value, converted to the requested type. 460 inline orxonox::Vector4 getVector4() const { return this->operator orxonox::Vector4(); } ///< Returns the current value, converted to the requested type. 461 inline orxonox::ColourValue getColourValue() const { return this->operator orxonox::ColourValue(); } ///< Returns the current value, converted to the requested type. 462 inline orxonox::Quaternion getQuaternion() const { return this->operator orxonox::Quaternion(); } ///< Returns the current value, converted to the requested type. 463 inline orxonox::Radian getRadian() const { return this->operator orxonox::Radian(); } ///< Returns the current value, converted to the requested type. 464 inline orxonox::Degree getDegree() const { return this->operator orxonox::Degree(); } ///< Returns the current value, converted to the requested type. 465 template <typename T> inline T* getPointer() const { return static_cast<T*>(this->getVoid()); } ///< Returns the current value, converted to a T* pointer. 433 466 434 467 private: 435 inline bool assignValue(const char& value) { if (this->value_ && this->value_->type_ == MT_Type::Char) { return this->value_->setValue(value); } else { this->changeValueContainer<char>(value); return true; } } / ** @brief Assigns a new value by changing type and creating a new container. */436 inline bool assignValue(const unsigned char& value) { if (this->value_ && this->value_->type_ == MT_Type::UnsignedChar) { return this->value_->setValue(value); } else { this->changeValueContainer<unsigned char>(value); return true; } } / ** @brief Assigns a new value by changing type and creating a new container. */437 inline bool assignValue(const short& value) { if (this->value_ && this->value_->type_ == MT_Type::Short) { return this->value_->setValue(value); } else { this->changeValueContainer<short>(value); return true; } } / ** @brief Assigns a new value by changing type and creating a new container. */438 inline bool assignValue(const unsigned short& value) { if (this->value_ && this->value_->type_ == MT_Type::UnsignedShort) { return this->value_->setValue(value); } else { this->changeValueContainer<unsigned short>(value); return true; } } / ** @brief Assigns a new value by changing type and creating a new container. */439 inline bool assignValue(const int& value) { if (this->value_ && this->value_->type_ == MT_Type::Int) { return this->value_->setValue(value); } else { this->changeValueContainer<int>(value); return true; } } / ** @brief Assigns a new value by changing type and creating a new container. */440 inline bool assignValue(const unsigned int& value) { if (this->value_ && this->value_->type_ == MT_Type::UnsignedInt) { return this->value_->setValue(value); } else { this->changeValueContainer<unsigned int>(value); return true; } } / ** @brief Assigns a new value by changing type and creating a new container. */441 inline bool assignValue(const long& value) { if (this->value_ && this->value_->type_ == MT_Type::Long) { return this->value_->setValue(value); } else { this->changeValueContainer<long>(value); return true; } } / ** @brief Assigns a new value by changing type and creating a new container. */442 inline bool assignValue(const unsigned long& value) { if (this->value_ && this->value_->type_ == MT_Type::UnsignedLong) { return this->value_->setValue(value); } else { this->changeValueContainer<unsigned long>(value); return true; } } / ** @brief Assigns a new value by changing type and creating a new container. */443 inline bool assignValue(const long long& value) { if (this->value_ && this->value_->type_ == MT_Type::LongLong) { return this->value_->setValue(value); } else { this->changeValueContainer<long long>(value); return true; } } / ** @brief Assigns a new value by changing type and creating a new container. */444 inline bool assignValue(const unsigned long long& value) { if (this->value_ && this->value_->type_ == MT_Type::UnsignedLongLong) { return this->value_->setValue(value); } else { this->changeValueContainer<unsigned long long>(value); return true; } } / ** @brief Assigns a new value by changing type and creating a new container. */445 inline bool assignValue(const float& value) { if (this->value_ && this->value_->type_ == MT_Type::Float) { return this->value_->setValue(value); } else { this->changeValueContainer<float>(value); return true; } } / ** @brief Assigns a new value by changing type and creating a new container. */446 inline bool assignValue(const double& value) { if (this->value_ && this->value_->type_ == MT_Type::Double) { return this->value_->setValue(value); } else { this->changeValueContainer<double>(value); return true; } } / ** @brief Assigns a new value by changing type and creating a new container. */447 inline bool assignValue(const long double& value) { if (this->value_ && this->value_->type_ == MT_Type::LongDouble) { return this->value_->setValue(value); } else { this->changeValueContainer<long double>(value); return true; } } / ** @brief Assigns a new value by changing type and creating a new container. */448 inline bool assignValue(const bool& value) { if (this->value_ && this->value_->type_ == MT_Type::Bool) { return this->value_->setValue(value); } else { this->changeValueContainer<bool>(value); return true; } } / ** @brief Assigns a new value by changing type and creating a new container. */449 inline bool assignValue( void* const& value) { if (this->value_ && this->value_->type_ == MT_Type::VoidPointer) { return this->value_->setValue(value); } else { this->changeValueContainer<void*>(value); return true; } } / ** @brief Assigns a new value by changing type and creating a new container. */450 inline bool assignValue(const std::string& value) { if (this->value_ && this->value_->type_ == MT_Type::String) { return this->value_->setValue(value); } else { this->changeValueContainer<std::string>(value); return true; } } / ** @brief Assigns a new value by changing type and creating a new container. */451 inline bool assignValue(const orxonox::Vector2& value) { if (this->value_ && this->value_->type_ == MT_Type::Vector2) { return this->value_->setValue(value); } else { this->changeValueContainer<orxonox::Vector2>(value); return true; } } / ** @brief Assigns a new value by changing type and creating a new container. */452 inline bool assignValue(const orxonox::Vector3& value) { if (this->value_ && this->value_->type_ == MT_Type::Vector3) { return this->value_->setValue(value); } else { this->changeValueContainer<orxonox::Vector3>(value); return true; } } / ** @brief Assigns a new value by changing type and creating a new container. */453 inline bool assignValue(const orxonox::Vector4& value) { if (this->value_ && this->value_->type_ == MT_Type::Vector4) { return this->value_->setValue(value); } else { this->changeValueContainer<orxonox::Vector4>(value); return true; } } / ** @brief Assigns a new value by changing type and creating a new container. */454 inline bool assignValue(const orxonox::ColourValue& value) { if (this->value_ && this->value_->type_ == MT_Type::ColourValue) { return this->value_->setValue(value); } else { this->changeValueContainer<orxonox::ColourValue>(value); return true; } } / ** @brief Assigns a new value by changing type and creating a new container. */455 inline bool assignValue(const orxonox::Quaternion& value) { if (this->value_ && this->value_->type_ == MT_Type::Quaternion) { return this->value_->setValue(value); } else { this->changeValueContainer<orxonox::Quaternion>(value); return true; } } / ** @brief Assigns a new value by changing type and creating a new container. */456 inline bool assignValue(const orxonox::Radian& value) { if (this->value_ && this->value_->type_ == MT_Type::Radian) { return this->value_->setValue(value); } else { this->changeValueContainer<orxonox::Radian>(value); return true; } } / ** @brief Assigns a new value by changing type and creating a new container. */457 inline bool assignValue(const orxonox::Degree& value) { if (this->value_ && this->value_->type_ == MT_Type::Degree) { return this->value_->setValue(value); } else { this->changeValueContainer<orxonox::Degree>(value); return true; } } / ** @brief Assigns a new value by changing type and creating a new container. */458 459 / ** @brief Changes the value container. */468 inline bool assignValue(const char& value) { if (this->value_ && this->value_->type_ == MT_Type::Char) { return this->value_->setValue(value); } else { this->changeValueContainer<char>(value); return true; } } ///< Assigns a new value by changing type and creating a new container. 469 inline bool assignValue(const unsigned char& value) { if (this->value_ && this->value_->type_ == MT_Type::UnsignedChar) { return this->value_->setValue(value); } else { this->changeValueContainer<unsigned char>(value); return true; } } ///< Assigns a new value by changing type and creating a new container. 470 inline bool assignValue(const short& value) { if (this->value_ && this->value_->type_ == MT_Type::Short) { return this->value_->setValue(value); } else { this->changeValueContainer<short>(value); return true; } } ///< Assigns a new value by changing type and creating a new container. 471 inline bool assignValue(const unsigned short& value) { if (this->value_ && this->value_->type_ == MT_Type::UnsignedShort) { return this->value_->setValue(value); } else { this->changeValueContainer<unsigned short>(value); return true; } } ///< Assigns a new value by changing type and creating a new container. 472 inline bool assignValue(const int& value) { if (this->value_ && this->value_->type_ == MT_Type::Int) { return this->value_->setValue(value); } else { this->changeValueContainer<int>(value); return true; } } ///< Assigns a new value by changing type and creating a new container. 473 inline bool assignValue(const unsigned int& value) { if (this->value_ && this->value_->type_ == MT_Type::UnsignedInt) { return this->value_->setValue(value); } else { this->changeValueContainer<unsigned int>(value); return true; } } ///< Assigns a new value by changing type and creating a new container. 474 inline bool assignValue(const long& value) { if (this->value_ && this->value_->type_ == MT_Type::Long) { return this->value_->setValue(value); } else { this->changeValueContainer<long>(value); return true; } } ///< Assigns a new value by changing type and creating a new container. 475 inline bool assignValue(const unsigned long& value) { if (this->value_ && this->value_->type_ == MT_Type::UnsignedLong) { return this->value_->setValue(value); } else { this->changeValueContainer<unsigned long>(value); return true; } } ///< Assigns a new value by changing type and creating a new container. 476 inline bool assignValue(const long long& value) { if (this->value_ && this->value_->type_ == MT_Type::LongLong) { return this->value_->setValue(value); } else { this->changeValueContainer<long long>(value); return true; } } ///< Assigns a new value by changing type and creating a new container. 477 inline bool assignValue(const unsigned long long& value) { if (this->value_ && this->value_->type_ == MT_Type::UnsignedLongLong) { return this->value_->setValue(value); } else { this->changeValueContainer<unsigned long long>(value); return true; } } ///< Assigns a new value by changing type and creating a new container. 478 inline bool assignValue(const float& value) { if (this->value_ && this->value_->type_ == MT_Type::Float) { return this->value_->setValue(value); } else { this->changeValueContainer<float>(value); return true; } } ///< Assigns a new value by changing type and creating a new container. 479 inline bool assignValue(const double& value) { if (this->value_ && this->value_->type_ == MT_Type::Double) { return this->value_->setValue(value); } else { this->changeValueContainer<double>(value); return true; } } ///< Assigns a new value by changing type and creating a new container. 480 inline bool assignValue(const long double& value) { if (this->value_ && this->value_->type_ == MT_Type::LongDouble) { return this->value_->setValue(value); } else { this->changeValueContainer<long double>(value); return true; } } ///< Assigns a new value by changing type and creating a new container. 481 inline bool assignValue(const bool& value) { if (this->value_ && this->value_->type_ == MT_Type::Bool) { return this->value_->setValue(value); } else { this->changeValueContainer<bool>(value); return true; } } ///< Assigns a new value by changing type and creating a new container. 482 inline bool assignValue( void* const& value) { if (this->value_ && this->value_->type_ == MT_Type::VoidPointer) { return this->value_->setValue(value); } else { this->changeValueContainer<void*>(value); return true; } } ///< Assigns a new value by changing type and creating a new container. 483 inline bool assignValue(const std::string& value) { if (this->value_ && this->value_->type_ == MT_Type::String) { return this->value_->setValue(value); } else { this->changeValueContainer<std::string>(value); return true; } } ///< Assigns a new value by changing type and creating a new container. 484 inline bool assignValue(const orxonox::Vector2& value) { if (this->value_ && this->value_->type_ == MT_Type::Vector2) { return this->value_->setValue(value); } else { this->changeValueContainer<orxonox::Vector2>(value); return true; } } ///< Assigns a new value by changing type and creating a new container. 485 inline bool assignValue(const orxonox::Vector3& value) { if (this->value_ && this->value_->type_ == MT_Type::Vector3) { return this->value_->setValue(value); } else { this->changeValueContainer<orxonox::Vector3>(value); return true; } } ///< Assigns a new value by changing type and creating a new container. 486 inline bool assignValue(const orxonox::Vector4& value) { if (this->value_ && this->value_->type_ == MT_Type::Vector4) { return this->value_->setValue(value); } else { this->changeValueContainer<orxonox::Vector4>(value); return true; } } ///< Assigns a new value by changing type and creating a new container. 487 inline bool assignValue(const orxonox::ColourValue& value) { if (this->value_ && this->value_->type_ == MT_Type::ColourValue) { return this->value_->setValue(value); } else { this->changeValueContainer<orxonox::ColourValue>(value); return true; } } ///< Assigns a new value by changing type and creating a new container. 488 inline bool assignValue(const orxonox::Quaternion& value) { if (this->value_ && this->value_->type_ == MT_Type::Quaternion) { return this->value_->setValue(value); } else { this->changeValueContainer<orxonox::Quaternion>(value); return true; } } ///< Assigns a new value by changing type and creating a new container. 489 inline bool assignValue(const orxonox::Radian& value) { if (this->value_ && this->value_->type_ == MT_Type::Radian) { return this->value_->setValue(value); } else { this->changeValueContainer<orxonox::Radian>(value); return true; } } ///< Assigns a new value by changing type and creating a new container. 490 inline bool assignValue(const orxonox::Degree& value) { if (this->value_ && this->value_->type_ == MT_Type::Degree) { return this->value_->setValue(value); } else { this->changeValueContainer<orxonox::Degree>(value); return true; } } ///< Assigns a new value by changing type and creating a new container. 491 492 /// Changes the value container. 460 493 template <typename T> inline void changeValueContainer(const T& value) { if (this->value_) { delete this->value_; } this->createNewValueContainer<T>(value); } 461 / ** @brief Creates a new value container (works only with specialized types). */494 /// Creates a new value container (works only with specialized types). 462 495 template <typename T> void createNewValueContainer(const T& value) { /* STATIC ASSERT */ *****value; return false; } 463 496 … … 465 498 }; 466 499 467 / ** @brief Puts the MultiType on a stream by using the native << operator of the current type. */500 /// Puts the MultiType on a stream by using the native << operator of the current type. 468 501 _UtilExport inline std::ostream& operator<<(std::ostream& outstream, const MultiType& mt) { if (mt.value_) { mt.value_->toString(outstream); } return outstream; } 469 502 470 template <> inline bool MultiType::isType<char>() const { return (this->value_ && this->value_->type_ == MT_Type::Char); } /** @brief Returns true if the current type equals the given type. */ 471 template <> inline bool MultiType::isType<unsigned char>() const { return (this->value_ && this->value_->type_ == MT_Type::UnsignedChar); } /** @brief Returns true if the current type equals the given type. */ 472 template <> inline bool MultiType::isType<short>() const { return (this->value_ && this->value_->type_ == MT_Type::Short); } /** @brief Returns true if the current type equals the given type. */ 473 template <> inline bool MultiType::isType<unsigned short>() const { return (this->value_ && this->value_->type_ == MT_Type::UnsignedShort); } /** @brief Returns true if the current type equals the given type. */ 474 template <> inline bool MultiType::isType<int>() const { return (this->value_ && this->value_->type_ == MT_Type::Int); } /** @brief Returns true if the current type equals the given type. */ 475 template <> inline bool MultiType::isType<unsigned int>() const { return (this->value_ && this->value_->type_ == MT_Type::UnsignedInt); } /** @brief Returns true if the current type equals the given type. */ 476 template <> inline bool MultiType::isType<long>() const { return (this->value_ && this->value_->type_ == MT_Type::Long); } /** @brief Returns true if the current type equals the given type. */ 477 template <> inline bool MultiType::isType<unsigned long>() const { return (this->value_ && this->value_->type_ == MT_Type::UnsignedLong); } /** @brief Returns true if the current type equals the given type. */ 478 template <> inline bool MultiType::isType<long long>() const { return (this->value_ && this->value_->type_ == MT_Type::LongLong); } /** @brief Returns true if the current type equals the given type. */ 479 template <> inline bool MultiType::isType<unsigned long long>() const { return (this->value_ && this->value_->type_ == MT_Type::UnsignedLongLong); } /** @brief Returns true if the current type equals the given type. */ 480 template <> inline bool MultiType::isType<float>() const { return (this->value_ && this->value_->type_ == MT_Type::Float); } /** @brief Returns true if the current type equals the given type. */ 481 template <> inline bool MultiType::isType<double>() const { return (this->value_ && this->value_->type_ == MT_Type::Double); } /** @brief Returns true if the current type equals the given type. */ 482 template <> inline bool MultiType::isType<long double>() const { return (this->value_ && this->value_->type_ == MT_Type::LongDouble); } /** @brief Returns true if the current type equals the given type. */ 483 template <> inline bool MultiType::isType<bool>() const { return (this->value_ && this->value_->type_ == MT_Type::Bool); } /** @brief Returns true if the current type equals the given type. */ 484 template <> inline bool MultiType::isType<void*>() const { return (this->value_ && this->value_->type_ == MT_Type::VoidPointer); } /** @brief Returns true if the current type equals the given type. */ 485 template <> inline bool MultiType::isType<std::string>() const { return (this->value_ && this->value_->type_ == MT_Type::String); } /** @brief Returns true if the current type equals the given type. */ 486 template <> inline bool MultiType::isType<orxonox::Vector2>() const { return (this->value_ && this->value_->type_ == MT_Type::Vector2); } /** @brief Returns true if the current type equals the given type. */ 487 template <> inline bool MultiType::isType<orxonox::Vector3>() const { return (this->value_ && this->value_->type_ == MT_Type::Vector3); } /** @brief Returns true if the current type equals the given type. */ 488 template <> inline bool MultiType::isType<orxonox::Vector4>() const { return (this->value_ && this->value_->type_ == MT_Type::Vector4); } /** @brief Returns true if the current type equals the given type. */ 489 template <> inline bool MultiType::isType<orxonox::ColourValue>() const { return (this->value_ && this->value_->type_ == MT_Type::ColourValue); } /** @brief Returns true if the current type equals the given type. */ 490 template <> inline bool MultiType::isType<orxonox::Quaternion>() const { return (this->value_ && this->value_->type_ == MT_Type::Quaternion); } /** @brief Returns true if the current type equals the given type. */ 491 template <> inline bool MultiType::isType<orxonox::Radian>() const { return (this->value_ && this->value_->type_ == MT_Type::Radian); } /** @brief Returns true if the current type equals the given type. */ 492 template <> inline bool MultiType::isType<orxonox::Degree>() const { return (this->value_ && this->value_->type_ == MT_Type::Degree); } /** @brief Returns true if the current type equals the given type. */ 493 494 template <> inline bool MultiType::convert<void>() { this->reset(); return true; } /** @brief Deletes the content, type becomes MT_Type::Null. */ 503 template <> inline bool MultiType::isType<char>() const { return (this->value_ && this->value_->type_ == MT_Type::Char); } ///< Returns true if the current type equals the given type. 504 template <> inline bool MultiType::isType<unsigned char>() const { return (this->value_ && this->value_->type_ == MT_Type::UnsignedChar); } ///< Returns true if the current type equals the given type. 505 template <> inline bool MultiType::isType<short>() const { return (this->value_ && this->value_->type_ == MT_Type::Short); } ///< Returns true if the current type equals the given type. 506 template <> inline bool MultiType::isType<unsigned short>() const { return (this->value_ && this->value_->type_ == MT_Type::UnsignedShort); } ///< Returns true if the current type equals the given type. 507 template <> inline bool MultiType::isType<int>() const { return (this->value_ && this->value_->type_ == MT_Type::Int); } ///< Returns true if the current type equals the given type. 508 template <> inline bool MultiType::isType<unsigned int>() const { return (this->value_ && this->value_->type_ == MT_Type::UnsignedInt); } ///< Returns true if the current type equals the given type. 509 template <> inline bool MultiType::isType<long>() const { return (this->value_ && this->value_->type_ == MT_Type::Long); } ///< Returns true if the current type equals the given type. 510 template <> inline bool MultiType::isType<unsigned long>() const { return (this->value_ && this->value_->type_ == MT_Type::UnsignedLong); } ///< Returns true if the current type equals the given type. 511 template <> inline bool MultiType::isType<long long>() const { return (this->value_ && this->value_->type_ == MT_Type::LongLong); } ///< Returns true if the current type equals the given type. 512 template <> inline bool MultiType::isType<unsigned long long>() const { return (this->value_ && this->value_->type_ == MT_Type::UnsignedLongLong); } ///< Returns true if the current type equals the given type. 513 template <> inline bool MultiType::isType<float>() const { return (this->value_ && this->value_->type_ == MT_Type::Float); } ///< Returns true if the current type equals the given type. 514 template <> inline bool MultiType::isType<double>() const { return (this->value_ && this->value_->type_ == MT_Type::Double); } ///< Returns true if the current type equals the given type. 515 template <> inline bool MultiType::isType<long double>() const { return (this->value_ && this->value_->type_ == MT_Type::LongDouble); } ///< Returns true if the current type equals the given type. 516 template <> inline bool MultiType::isType<bool>() const { return (this->value_ && this->value_->type_ == MT_Type::Bool); } ///< Returns true if the current type equals the given type. 517 template <> inline bool MultiType::isType<void*>() const { return (this->value_ && this->value_->type_ == MT_Type::VoidPointer); } ///< Returns true if the current type equals the given type. 518 template <> inline bool MultiType::isType<std::string>() const { return (this->value_ && this->value_->type_ == MT_Type::String); } ///< Returns true if the current type equals the given type. 519 template <> inline bool MultiType::isType<orxonox::Vector2>() const { return (this->value_ && this->value_->type_ == MT_Type::Vector2); } ///< Returns true if the current type equals the given type. 520 template <> inline bool MultiType::isType<orxonox::Vector3>() const { return (this->value_ && this->value_->type_ == MT_Type::Vector3); } ///< Returns true if the current type equals the given type. 521 template <> inline bool MultiType::isType<orxonox::Vector4>() const { return (this->value_ && this->value_->type_ == MT_Type::Vector4); } ///< Returns true if the current type equals the given type. 522 template <> inline bool MultiType::isType<orxonox::ColourValue>() const { return (this->value_ && this->value_->type_ == MT_Type::ColourValue); } ///< Returns true if the current type equals the given type. 523 template <> inline bool MultiType::isType<orxonox::Quaternion>() const { return (this->value_ && this->value_->type_ == MT_Type::Quaternion); } ///< Returns true if the current type equals the given type. 524 template <> inline bool MultiType::isType<orxonox::Radian>() const { return (this->value_ && this->value_->type_ == MT_Type::Radian); } ///< Returns true if the current type equals the given type. 525 template <> inline bool MultiType::isType<orxonox::Degree>() const { return (this->value_ && this->value_->type_ == MT_Type::Degree); } ///< Returns true if the current type equals the given type. 526 527 /// Deletes the content, type becomes MT_Type::Null. 528 template <> inline bool MultiType::convert<void>() { this->reset(); return true; } 495 529 496 530 // Specialization to avoid ambiguities with the conversion operator 497 template <> inline bool MultiType::convert<std::string>() { return this->setValue<std::string> (this->operator std::string()); } / ** @brief Converts the current value to the given type. */498 template <> inline bool MultiType::convert<orxonox::Vector2>() { return this->setValue<orxonox::Vector2> (this->operator orxonox::Vector2()); } / ** @brief Converts the current value to the given type. */499 template <> inline bool MultiType::convert<orxonox::Vector3>() { return this->setValue<orxonox::Vector3> (this->operator orxonox::Vector3()); } / ** @brief Converts the current value to the given type. */500 template <> inline bool MultiType::convert<orxonox::Vector4>() { return this->setValue<orxonox::Vector4> (this->operator orxonox::Vector4()); } / ** @brief Converts the current value to the given type. */501 template <> inline bool MultiType::convert<orxonox::ColourValue>() { return this->setValue<orxonox::ColourValue>(this->operator orxonox::ColourValue()); } / ** @brief Converts the current value to the given type. */502 template <> inline bool MultiType::convert<orxonox::Quaternion>() { return this->setValue<orxonox::Quaternion> (this->operator orxonox::Quaternion()); } / ** @brief Converts the current value to the given type. */503 template <> inline bool MultiType::convert<orxonox::Radian>() { return this->setValue<orxonox::Radian> (this->operator orxonox::Radian()); } / ** @brief Converts the current value to the given type. */504 template <> inline bool MultiType::convert<orxonox::Degree>() { return this->setValue<orxonox::Degree> (this->operator orxonox::Degree()); } / ** @brief Converts the current value to the given type. */531 template <> inline bool MultiType::convert<std::string>() { return this->setValue<std::string> (this->operator std::string()); } ///< Converts the current value to the given type. 532 template <> inline bool MultiType::convert<orxonox::Vector2>() { return this->setValue<orxonox::Vector2> (this->operator orxonox::Vector2()); } ///< Converts the current value to the given type. 533 template <> inline bool MultiType::convert<orxonox::Vector3>() { return this->setValue<orxonox::Vector3> (this->operator orxonox::Vector3()); } ///< Converts the current value to the given type. 534 template <> inline bool MultiType::convert<orxonox::Vector4>() { return this->setValue<orxonox::Vector4> (this->operator orxonox::Vector4()); } ///< Converts the current value to the given type. 535 template <> inline bool MultiType::convert<orxonox::ColourValue>() { return this->setValue<orxonox::ColourValue>(this->operator orxonox::ColourValue()); } ///< Converts the current value to the given type. 536 template <> inline bool MultiType::convert<orxonox::Quaternion>() { return this->setValue<orxonox::Quaternion> (this->operator orxonox::Quaternion()); } ///< Converts the current value to the given type. 537 template <> inline bool MultiType::convert<orxonox::Radian>() { return this->setValue<orxonox::Radian> (this->operator orxonox::Radian()); } ///< Converts the current value to the given type. 538 template <> inline bool MultiType::convert<orxonox::Degree>() { return this->setValue<orxonox::Degree> (this->operator orxonox::Degree()); } ///< Converts the current value to the given type. 505 539 506 540 // Specialization to avoid ambiguities with the conversion operator 507 template <> inline bool MultiType::convert<const std::string&>() { return this->convert<std::string>(); } / ** @brief Converts the current value to the given type. */508 template <> inline bool MultiType::convert<const orxonox::Vector2&>() { return this->convert<orxonox::Vector2>(); } / ** @brief Converts the current value to the given type. */509 template <> inline bool MultiType::convert<const orxonox::Vector3&>() { return this->convert<orxonox::Vector3>(); } / ** @brief Converts the current value to the given type. */510 template <> inline bool MultiType::convert<const orxonox::Vector4&>() { return this->convert<orxonox::Vector4>(); } / ** @brief Converts the current value to the given type. */511 template <> inline bool MultiType::convert<const orxonox::ColourValue&>() { return this->convert<orxonox::ColourValue>(); } / ** @brief Converts the current value to the given type. */512 template <> inline bool MultiType::convert<const orxonox::Quaternion&>() { return this->convert<orxonox::Quaternion>(); } / ** @brief Converts the current value to the given type. */513 template <> inline bool MultiType::convert<const orxonox::Radian&>() { return this->convert<orxonox::Radian>(); } / ** @brief Converts the current value to the given type. */514 template <> inline bool MultiType::convert<const orxonox::Degree&>() { return this->convert<orxonox::Degree>(); } / ** @brief Converts the current value to the given type. */541 template <> inline bool MultiType::convert<const std::string&>() { return this->convert<std::string>(); } ///< Converts the current value to the given type. 542 template <> inline bool MultiType::convert<const orxonox::Vector2&>() { return this->convert<orxonox::Vector2>(); } ///< Converts the current value to the given type. 543 template <> inline bool MultiType::convert<const orxonox::Vector3&>() { return this->convert<orxonox::Vector3>(); } ///< Converts the current value to the given type. 544 template <> inline bool MultiType::convert<const orxonox::Vector4&>() { return this->convert<orxonox::Vector4>(); } ///< Converts the current value to the given type. 545 template <> inline bool MultiType::convert<const orxonox::ColourValue&>() { return this->convert<orxonox::ColourValue>(); } ///< Converts the current value to the given type. 546 template <> inline bool MultiType::convert<const orxonox::Quaternion&>() { return this->convert<orxonox::Quaternion>(); } ///< Converts the current value to the given type. 547 template <> inline bool MultiType::convert<const orxonox::Radian&>() { return this->convert<orxonox::Radian>(); } ///< Converts the current value to the given type. 548 template <> inline bool MultiType::convert<const orxonox::Degree&>() { return this->convert<orxonox::Degree>(); } ///< Converts the current value to the given type. 515 549 516 550 template <> _UtilExport void MultiType::createNewValueContainer(const char& value); … … 538 572 template <> _UtilExport void MultiType::createNewValueContainer(const orxonox::Degree& value); 539 573 540 inline bool MultiType::setValue(const char& value) { if (this->value_) { return this->value_->setValue(value); } else { return this->assignValue(value); } } /** @brief Assigns the given value and converts it to the current type. */ 541 inline bool MultiType::setValue(const unsigned char& value) { if (this->value_) { return this->value_->setValue(value); } else { return this->assignValue(value); } } /** @brief Assigns the given value and converts it to the current type. */ 542 inline bool MultiType::setValue(const short& value) { if (this->value_) { return this->value_->setValue(value); } else { return this->assignValue(value); } } /** @brief Assigns the given value and converts it to the current type. */ 543 inline bool MultiType::setValue(const unsigned short& value) { if (this->value_) { return this->value_->setValue(value); } else { return this->assignValue(value); } } /** @brief Assigns the given value and converts it to the current type. */ 544 inline bool MultiType::setValue(const int& value) { if (this->value_) { return this->value_->setValue(value); } else { return this->assignValue(value); } } /** @brief Assigns the given value and converts it to the current type. */ 545 inline bool MultiType::setValue(const unsigned int& value) { if (this->value_) { return this->value_->setValue(value); } else { return this->assignValue(value); } } /** @brief Assigns the given value and converts it to the current type. */ 546 inline bool MultiType::setValue(const long& value) { if (this->value_) { return this->value_->setValue(value); } else { return this->assignValue(value); } } /** @brief Assigns the given value and converts it to the current type. */ 547 inline bool MultiType::setValue(const unsigned long& value) { if (this->value_) { return this->value_->setValue(value); } else { return this->assignValue(value); } } /** @brief Assigns the given value and converts it to the current type. */ 548 inline bool MultiType::setValue(const long long& value) { if (this->value_) { return this->value_->setValue(value); } else { return this->assignValue(value); } } /** @brief Assigns the given value and converts it to the current type. */ 549 inline bool MultiType::setValue(const unsigned long long& value) { if (this->value_) { return this->value_->setValue(value); } else { return this->assignValue(value); } } /** @brief Assigns the given value and converts it to the current type. */ 550 inline bool MultiType::setValue(const float& value) { if (this->value_) { return this->value_->setValue(value); } else { return this->assignValue(value); } } /** @brief Assigns the given value and converts it to the current type. */ 551 inline bool MultiType::setValue(const double& value) { if (this->value_) { return this->value_->setValue(value); } else { return this->assignValue(value); } } /** @brief Assigns the given value and converts it to the current type. */ 552 inline bool MultiType::setValue(const long double& value) { if (this->value_) { return this->value_->setValue(value); } else { return this->assignValue(value); } } /** @brief Assigns the given value and converts it to the current type. */ 553 inline bool MultiType::setValue(const bool& value) { if (this->value_) { return this->value_->setValue(value); } else { return this->assignValue(value); } } /** @brief Assigns the given value and converts it to the current type. */ 554 inline bool MultiType::setValue( void* const& value) { if (this->value_) { return this->value_->setValue(value); } else { return this->assignValue(value); } } /** @brief Assigns the given value and converts it to the current type. */ 555 inline bool MultiType::setValue(const std::string& value) { if (this->value_) { return this->value_->setValue(value); } else { return this->assignValue(value); } } /** @brief Assigns the given value and converts it to the current type. */ 556 inline bool MultiType::setValue(const orxonox::Vector2& value) { if (this->value_) { return this->value_->setValue(value); } else { return this->assignValue(value); } } /** @brief Assigns the given value and converts it to the current type. */ 557 inline bool MultiType::setValue(const orxonox::Vector3& value) { if (this->value_) { return this->value_->setValue(value); } else { return this->assignValue(value); } } /** @brief Assigns the given value and converts it to the current type. */ 558 inline bool MultiType::setValue(const orxonox::Vector4& value) { if (this->value_) { return this->value_->setValue(value); } else { return this->assignValue(value); } } /** @brief Assigns the given value and converts it to the current type. */ 559 inline bool MultiType::setValue(const orxonox::ColourValue& value) { if (this->value_) { return this->value_->setValue(value); } else { return this->assignValue(value); } } /** @brief Assigns the given value and converts it to the current type. */ 560 inline bool MultiType::setValue(const orxonox::Quaternion& value) { if (this->value_) { return this->value_->setValue(value); } else { return this->assignValue(value); } } /** @brief Assigns the given value and converts it to the current type. */ 561 inline bool MultiType::setValue(const orxonox::Radian& value) { if (this->value_) { return this->value_->setValue(value); } else { return this->assignValue(value); } } /** @brief Assigns the given value and converts it to the current type. */ 562 inline bool MultiType::setValue(const orxonox::Degree& value) { if (this->value_) { return this->value_->setValue(value); } else { return this->assignValue(value); } } /** @brief Assigns the given value and converts it to the current type. */ 563 564 inline bool MultiType::setValue(const char* value) { if (this->value_) { return this->value_->setValue(std::string(value)); } else { return this->assignValue(std::string(value)); } } /** @brief Assigns the given value and converts it to the current type. */ 574 inline bool MultiType::setValue(const char& value) { if (this->value_) { return this->value_->setValue(value); } else { return this->assignValue(value); } } ///< Assigns the given value and converts it to the current type. 575 inline bool MultiType::setValue(const unsigned char& value) { if (this->value_) { return this->value_->setValue(value); } else { return this->assignValue(value); } } ///< Assigns the given value and converts it to the current type. 576 inline bool MultiType::setValue(const short& value) { if (this->value_) { return this->value_->setValue(value); } else { return this->assignValue(value); } } ///< Assigns the given value and converts it to the current type. 577 inline bool MultiType::setValue(const unsigned short& value) { if (this->value_) { return this->value_->setValue(value); } else { return this->assignValue(value); } } ///< Assigns the given value and converts it to the current type. 578 inline bool MultiType::setValue(const int& value) { if (this->value_) { return this->value_->setValue(value); } else { return this->assignValue(value); } } ///< Assigns the given value and converts it to the current type. 579 inline bool MultiType::setValue(const unsigned int& value) { if (this->value_) { return this->value_->setValue(value); } else { return this->assignValue(value); } } ///< Assigns the given value and converts it to the current type. 580 inline bool MultiType::setValue(const long& value) { if (this->value_) { return this->value_->setValue(value); } else { return this->assignValue(value); } } ///< Assigns the given value and converts it to the current type. 581 inline bool MultiType::setValue(const unsigned long& value) { if (this->value_) { return this->value_->setValue(value); } else { return this->assignValue(value); } } ///< Assigns the given value and converts it to the current type. 582 inline bool MultiType::setValue(const long long& value) { if (this->value_) { return this->value_->setValue(value); } else { return this->assignValue(value); } } ///< Assigns the given value and converts it to the current type. 583 inline bool MultiType::setValue(const unsigned long long& value) { if (this->value_) { return this->value_->setValue(value); } else { return this->assignValue(value); } } ///< Assigns the given value and converts it to the current type. 584 inline bool MultiType::setValue(const float& value) { if (this->value_) { return this->value_->setValue(value); } else { return this->assignValue(value); } } ///< Assigns the given value and converts it to the current type. 585 inline bool MultiType::setValue(const double& value) { if (this->value_) { return this->value_->setValue(value); } else { return this->assignValue(value); } } ///< Assigns the given value and converts it to the current type. 586 inline bool MultiType::setValue(const long double& value) { if (this->value_) { return this->value_->setValue(value); } else { return this->assignValue(value); } } ///< Assigns the given value and converts it to the current type. 587 inline bool MultiType::setValue(const bool& value) { if (this->value_) { return this->value_->setValue(value); } else { return this->assignValue(value); } } ///< Assigns the given value and converts it to the current type. 588 inline bool MultiType::setValue( void* const& value) { if (this->value_) { return this->value_->setValue(value); } else { return this->assignValue(value); } } ///< Assigns the given value and converts it to the current type. 589 inline bool MultiType::setValue(const std::string& value) { if (this->value_) { return this->value_->setValue(value); } else { return this->assignValue(value); } } ///< Assigns the given value and converts it to the current type. 590 inline bool MultiType::setValue(const orxonox::Vector2& value) { if (this->value_) { return this->value_->setValue(value); } else { return this->assignValue(value); } } ///< Assigns the given value and converts it to the current type. 591 inline bool MultiType::setValue(const orxonox::Vector3& value) { if (this->value_) { return this->value_->setValue(value); } else { return this->assignValue(value); } } ///< Assigns the given value and converts it to the current type. 592 inline bool MultiType::setValue(const orxonox::Vector4& value) { if (this->value_) { return this->value_->setValue(value); } else { return this->assignValue(value); } } ///< Assigns the given value and converts it to the current type. 593 inline bool MultiType::setValue(const orxonox::ColourValue& value) { if (this->value_) { return this->value_->setValue(value); } else { return this->assignValue(value); } } ///< Assigns the given value and converts it to the current type. 594 inline bool MultiType::setValue(const orxonox::Quaternion& value) { if (this->value_) { return this->value_->setValue(value); } else { return this->assignValue(value); } } ///< Assigns the given value and converts it to the current type. 595 inline bool MultiType::setValue(const orxonox::Radian& value) { if (this->value_) { return this->value_->setValue(value); } else { return this->assignValue(value); } } ///< Assigns the given value and converts it to the current type. 596 inline bool MultiType::setValue(const orxonox::Degree& value) { if (this->value_) { return this->value_->setValue(value); } else { return this->assignValue(value); } } ///< Assigns the given value and converts it to the current type. 597 598 /// Assigns the given value and converts it to the current type. 599 inline bool MultiType::setValue(const char* value) { if (this->value_) { return this->value_->setValue(std::string(value)); } else { return this->assignValue(std::string(value)); } } 565 600 } 566 601 -
code/trunk/src/libraries/util/MultiTypeValue.h
r6417 r7401 29 29 /** 30 30 @file 31 @ingroup MultiType 31 32 @brief Declaration and Implementation of the MT_Value<T> class. 32 33 … … 53 54 { 54 55 public: 55 / ** @brief Constructor: Assigns the value and the type identifier. */56 /// Constructor: Assigns the value and the type identifier. 56 57 MT_Value(const T& value, MT_Type::Value type) : MT_ValueBase(type), value_(value) {} 57 58 58 / ** @brief Creates a copy of itself. */59 /// Creates a copy of itself. 59 60 inline MT_ValueBase* clone() const { return new MT_Value<T>(this->value_, this->type_); } 60 61 61 / ** @brief Resets the current value to the default. */62 /// Resets the current value to the default. 62 63 inline void reset() { this->value_ = zeroise<T>(); bHasDefaultValue_ = true; } 63 64 64 /** @brief Assigns the value of the other MultiType, converted to T. @param other The other MultiType */ 65 /** 66 @brief Assigns the value of the other MultiType, converted to T. 67 @param other The other MultiType 68 */ 65 69 inline bool assimilate(const MultiType& other) 66 70 { … … 76 80 } 77 81 78 inline bool getValue(char* value) const { return convertValue<T, char >(value, value_, 0); } / ** @brief Assigns the value to the given pointer. The value gets converted if the types don't match. */79 inline bool getValue(unsigned char* value) const { return convertValue<T, unsigned char >(value, value_, 0); } / ** @brief Assigns the value to the given pointer. The value gets converted if the types don't match. */80 inline bool getValue(short* value) const { return convertValue<T, short >(value, value_, 0); } / ** @brief Assigns the value to the given pointer. The value gets converted if the types don't match. */81 inline bool getValue(unsigned short* value) const { return convertValue<T, unsigned short >(value, value_, 0); } / ** @brief Assigns the value to the given pointer. The value gets converted if the types don't match. */82 inline bool getValue(int* value) const { return convertValue<T, int >(value, value_, 0); } / ** @brief Assigns the value to the given pointer. The value gets converted if the types don't match. */83 inline bool getValue(unsigned int* value) const { return convertValue<T, unsigned int >(value, value_, 0); } / ** @brief Assigns the value to the given pointer. The value gets converted if the types don't match. */84 inline bool getValue(long* value) const { return convertValue<T, long >(value, value_, 0); } / ** @brief Assigns the value to the given pointer. The value gets converted if the types don't match. */85 inline bool getValue(unsigned long* value) const { return convertValue<T, unsigned long >(value, value_, 0); } / ** @brief Assigns the value to the given pointer. The value gets converted if the types don't match. */86 inline bool getValue(long long* value) const { return convertValue<T, long long >(value, value_, 0); } / ** @brief Assigns the value to the given pointer. The value gets converted if the types don't match. */87 inline bool getValue(unsigned long long* value) const { return convertValue<T, unsigned long long >(value, value_, 0); } / ** @brief Assigns the value to the given pointer. The value gets converted if the types don't match. */88 inline bool getValue(float* value) const { return convertValue<T, float >(value, value_, 0); } / ** @brief Assigns the value to the given pointer. The value gets converted if the types don't match. */89 inline bool getValue(double* value) const { return convertValue<T, double >(value, value_, 0); } / ** @brief Assigns the value to the given pointer. The value gets converted if the types don't match. */90 inline bool getValue(long double* value) const { return convertValue<T, long double >(value, value_, 0); } / ** @brief Assigns the value to the given pointer. The value gets converted if the types don't match. */91 inline bool getValue(bool* value) const { return convertValue<T, bool >(value, value_, 0); } / ** @brief Assigns the value to the given pointer. The value gets converted if the types don't match. */92 inline bool getValue(void** value) const { return convertValue<T, void* >(value, value_, 0); } / ** @brief Assigns the value to the given pointer. The value gets converted if the types don't match. */93 inline bool getValue(std::string* value) const { return convertValue<T, std::string >(value, value_, zeroise<std::string> ()); } / ** @brief Assigns the value to the given pointer. The value gets converted if the types don't match. */94 inline bool getValue(orxonox::Vector2* value) const { return convertValue<T, orxonox::Vector2 >(value, value_, zeroise<orxonox::Vector2> ()); } / ** @brief Assigns the value to the given pointer. The value gets converted if the types don't match. */95 inline bool getValue(orxonox::Vector3* value) const { return convertValue<T, orxonox::Vector3 >(value, value_, zeroise<orxonox::Vector3> ()); } / ** @brief Assigns the value to the given pointer. The value gets converted if the types don't match. */96 inline bool getValue(orxonox::Vector4* value) const { return convertValue<T, orxonox::Vector4 >(value, value_, zeroise<orxonox::Vector4> ()); } / ** @brief Assigns the value to the given pointer. The value gets converted if the types don't match. */97 inline bool getValue(orxonox::ColourValue* value) const { return convertValue<T, orxonox::ColourValue>(value, value_, zeroise<orxonox::ColourValue>()); } / ** @brief Assigns the value to the given pointer. The value gets converted if the types don't match. */98 inline bool getValue(orxonox::Quaternion* value) const { return convertValue<T, orxonox::Quaternion >(value, value_, zeroise<orxonox::Quaternion> ()); } / ** @brief Assigns the value to the given pointer. The value gets converted if the types don't match. */99 inline bool getValue(orxonox::Radian* value) const { return convertValue<T, orxonox::Radian >(value, value_, zeroise<orxonox::Radian> ()); } / ** @brief Assigns the value to the given pointer. The value gets converted if the types don't match. */100 inline bool getValue(orxonox::Degree* value) const { return convertValue<T, orxonox::Degree >(value, value_, zeroise<orxonox::Degree> ()); } / ** @brief Assigns the value to the given pointer. The value gets converted if the types don't match. */101 102 inline bool setValue(const char& value) { return !(bHasDefaultValue_ = !convertValue<char , T>(&value_, value, zeroise<T>())); } / ** @brief Assigns the value by converting it to T. */103 inline bool setValue(const unsigned char& value) { return !(bHasDefaultValue_ = !convertValue<unsigned char , T>(&value_, value, zeroise<T>())); } / ** @brief Assigns the value by converting it to T. */104 inline bool setValue(const short& value) { return !(bHasDefaultValue_ = !convertValue<short , T>(&value_, value, zeroise<T>())); } / ** @brief Assigns the value by converting it to T. */105 inline bool setValue(const unsigned short& value) { return !(bHasDefaultValue_ = !convertValue<unsigned short , T>(&value_, value, zeroise<T>())); } / ** @brief Assigns the value by converting it to T. */106 inline bool setValue(const int& value) { return !(bHasDefaultValue_ = !convertValue<int , T>(&value_, value, zeroise<T>())); } / ** @brief Assigns the value by converting it to T. */107 inline bool setValue(const unsigned int& value) { return !(bHasDefaultValue_ = !convertValue<unsigned int , T>(&value_, value, zeroise<T>())); } / ** @brief Assigns the value by converting it to T. */108 inline bool setValue(const long& value) { return !(bHasDefaultValue_ = !convertValue<long , T>(&value_, value, zeroise<T>())); } / ** @brief Assigns the value by converting it to T. */109 inline bool setValue(const unsigned long& value) { return !(bHasDefaultValue_ = !convertValue<unsigned long , T>(&value_, value, zeroise<T>())); } / ** @brief Assigns the value by converting it to T. */110 inline bool setValue(const long long& value) { return !(bHasDefaultValue_ = !convertValue<long long , T>(&value_, value, zeroise<T>())); } / ** @brief Assigns the value by converting it to T. */111 inline bool setValue(const unsigned long long& value) { return !(bHasDefaultValue_ = !convertValue<unsigned long long , T>(&value_, value, zeroise<T>())); } / ** @brief Assigns the value by converting it to T. */112 inline bool setValue(const float& value) { return !(bHasDefaultValue_ = !convertValue<float , T>(&value_, value, zeroise<T>())); } / ** @brief Assigns the value by converting it to T. */113 inline bool setValue(const double& value) { return !(bHasDefaultValue_ = !convertValue<double , T>(&value_, value, zeroise<T>())); } / ** @brief Assigns the value by converting it to T. */114 inline bool setValue(const long double& value) { return !(bHasDefaultValue_ = !convertValue<long double , T>(&value_, value, zeroise<T>())); } / ** @brief Assigns the value by converting it to T. */115 inline bool setValue(const bool& value) { return !(bHasDefaultValue_ = !convertValue<bool , T>(&value_, value, zeroise<T>())); } / ** @brief Assigns the value by converting it to T. */116 inline bool setValue( void* const& value) { return !(bHasDefaultValue_ = !convertValue<void* , T>(&value_, value, zeroise<T>())); } / ** @brief Assigns the value by converting it to T. */117 inline bool setValue(const std::string& value) { return !(bHasDefaultValue_ = !convertValue<std::string , T>(&value_, value, zeroise<T>())); } / ** @brief Assigns the value by converting it to T. */118 inline bool setValue(const orxonox::Vector2& value) { return !(bHasDefaultValue_ = !convertValue<orxonox::Vector2 , T>(&value_, value, zeroise<T>())); } / ** @brief Assigns the value by converting it to T. */119 inline bool setValue(const orxonox::Vector3& value) { return !(bHasDefaultValue_ = !convertValue<orxonox::Vector3 , T>(&value_, value, zeroise<T>())); } / ** @brief Assigns the value by converting it to T. */120 inline bool setValue(const orxonox::Vector4& value) { return !(bHasDefaultValue_ = !convertValue<orxonox::Vector4 , T>(&value_, value, zeroise<T>())); } / ** @brief Assigns the value by converting it to T. */121 inline bool setValue(const orxonox::ColourValue& value) { return !(bHasDefaultValue_ = !convertValue<orxonox::ColourValue, T>(&value_, value, zeroise<T>())); } / ** @brief Assigns the value by converting it to T. */122 inline bool setValue(const orxonox::Quaternion& value) { return !(bHasDefaultValue_ = !convertValue<orxonox::Quaternion , T>(&value_, value, zeroise<T>())); } / ** @brief Assigns the value by converting it to T. */123 inline bool setValue(const orxonox::Radian& value) { return !(bHasDefaultValue_ = !convertValue<orxonox::Radian , T>(&value_, value, zeroise<T>())); } / ** @brief Assigns the value by converting it to T. */124 inline bool setValue(const orxonox::Degree& value) { return !(bHasDefaultValue_ = !convertValue<orxonox::Degree , T>(&value_, value, zeroise<T>())); } / ** @brief Assigns the value by converting it to T. */125 126 inline operator char() const { return getConvertedValue<T, char> (this->value_, 0); } / ** @brief Returns the current value, converted to the requested type. */127 inline operator unsigned char() const { return getConvertedValue<T, unsigned char> (this->value_, 0); } / ** @brief Returns the current value, converted to the requested type. */128 inline operator short() const { return getConvertedValue<T, short> (this->value_, 0); } / ** @brief Returns the current value, converted to the requested type. */129 inline operator unsigned short() const { return getConvertedValue<T, unsigned short> (this->value_, 0); } / ** @brief Returns the current value, converted to the requested type. */130 inline operator int() const { return getConvertedValue<T, int> (this->value_, 0); } / ** @brief Returns the current value, converted to the requested type. */131 inline operator unsigned int() const { return getConvertedValue<T, unsigned int> (this->value_, 0); } / ** @brief Returns the current value, converted to the requested type. */132 inline operator long() const { return getConvertedValue<T, long> (this->value_, 0); } / ** @brief Returns the current value, converted to the requested type. */133 inline operator unsigned long() const { return getConvertedValue<T, unsigned long> (this->value_, 0); } / ** @brief Returns the current value, converted to the requested type. */134 inline operator long long() const { return getConvertedValue<T, long long> (this->value_, 0); } / ** @brief Returns the current value, converted to the requested type. */135 inline operator unsigned long long() const { return getConvertedValue<T, unsigned long long> (this->value_, 0); } / ** @brief Returns the current value, converted to the requested type. */136 inline operator float() const { return getConvertedValue<T, float> (this->value_, 0); } / ** @brief Returns the current value, converted to the requested type. */137 inline operator double() const { return getConvertedValue<T, double> (this->value_, 0); } / ** @brief Returns the current value, converted to the requested type. */138 inline operator long double() const { return getConvertedValue<T, long double> (this->value_, 0); } / ** @brief Returns the current value, converted to the requested type. */139 inline operator bool() const { return getConvertedValue<T, bool> (this->value_, 0); } / ** @brief Returns the current value, converted to the requested type. */140 inline operator void*() const { return getConvertedValue<T, void*> (this->value_, 0); } / ** @brief Returns the current value, converted to the requested type. */141 inline operator std::string() const { return getConvertedValue<T, std::string> (this->value_, NilValue<std::string >()); } / ** @brief Returns the current value, converted to the requested type. */142 inline operator orxonox::Vector2() const { return getConvertedValue<T, orxonox::Vector2> (this->value_, NilValue<orxonox::Vector2 >()); } / ** @brief Returns the current value, converted to the requested type. */143 inline operator orxonox::Vector3() const { return getConvertedValue<T, orxonox::Vector3> (this->value_, NilValue<orxonox::Vector3 >()); } / ** @brief Returns the current value, converted to the requested type. */144 inline operator orxonox::Vector4() const { return getConvertedValue<T, orxonox::Vector4> (this->value_, NilValue<orxonox::Vector4 >()); } / ** @brief Returns the current value, converted to the requested type. */145 inline operator orxonox::ColourValue() const { return getConvertedValue<T, orxonox::ColourValue>(this->value_, NilValue<orxonox::ColourValue>()); } / ** @brief Returns the current value, converted to the requested type. */146 inline operator orxonox::Quaternion() const { return getConvertedValue<T, orxonox::Quaternion> (this->value_, NilValue<orxonox::Quaternion >()); } / ** @brief Returns the current value, converted to the requested type. */147 inline operator orxonox::Radian() const { return getConvertedValue<T, orxonox::Radian> (this->value_, NilValue<orxonox::Radian >()); } / ** @brief Returns the current value, converted to the requested type. */148 inline operator orxonox::Degree() const { return getConvertedValue<T, orxonox::Degree> (this->value_, NilValue<orxonox::Degree >()); } / ** @brief Returns the current value, converted to the requested type. */149 150 / ** @brief Puts the current value on the stream */82 inline bool getValue(char* value) const { return convertValue<T, char >(value, value_, 0); } ///< Assigns the value to the given pointer. The value gets converted if the types don't match. 83 inline bool getValue(unsigned char* value) const { return convertValue<T, unsigned char >(value, value_, 0); } ///< Assigns the value to the given pointer. The value gets converted if the types don't match. 84 inline bool getValue(short* value) const { return convertValue<T, short >(value, value_, 0); } ///< Assigns the value to the given pointer. The value gets converted if the types don't match. 85 inline bool getValue(unsigned short* value) const { return convertValue<T, unsigned short >(value, value_, 0); } ///< Assigns the value to the given pointer. The value gets converted if the types don't match. 86 inline bool getValue(int* value) const { return convertValue<T, int >(value, value_, 0); } ///< Assigns the value to the given pointer. The value gets converted if the types don't match. 87 inline bool getValue(unsigned int* value) const { return convertValue<T, unsigned int >(value, value_, 0); } ///< Assigns the value to the given pointer. The value gets converted if the types don't match. 88 inline bool getValue(long* value) const { return convertValue<T, long >(value, value_, 0); } ///< Assigns the value to the given pointer. The value gets converted if the types don't match. 89 inline bool getValue(unsigned long* value) const { return convertValue<T, unsigned long >(value, value_, 0); } ///< Assigns the value to the given pointer. The value gets converted if the types don't match. 90 inline bool getValue(long long* value) const { return convertValue<T, long long >(value, value_, 0); } ///< Assigns the value to the given pointer. The value gets converted if the types don't match. 91 inline bool getValue(unsigned long long* value) const { return convertValue<T, unsigned long long >(value, value_, 0); } ///< Assigns the value to the given pointer. The value gets converted if the types don't match. 92 inline bool getValue(float* value) const { return convertValue<T, float >(value, value_, 0); } ///< Assigns the value to the given pointer. The value gets converted if the types don't match. 93 inline bool getValue(double* value) const { return convertValue<T, double >(value, value_, 0); } ///< Assigns the value to the given pointer. The value gets converted if the types don't match. 94 inline bool getValue(long double* value) const { return convertValue<T, long double >(value, value_, 0); } ///< Assigns the value to the given pointer. The value gets converted if the types don't match. 95 inline bool getValue(bool* value) const { return convertValue<T, bool >(value, value_, 0); } ///< Assigns the value to the given pointer. The value gets converted if the types don't match. 96 inline bool getValue(void** value) const { return convertValue<T, void* >(value, value_, 0); } ///< Assigns the value to the given pointer. The value gets converted if the types don't match. 97 inline bool getValue(std::string* value) const { return convertValue<T, std::string >(value, value_, zeroise<std::string> ()); } ///< Assigns the value to the given pointer. The value gets converted if the types don't match. 98 inline bool getValue(orxonox::Vector2* value) const { return convertValue<T, orxonox::Vector2 >(value, value_, zeroise<orxonox::Vector2> ()); } ///< Assigns the value to the given pointer. The value gets converted if the types don't match. 99 inline bool getValue(orxonox::Vector3* value) const { return convertValue<T, orxonox::Vector3 >(value, value_, zeroise<orxonox::Vector3> ()); } ///< Assigns the value to the given pointer. The value gets converted if the types don't match. 100 inline bool getValue(orxonox::Vector4* value) const { return convertValue<T, orxonox::Vector4 >(value, value_, zeroise<orxonox::Vector4> ()); } ///< Assigns the value to the given pointer. The value gets converted if the types don't match. 101 inline bool getValue(orxonox::ColourValue* value) const { return convertValue<T, orxonox::ColourValue>(value, value_, zeroise<orxonox::ColourValue>()); } ///< Assigns the value to the given pointer. The value gets converted if the types don't match. 102 inline bool getValue(orxonox::Quaternion* value) const { return convertValue<T, orxonox::Quaternion >(value, value_, zeroise<orxonox::Quaternion> ()); } ///< Assigns the value to the given pointer. The value gets converted if the types don't match. 103 inline bool getValue(orxonox::Radian* value) const { return convertValue<T, orxonox::Radian >(value, value_, zeroise<orxonox::Radian> ()); } ///< Assigns the value to the given pointer. The value gets converted if the types don't match. 104 inline bool getValue(orxonox::Degree* value) const { return convertValue<T, orxonox::Degree >(value, value_, zeroise<orxonox::Degree> ()); } ///< Assigns the value to the given pointer. The value gets converted if the types don't match. 105 106 inline bool setValue(const char& value) { return !(bHasDefaultValue_ = !convertValue<char , T>(&value_, value, zeroise<T>())); } ///< Assigns the value by converting it to T. 107 inline bool setValue(const unsigned char& value) { return !(bHasDefaultValue_ = !convertValue<unsigned char , T>(&value_, value, zeroise<T>())); } ///< Assigns the value by converting it to T. 108 inline bool setValue(const short& value) { return !(bHasDefaultValue_ = !convertValue<short , T>(&value_, value, zeroise<T>())); } ///< Assigns the value by converting it to T. 109 inline bool setValue(const unsigned short& value) { return !(bHasDefaultValue_ = !convertValue<unsigned short , T>(&value_, value, zeroise<T>())); } ///< Assigns the value by converting it to T. 110 inline bool setValue(const int& value) { return !(bHasDefaultValue_ = !convertValue<int , T>(&value_, value, zeroise<T>())); } ///< Assigns the value by converting it to T. 111 inline bool setValue(const unsigned int& value) { return !(bHasDefaultValue_ = !convertValue<unsigned int , T>(&value_, value, zeroise<T>())); } ///< Assigns the value by converting it to T. 112 inline bool setValue(const long& value) { return !(bHasDefaultValue_ = !convertValue<long , T>(&value_, value, zeroise<T>())); } ///< Assigns the value by converting it to T. 113 inline bool setValue(const unsigned long& value) { return !(bHasDefaultValue_ = !convertValue<unsigned long , T>(&value_, value, zeroise<T>())); } ///< Assigns the value by converting it to T. 114 inline bool setValue(const long long& value) { return !(bHasDefaultValue_ = !convertValue<long long , T>(&value_, value, zeroise<T>())); } ///< Assigns the value by converting it to T. 115 inline bool setValue(const unsigned long long& value) { return !(bHasDefaultValue_ = !convertValue<unsigned long long , T>(&value_, value, zeroise<T>())); } ///< Assigns the value by converting it to T. 116 inline bool setValue(const float& value) { return !(bHasDefaultValue_ = !convertValue<float , T>(&value_, value, zeroise<T>())); } ///< Assigns the value by converting it to T. 117 inline bool setValue(const double& value) { return !(bHasDefaultValue_ = !convertValue<double , T>(&value_, value, zeroise<T>())); } ///< Assigns the value by converting it to T. 118 inline bool setValue(const long double& value) { return !(bHasDefaultValue_ = !convertValue<long double , T>(&value_, value, zeroise<T>())); } ///< Assigns the value by converting it to T. 119 inline bool setValue(const bool& value) { return !(bHasDefaultValue_ = !convertValue<bool , T>(&value_, value, zeroise<T>())); } ///< Assigns the value by converting it to T. 120 inline bool setValue( void* const& value) { return !(bHasDefaultValue_ = !convertValue<void* , T>(&value_, value, zeroise<T>())); } ///< Assigns the value by converting it to T. 121 inline bool setValue(const std::string& value) { return !(bHasDefaultValue_ = !convertValue<std::string , T>(&value_, value, zeroise<T>())); } ///< Assigns the value by converting it to T. 122 inline bool setValue(const orxonox::Vector2& value) { return !(bHasDefaultValue_ = !convertValue<orxonox::Vector2 , T>(&value_, value, zeroise<T>())); } ///< Assigns the value by converting it to T. 123 inline bool setValue(const orxonox::Vector3& value) { return !(bHasDefaultValue_ = !convertValue<orxonox::Vector3 , T>(&value_, value, zeroise<T>())); } ///< Assigns the value by converting it to T. 124 inline bool setValue(const orxonox::Vector4& value) { return !(bHasDefaultValue_ = !convertValue<orxonox::Vector4 , T>(&value_, value, zeroise<T>())); } ///< Assigns the value by converting it to T. 125 inline bool setValue(const orxonox::ColourValue& value) { return !(bHasDefaultValue_ = !convertValue<orxonox::ColourValue, T>(&value_, value, zeroise<T>())); } ///< Assigns the value by converting it to T. 126 inline bool setValue(const orxonox::Quaternion& value) { return !(bHasDefaultValue_ = !convertValue<orxonox::Quaternion , T>(&value_, value, zeroise<T>())); } ///< Assigns the value by converting it to T. 127 inline bool setValue(const orxonox::Radian& value) { return !(bHasDefaultValue_ = !convertValue<orxonox::Radian , T>(&value_, value, zeroise<T>())); } ///< Assigns the value by converting it to T. 128 inline bool setValue(const orxonox::Degree& value) { return !(bHasDefaultValue_ = !convertValue<orxonox::Degree , T>(&value_, value, zeroise<T>())); } ///< Assigns the value by converting it to T. 129 130 inline operator char() const { return getConvertedValue<T, char> (this->value_, 0); } ///< Returns the current value, converted to the requested type. 131 inline operator unsigned char() const { return getConvertedValue<T, unsigned char> (this->value_, 0); } ///< Returns the current value, converted to the requested type. 132 inline operator short() const { return getConvertedValue<T, short> (this->value_, 0); } ///< Returns the current value, converted to the requested type. 133 inline operator unsigned short() const { return getConvertedValue<T, unsigned short> (this->value_, 0); } ///< Returns the current value, converted to the requested type. 134 inline operator int() const { return getConvertedValue<T, int> (this->value_, 0); } ///< Returns the current value, converted to the requested type. 135 inline operator unsigned int() const { return getConvertedValue<T, unsigned int> (this->value_, 0); } ///< Returns the current value, converted to the requested type. 136 inline operator long() const { return getConvertedValue<T, long> (this->value_, 0); } ///< Returns the current value, converted to the requested type. 137 inline operator unsigned long() const { return getConvertedValue<T, unsigned long> (this->value_, 0); } ///< Returns the current value, converted to the requested type. 138 inline operator long long() const { return getConvertedValue<T, long long> (this->value_, 0); } ///< Returns the current value, converted to the requested type. 139 inline operator unsigned long long() const { return getConvertedValue<T, unsigned long long> (this->value_, 0); } ///< Returns the current value, converted to the requested type. 140 inline operator float() const { return getConvertedValue<T, float> (this->value_, 0); } ///< Returns the current value, converted to the requested type. 141 inline operator double() const { return getConvertedValue<T, double> (this->value_, 0); } ///< Returns the current value, converted to the requested type. 142 inline operator long double() const { return getConvertedValue<T, long double> (this->value_, 0); } ///< Returns the current value, converted to the requested type. 143 inline operator bool() const { return getConvertedValue<T, bool> (this->value_, 0); } ///< Returns the current value, converted to the requested type. 144 inline operator void*() const { return getConvertedValue<T, void*> (this->value_, 0); } ///< Returns the current value, converted to the requested type. 145 inline operator std::string() const { return getConvertedValue<T, std::string> (this->value_, NilValue<std::string >()); } ///< Returns the current value, converted to the requested type. 146 inline operator orxonox::Vector2() const { return getConvertedValue<T, orxonox::Vector2> (this->value_, NilValue<orxonox::Vector2 >()); } ///< Returns the current value, converted to the requested type. 147 inline operator orxonox::Vector3() const { return getConvertedValue<T, orxonox::Vector3> (this->value_, NilValue<orxonox::Vector3 >()); } ///< Returns the current value, converted to the requested type. 148 inline operator orxonox::Vector4() const { return getConvertedValue<T, orxonox::Vector4> (this->value_, NilValue<orxonox::Vector4 >()); } ///< Returns the current value, converted to the requested type. 149 inline operator orxonox::ColourValue() const { return getConvertedValue<T, orxonox::ColourValue>(this->value_, NilValue<orxonox::ColourValue>()); } ///< Returns the current value, converted to the requested type. 150 inline operator orxonox::Quaternion() const { return getConvertedValue<T, orxonox::Quaternion> (this->value_, NilValue<orxonox::Quaternion >()); } ///< Returns the current value, converted to the requested type. 151 inline operator orxonox::Radian() const { return getConvertedValue<T, orxonox::Radian> (this->value_, NilValue<orxonox::Radian >()); } ///< Returns the current value, converted to the requested type. 152 inline operator orxonox::Degree() const { return getConvertedValue<T, orxonox::Degree> (this->value_, NilValue<orxonox::Degree >()); } ///< Returns the current value, converted to the requested type. 153 154 /// Puts the current value on the stream 151 155 inline void toString(std::ostream& outstream) const { outstream << this->value_; } 152 156 153 / ** @brief loads data from the bytestream (mem) into the MT and increases the bytestream pointer by the size of the data */157 /// loads data from the bytestream (mem) into the MT and increases the bytestream pointer by the size of the data 154 158 inline void importData( uint8_t*& mem ) { loadAndIncrease( /*(const T&)*/this->value_, mem ); } 155 / ** @brief saves data from the MT into the bytestream (mem) and increases the bytestream pointer by the size of the data */159 /// saves data from the MT into the bytestream (mem) and increases the bytestream pointer by the size of the data 156 160 inline void exportData( uint8_t*& mem ) const { saveAndIncrease( /*(const T&)*/this->value_, mem ); } 157 / ** @brief returns the size of the data that would be saved by exportData */161 /// returns the size of the data that would be saved by exportData 158 162 inline uint8_t getSize() const { return returnSize( this->value_ ); } 159 163 160 T value_; // !< The stored value164 T value_; ///< The stored value 161 165 }; 162 166 -
code/trunk/src/libraries/util/OrxAssert.h
r6105 r7401 29 29 /** 30 30 @file 31 @ingroup ExceptionAssertion 31 32 @brief 32 33 Declaration of custom assertion facilities … … 41 42 #include "OutputHandler.h" 42 43 43 // define an assert macro that can display a message44 44 #ifndef NDEBUG 45 /** Run time assertion like assert(), but with an embedded message. 46 @details 47 The message will be printed as error with COUT(1). <br> 48 You can use the same magic here as you can with \ref ThrowException 49 @code 50 OrxAssert(condition, "Text: " << number << " more text"); 51 @endcode 52 */ 45 53 #define OrxAssert(Assertion, ErrorMessage) \ 46 54 Assertion ? ((void)0) : (void)(orxonox::OutputHandler::getOutStream(1) << ErrorMessage << std::endl); \ -
code/trunk/src/libraries/util/OrxEnum.h
r5738 r7401 28 28 29 29 /** 30 @file 31 @brief 32 Declaration of the OrxEnum class. 30 @file 31 @ingroup Util 33 32 */ 34 33 … … 40 39 namespace orxonox 41 40 { 41 /** Lightweight enumeration class that can be extended at run time. 42 @details 43 The class accepts type int and also defines operator int(). Therefore 44 int and OrxEnum can be used interchangeably so you can extend the content 45 of the enumeration at run time by adding ints. 46 @par Declaring an OrxEnum 47 Write a struct that inherits OrxEnum and use some macros: 48 @code 49 struct MyEnum : OrxEnum<MyEnum> 50 { 51 OrxEnumConstructors(MyEnum); 52 53 static const int Value1 = -1; 54 static const int Value2 = 0; 55 static const int Value3 = Value2 + 10; 56 }; 57 @endcode 58 */ 42 59 template <class T> 43 60 struct OrxEnum … … 45 62 public: 46 63 OrxEnum() { } 47 OrxEnum(int type) 64 OrxEnum(int type) { type_ = type; } 48 65 OrxEnum(const T& instance) { type_ = instance.type_; } 49 66 50 operator int() 67 operator int() { return type_; } 51 68 T& operator =(int type) { type_ = type; return *this; } 52 69 bool operator <(const T& right) const { return (type_ < right.type_); } … … 59 76 } 60 77 78 /// See orxonox::OrxEnum for more info 61 79 #define OrxEnumConstructors(enumName) \ 62 80 enumName() { } \ -
code/trunk/src/libraries/util/OutputHandler.cc
r6417 r7401 67 67 @brief 68 68 Gets temporary log path and starts the log file 69 @param outputHandler70 This is only required to avoid another call to getInstance (this c'tor was71 called from getInstance!)72 69 */ 73 70 LogFileWriter() … … 117 114 118 115 private: 119 std::ofstream logFile_; //! File handle for the log file120 std::string logFilename_; //! Filename of the log file116 std::ofstream logFile_; //!< File handle for the log file 117 std::string logFilename_; //!< Filename of the log file 121 118 }; 122 119 … … 162 159 @brief 163 160 Sets the right soft debug level and registers itself 164 @param outputHandler165 This is only required to avoid another call to getInstance (this c'tor was166 called from getInstance!)167 161 */ 168 162 MemoryLogWriter() … … 186 180 187 181 private: 188 std::ostringstream buffer_; //! Stream object used to process the output189 std::vector<std::pair<int, std::string> > output_; //! Vector containing ALL output182 std::ostringstream buffer_; //!< Stream object used to process the output 183 std::vector<std::pair<int, std::string> > output_; //!< Vector containing ALL output 190 184 }; 191 185 -
code/trunk/src/libraries/util/OutputHandler.h
r7284 r7401 29 29 /** 30 30 @file 31 @ingroup Util Output 31 32 @brief 32 Declaration of classes related to output (logging) .33 Declaration of classes related to output (logging), most notably OutputHandler and OutputListener. 33 34 */ 34 35 … … 50 51 Denotes different levels of text output (log output) 51 52 52 0, None : Very important output53 1, Error : Errors54 2, Warning: Warnings55 3, Info : Information56 4, Debug : Debug information57 5, Verbose: More debug information58 6, Ultra : Crazy debug information53 - 0, None : Very important output 54 - 1, Error : Errors 55 - 2, Warning: Warnings 56 - 3, Info : Information 57 - 4, Debug : Debug information 58 - 5, Verbose: More debug information 59 - 6, Ultra : Crazy debug information 59 60 */ 60 61 namespace OutputLevel … … 79 80 /** 80 81 @brief 81 The OutputHandler acts like std::cout, but output isn't only shown in the console. 82 83 You can register your own listener for output by inheriting from OutputListner. 82 The OutputHandler acts like @c std::cout, but output isn't only shown in the console. 83 84 Output passed to the OutputHandler is distributed to all registered listeners, 85 for example the console, the logfile, or the ingame shell. 86 87 You can register your own listener for output by inheriting from OutputListener. 84 88 And if you need the output previously processed, iterate over it with 85 OutputHandler::getOutputVector[Begin/End]. 89 OutputHandler::getOutputVectorBegin and OutputHandler::getOutputVectorEnd. 90 86 91 The way to output text is to first set the desired output level with 87 OutputHandler::getOutStream(level) and then use the "<<" operator like with std::cout. 92 @ref getOutStream "OutputHandler::getOutStream(level)" and then use 93 the "<<" operator like with @c std::cout. Alternatively you can use the COUT() macro. 88 94 */ 89 95 class _UtilExport OutputHandler … … 213 219 OutputHandler(); 214 220 ~OutputHandler(); 215 OutputHandler(const OutputHandler& rhs); //!Unused and undefined221 OutputHandler(const OutputHandler& rhs); //!< Copy-constructor: Unused and undefined 216 222 217 223 std::list<OutputListener*> listeners_; //!< Array with all registered output listeners -
code/trunk/src/libraries/util/Scope.cc
r5738 r7401 27 27 */ 28 28 29 /** 30 @file 31 @brief Static linkage of the two maps in orxonox::ScopeManager. 32 */ 33 29 34 #include "Scope.h" 30 35 -
code/trunk/src/libraries/util/Scope.h
r7266 r7401 27 27 */ 28 28 29 /** 30 @file 31 @ingroup SingletonScope 32 @brief Declaration of the classes that are needed to use Scopes: 33 orxonox::Scope, orxonox::ScopeListener, and orxonox::ScopeManager. 34 35 @anchor Scope 36 37 A virtual scope can be represented by an instance of class orxonox::Scope. orxonox::Scope<@a scope> is a template 38 an its template argument defines the name of the virtual scope. See orxonox::ScopeID for an enumeration of the 39 available values for @a scope. The orxonox::Scope object for a given @a scope can be activated or deactivated. 40 Instances of orxonox::ScopeListener can register for a given @a scope and will get a notification if the 41 corresponding orxonox::Scope object changes its state. 42 43 To avoid multiple instances of orxonox::Scope<@a scope> in different libraries, each instance of orxonox::Scope 44 registers in orxonox::ScopeManager, where they are linked statically in the util library. 45 46 Scopes are usually used to control the creation and destruction of Singletons. 47 48 @see orxonox::ScopedSingletonManager 49 @see orxonox::Singleton 50 */ 51 29 52 #ifndef __Util_Scope_H__ 30 53 #define __Util_Scope_H__ … … 42 65 { 43 66 /** 44 @brief The ScopeManager stores the variables of the scope templates in a statically linked context. 67 @brief The ScopeManager stores the variables of the Scope templates in a statically linked context. 68 69 If all Scope objects are managed by this class, they are statically linked in the util library. 70 Without this, a new instance of Scope<T> for each T would be created in every library of Orxonox, 71 which is of course not the desired behavior. 72 73 @see See @ref Scope "this description" for details about the interrelationship of Scope, ScopeListener, and ScopeManager. 45 74 */ 46 75 class _UtilExport ScopeManager … … 56 85 57 86 /** 58 @brief ScopeListeners register themselves in the corresponding scope and wait for notifications. 87 @brief ScopeListeners register themselves in the corresponding Scope and wait for notifications. 88 Notifications are sent if a Scope is activated or deactivated. 89 90 @see See @ref Scope "this description" for details about the interrelationship of Scope, ScopeListener, and ScopeManager. 59 91 */ 60 92 class _UtilExport ScopeListener … … 86 118 Objects inheriting from a ScopeListener are registered in a list (different for each scope). 87 119 If the scope gets activated or deactivated, all objects in this list are notified. 120 121 @see See @ref Scope "this description" for details about the interrelationship of Scope, ScopeListener, and ScopeManager. 88 122 */ 89 123 template <ScopeID::Value scope> … … 130 164 } 131 165 166 //! Deactivates the listeners of this scope in case the scope is destroyed or the construction fails. 132 167 void deactivateListeners() 133 168 { -
code/trunk/src/libraries/util/ScopedSingletonManager.cc
r7284 r7401 27 27 */ 28 28 29 /** 30 @file 31 @brief Static linkage of the ScopedSingletonManager maps. 32 */ 33 29 34 #include "ScopedSingletonManager.h" 30 35 -
code/trunk/src/libraries/util/ScopedSingletonManager.h
r7284 r7401 26 26 * 27 27 */ 28 29 /** 30 @file 31 @ingroup SingletonScope 32 @brief Definition of orxonox::ScopedSingletonManager, orxonox::ClassScopedSingletonManager, and the ManageScopedSingleton macro. 33 34 ScopedSingletonManager is used to create and destroy Singletons that belong to 35 a given Scope. For each one of these singletons, the macro ManageScopedSingleton() 36 has to be called to register the singleton with orxonox::ScopedSingletonManager. 37 38 See @ref SingletonExample "this code" for an example. 39 40 @see orxonox::Singleton 41 @see orxonox::Scope 42 */ 28 43 29 44 #ifndef __ScopedSingletonManager_H__ … … 38 53 #include "util/Singleton.h" 39 54 55 /** 56 @brief Registers an orxonox::Singleton with orxonox::ScopedSingletonManager. 57 @param className The name of the singleton class 58 @param scope The scope in which the singleton should exist 59 @param allowedToFail If true, the singleton is allowed to fail and thus a try-catch block is used when creating the singleton. 60 61 If this macro is called for a singleton, it is registered with ScopedSingletonManager 62 and will thus be created if its scope becomes active and destroyed if is deactivated. 63 */ 40 64 #define ManageScopedSingleton(className, scope, allowedToFail) \ 41 65 className* className::singletonPtr_s = NULL; \ … … 46 70 class OrxonoxClass; 47 71 72 /** 73 @brief Base class of ClassScopedSingletonManager, implements some static functions 74 used to dispatch calls to preUpdate and postUpdate to all instances of this class. 75 It also keeps track of all existing ScopedSingletonManagers and stores them in a 76 map, sorted by the scope they belong to. 77 */ 48 78 class _UtilExport ScopedSingletonManager 49 79 { 50 80 public: 81 /// Constructor: Initializes all the values 51 82 ScopedSingletonManager(const std::string& className, ScopeID::Value scope) 52 83 : className_(className) … … 54 85 { } 55 86 virtual ~ScopedSingletonManager() { } 87 88 /// Adds a new instance of ScopedSingletonManager to the map. 56 89 static void addManager(ScopedSingletonManager* manager); 57 90 91 /// Calls preUpdate in all instances of ScopedSingletonManager that are registered in the map. 58 92 template<ScopeID::Value scope> 59 93 static void preUpdate(const Clock& time) … … 64 98 } 65 99 virtual void preUpdate(const Clock& time) = 0; 100 101 /// Calls postUpdate in all instances of ScopedSingletonManager that are registered in the map. 66 102 template<ScopeID::Value scope> 67 103 static void postUpdate(const Clock& time) … … 78 114 79 115 protected: 80 const std::string className_; 81 const ScopeID::Value scope_; 116 const std::string className_; ///< The name of the scoped singleton class that is managed by this object 117 const ScopeID::Value scope_; ///< The scope of the singleton that is managed by this object 82 118 }; 83 119 120 /** 121 @anchor ClassScopedSingletonManager 122 123 @brief Manages a scoped singleton for a given scope. 124 @param T The managed singleton class 125 @param scope The scope in which the singleton @a T should be active 126 @param allowedToFail If true, a specialization of this template is used, that uses try-catch blocks to handle possible failures. 127 128 This class inherits from ScopeListener for the given scope and thus its functions 129 activated() and deactivated() are called whenever the Scope changes its state. 130 131 If the Scope is activated, a new instance of @a T (which must be a singleton) is created. 132 If the Scope is deactivated, the singleton is destroyed. 133 134 @see Singleton 135 */ 84 136 template <class T, ScopeID::Value scope, bool allowedToFail> 85 137 class ClassScopedSingletonManager : public ScopedSingletonManager, public ScopeListener 86 138 { 87 139 public: 140 //! Constructor: Initializes the singleton pointer and passes the scope to ScopedSingletonManager and ScopeListener 88 141 ClassScopedSingletonManager(const std::string& className) 89 142 : ScopedSingletonManager(className, scope) … … 113 166 } 114 167 168 //! Destroys the singleton instance - overloaded for OrxonoxClass, calls OrxonoxClass::destroy() 115 169 void destroy(OrxonoxClass*) 116 170 { 117 171 singletonPtr_->destroy(); 118 172 } 173 //! Destroys the singleton instance - overloaded for all other pointers, calls delete 119 174 void destroy(void*) 120 175 { … … 139 194 140 195 private: 141 T* singletonPtr_; 196 T* singletonPtr_; ///< Unique instance of the singleton class @a T 142 197 }; 143 198 199 /** 200 @brief This class partially spezializes ClassScopedSingletonManager for classes @a T that are allowed to fail. 201 @param T The managed singleton class 202 @param scope The scope in which the singleton @a T should be active 203 204 Because @a T could fail when being created, this partial spezialization of ClassScopedSingletonManager 205 uses a try-catch block to handle exceptions. 206 207 See @ref ClassScopedSingletonManager for a full documentation of the basis template. 208 */ 144 209 template <class T, ScopeID::Value scope> 145 210 class ClassScopedSingletonManager<T, scope, true> : public ScopedSingletonManager, public ScopeListener 146 211 { 147 212 public: 213 //! Constructor: Initializes the singleton pointer and passes the scope to ScopedSingletonManager and ScopeListener 148 214 ClassScopedSingletonManager(const std::string& className) 149 215 : ScopedSingletonManager(className, scope) … … 180 246 } 181 247 248 //! Destroys the singleton instance - overloaded for OrxonoxClass, calls OrxonoxClass::destroy() 182 249 void destroy(OrxonoxClass* ptr) 183 250 { 184 251 singletonPtr_->destroy(); 185 252 } 253 //! Destroys the singleton instance - overloaded for void*, calls delete 186 254 void destroy(void* ptr) 187 255 { … … 208 276 209 277 private: 210 T* singletonPtr_; 278 T* singletonPtr_; ///< Unique instance of the singleton class @a T 211 279 }; 212 280 } -
code/trunk/src/libraries/util/Serialise.h
r7182 r7401 29 29 /** 30 30 @file 31 @ingroup Util 31 32 @brief Functions to serialise most of the types/classed used in Orxonox 32 33 */ … … 53 54 template <class T> inline bool checkEquality( const T& variable, uint8_t* mem ); 54 55 55 56 56 57 // =========== char* 57 58 58 59 inline uint32_t returnSize( char*& variable ) 59 60 { 60 61 return strlen(variable)+1; 61 62 } 62 63 63 64 inline void saveAndIncrease( char*& variable, uint8_t*& mem ) 64 65 { … … 66 67 mem += returnSize(variable); 67 68 } 68 69 69 70 inline void loadAndIncrease( char*& variable, uint8_t*& mem ) 70 71 { … … 76 77 mem += len; 77 78 } 78 79 79 80 inline bool checkEquality( char*& variable, uint8_t* mem ) 80 81 { 81 82 return strcmp(variable, (char*)mem)==0; 82 83 } 83 84 84 85 // =================== Template specialisation stuff ============= 85 86 … … 423 424 return memcmp(&temp, mem, sizeof(uint64_t))==0; 424 425 } 425 426 426 427 // =========== string 427 428 -
code/trunk/src/libraries/util/SharedPtr.cc
r7284 r7401 27 27 */ 28 28 29 /** 30 @file 31 @brief Static linkage of the SmallObjectAllocator used by SharedPtr. 32 */ 33 29 34 #include "SharedPtr.h" 30 35 31 36 namespace orxonox 32 37 { 33 SmallObjectAllocator& createSharedCounterPool()38 namespace detail 34 39 { 35 static SmallObjectAllocator instance(sizeof(SharedCounterImpl<void>)); 36 return instance; 40 SmallObjectAllocator& createSharedCounterPool() 41 { 42 static SmallObjectAllocator instance(sizeof(SharedCounterImpl<void>)); 43 return instance; 44 } 37 45 } 38 46 } -
code/trunk/src/libraries/util/SharedPtr.h
r7284 r7401 27 27 */ 28 28 29 /** 30 @defgroup SharedPtr SharedPtr<T> 31 @ingroup Util 32 */ 33 34 /** 35 @file 36 @ingroup SharedPtr 37 @brief Definition of the SharedPtr template that is used to manage pointers. 38 39 @anchor SharedPtrExample 40 41 The orxonox::SharedPtr template can be used to manage a pointer to an object 42 that was created with new. The SharedPtr acts like the pointer itself, but it 43 keeps track of the number of references to it. If all references are removed, 44 SharedPtr deletes the managed object automatically. 45 46 Example: 47 48 Classic implementation using new and delete: 49 @code 50 void someFunction() 51 { 52 MyClass* object = new MyClass(); // Create a new instance of MyClass 53 54 object->myFunction(); // Calls MyClass::myFunction() 55 56 delete object; // Delete the object at the end of the scope 57 } 58 @endcode 59 60 The same function using SharedPtr: 61 @code 62 void someFunction() 63 { 64 SharedPtr<MyClass> object = new MyClass(); // Create a new instance of MyClass and store its pointer in a SharedPtr 65 66 object->myFunction(); // Calls MyClass::myFunction() 67 68 } // At the end of the scope, the SharedPtr is destroyed. Because no other SharedPtrs 69 // point at the object, the object itself is also destroyed automatically 70 @endcode 71 72 This is especially handy if you do not know what will happen with an object that was 73 created with new, for example if you pass it to another object. If multiple instances 74 share a pointer to the same object, none of these instances can delete the object 75 without interfering with the other instances. But if none of the instances destroy the 76 object, it will never be destroyed and results in a memory leak. With a SharedPtr 77 however you don't have to think about destroying the object, because the SharedPtr 78 itself keeps track of the references. 79 80 Example: 81 82 Classic implementation using new and delete: 83 @code 84 class OtherClass // Declaration of some class 85 { 86 public: 87 OtherClass(MyClass* object) // Constructor 88 { 89 this->object_ = object; // Assigns the pointer to the member variable object_ 90 } 91 92 ~OtherClass() // Destructor 93 { 94 ??? // What to do with object_? 95 } 96 97 private: 98 MyClass* object_; // A pointer to the object 99 }; 100 101 void someFunction() 102 { 103 MyClass* object = new MyClass(); // Create a new instance of MyClass 104 105 OtherClass* other1 = new OtherClass(object); // Create an instance of OtherClass and pass the object pointer 106 OtherClass* other2 = new OtherClass(object); // " 107 OtherClass* other3 = new OtherClass(object); // " 108 109 ??? // What happens with object now? 110 } 111 @endcode 112 113 If you use SharedPtr<MyClass> instead of a classic MyClass* pointer, the instance of 114 MyClass would be automatically destroyed if all instances of OtherClass are destroyed. 115 You don't need any code in the destructor and you can completely forget about the 116 object, because its managed by the SharedPtr. 117 118 The same code using SharedPtr: 119 @code 120 class OtherClass // Declaration of some class 121 { 122 public: 123 OtherClass(const SharedPtr<MyClass>& object) // Constructor 124 { 125 this->object_ = object; // Assigns the pointer to the member variable object_ 126 } 127 128 private: 129 SharedPtr<MyClass> object_; // A SharedPtr to the object 130 }; 131 132 void someFunction() 133 { 134 SharedPtr<MyClass> object = new MyClass(); // Create a new instance of MyClass 135 136 OtherClass* other1 = new OtherClass(object); // Create an instance of OtherClass and pass the object pointer 137 OtherClass* other2 = new OtherClass(object); // " 138 OtherClass* other3 = new OtherClass(object); // " 139 140 } // The SmartPtr "object" is destroyed at the end of the scope, 141 // but the three instances of OtherClass keep the object alive 142 // until they are all destroyed. 143 @endcode 144 */ 145 29 146 #ifndef _SharedPtr_H__ 30 147 #define _SharedPtr_H__ … … 39 156 namespace orxonox 40 157 { 41 class SharedCounter 42 { 43 public: 44 SharedCounter() : count_(1) {} 45 virtual void destroy() = 0; 46 47 int count_; 48 }; 49 50 template <class T> 51 class SharedCounterImpl : public SharedCounter 52 { 53 public: 54 SharedCounterImpl(T* pointer) : pointer_(pointer) {} 55 56 void destroy() 57 { 58 delete this->pointer_; 59 } 60 61 private: 62 T* pointer_; 63 }; 64 65 _UtilExport SmallObjectAllocator& createSharedCounterPool(); 66 67 FORCEINLINE SmallObjectAllocator& getSharedCounterPool() 68 { 69 static SmallObjectAllocator& instance = createSharedCounterPool(); 70 return instance; 158 namespace detail 159 { 160 /// BaseClass of SharedCounterImpl, has a counter that is initialized with 1 161 class SharedCounter 162 { 163 public: 164 SharedCounter() : count_(1) {} 165 virtual void destroy() = 0; 166 167 int count_; 168 }; 169 170 /// Child class of SharedCounter, keeps a pointer to an object of type T that can be destroyed with destroy() 171 template <class T> 172 class SharedCounterImpl : public SharedCounter 173 { 174 public: 175 SharedCounterImpl(T* pointer) : pointer_(pointer) {} 176 177 void destroy() 178 { 179 delete this->pointer_; 180 } 181 182 private: 183 T* pointer_; 184 }; 185 186 _UtilExport SmallObjectAllocator& createSharedCounterPool(); 187 188 FORCEINLINE SmallObjectAllocator& getSharedCounterPool() 189 { 190 static SmallObjectAllocator& instance = createSharedCounterPool(); 191 return instance; 192 } 71 193 } 72 194 195 /** 196 @brief The SharedPtr template is a utility to manage pointers to an object. 197 @param T The type of the managed object 198 199 SharedPtr acts like a real pointer, except that it keeps track of the number of 200 references to the object. If the the number of references drops to zero, the 201 object is destroyed automatically. 202 203 @see See @ref SharedPtrExample "this description" for some examples and more information. 204 205 @note The number of references is stored in a separate object that is shared 206 among all instances of SharedPtr that point to the same pointer. This object is 207 also responsible for destroying the pointer if the reference counter becomes zero. 208 */ 73 209 template <class T> 74 210 class SharedPtr … … 78 214 79 215 public: 216 /// Default constructor, the pointer is set to NULL. 80 217 inline SharedPtr() : pointer_(0), counter_(0) 81 218 { 82 219 } 83 220 221 /// Constructor, creates a SharedPtr that points to @a pointer, increments the counter. 84 222 inline SharedPtr(T* pointer) : pointer_(pointer), counter_(0) 85 223 { 86 224 if (this->pointer_) 87 225 { 88 void* chunk = getSharedCounterPool().alloc();89 this->counter_ = new (chunk) SharedCounterImpl<T>(this->pointer_);226 void* chunk = detail::getSharedCounterPool().alloc(); 227 this->counter_ = new (chunk) detail::SharedCounterImpl<T>(this->pointer_); 90 228 } 91 229 } 92 230 231 /// Copy-constructor, this SharedPtr now points to the same object like the other SharedPtr, increments the counter. 93 232 inline SharedPtr(const SharedPtr& other) : pointer_(other.pointer_), counter_(other.counter_) 94 233 { … … 97 236 } 98 237 238 /// Copy-constructor for SharedPtr with another template agument, increments the counter. 99 239 template <class O> 100 240 inline SharedPtr(const SharedPtr<O>& other) : pointer_(other.pointer_), counter_(other.counter_) … … 104 244 } 105 245 246 /// Destructor, decrements the counter and deletes the object if the counter becomes zero. 106 247 inline ~SharedPtr() 107 248 { … … 113 254 { 114 255 this->counter_->destroy(); 115 getSharedCounterPool().free(this->counter_);256 detail::getSharedCounterPool().free(this->counter_); 116 257 } 117 258 } 118 259 } 119 260 261 /// Assigns a new object, decrements the counter of the old object, increments the counter of the new object. 120 262 inline SharedPtr& operator=(const SharedPtr& other) 121 263 { … … 124 266 } 125 267 268 /// Assigns a new object with another template argument, decrements the counter of the old object, increments the counter of the new object. 126 269 template <class O> 127 270 inline SharedPtr& operator=(const SharedPtr<O>& other) … … 131 274 } 132 275 276 /// Casts the pointer to another type 133 277 template <class O> 134 278 inline SharedPtr<O> cast() const … … 138 282 } 139 283 284 /// Overloaded -> operator, returns the pointer to the managed object. 140 285 inline T* operator->() const 141 286 { … … 144 289 } 145 290 291 /// Overloaded * operator, returns a reference ot the managed object. 146 292 inline T& operator*() const 147 293 { … … 150 296 } 151 297 298 /// Returns the pointer to the managed object. 152 299 inline T* get() const 153 300 { … … 155 302 } 156 303 304 /// Returns true if the pointer is not NULL. 157 305 inline operator bool() const 158 306 { … … 160 308 } 161 309 310 /// Swaps the pointer and the counter of two instances of SharedPtr with the same template argument. 162 311 inline void swap(SharedPtr& other) 163 312 { … … 167 316 168 317 private: 169 inline SharedPtr(T* pointer, SharedCounter* counter) : pointer_(pointer), counter_(counter) 318 /// Private constructor, used by the cast() function. 319 inline SharedPtr(T* pointer, detail::SharedCounter* counter) : pointer_(pointer), counter_(counter) 170 320 { 171 321 if (this->pointer_) … … 173 323 } 174 324 175 T* pointer_; 176 SharedCounter* counter_;325 T* pointer_; ///< A pointer to the managed object of type @a T 326 detail::SharedCounter* counter_; ///< A pointer to the shared reference counter 177 327 }; 178 328 329 /** 330 @brief A child class of SharedPtr, used to reflect the hierarchy of the underlying class @a T. 331 @param T The type of the managed object 332 @param Parent The type of the SharedPtr that manages the parent class of @a T 333 334 This class is used to reflect the hierarchy of the underlying class @a T. 335 For example the @c Functor classes: While a @c Functor* pointer would be managed by 336 @c SharedPtr<Functor>, the child class @c FunctorStatic is managed by the class 337 <tt>SharedChildPtr<FunctorStatic, SharedPtr<Functor> ></tt>. 338 339 The second template argument @a Parent is used as the parent class of 340 SharedChildPtr. This means that each instance of <tt>SharedChildPtr<T, Parent></tt> 341 can be upcasted to @c Parent. 342 343 So for example this works: 344 @code 345 SharedChildPtr<FunctorStatic, SharedPtr<Functor> > functorStatic = createFunctor(&MyClass::myStaticFunction); 346 SharedPtr<Functor> functor = functorStatic; 347 @endcode 348 349 @note There are some typedefs and more to make the usage of SharedChildPtr easier 350 for the classes Functor and Executor. See FunctorPtr.h and ExecutorPtr.h. The above 351 example could thus be simplified the following way: 352 @code 353 FunctorStaticPtr functorStatic = createFunctor(&MyClass::myStaticFunction); 354 FunctorPtr functor = functorStatic; 355 @endcode 356 357 @see See SharedPtr for more information about the base class SharedPtr. 358 @see See @ref SharedPtrExample "this description" for some examples about how to use SharedPtr. 359 */ 179 360 template <class T, class Parent> 180 361 class SharedChildPtr : public Parent -
code/trunk/src/libraries/util/SignalHandler.h
r5738 r7401 29 29 /** 30 30 @file 31 @ingroup Util 31 32 @brief Declaration of the SignalHandler class. 32 33 */ … … 68 69 typedef std::list<SignalCallbackRec> SignalCallbackList; 69 70 71 /// The SignalHandler is used to catch signals like SIGSEGV and write a backtrace to the logfile. 70 72 class SignalHandler : public Singleton<SignalHandler> 71 73 { … … 99 101 namespace orxonox 100 102 { 103 /// The SignalHandler is used to catch signals like SIGSEGV and write a backtrace to the logfile. Not implemented on Windows. 101 104 class _UtilExport SignalHandler : public Singleton<SignalHandler> 102 105 { -
code/trunk/src/libraries/util/Singleton.h
r7163 r7401 27 27 */ 28 28 29 /** 30 @defgroup SingletonScope Singletons and Scope 31 @ingroup Util 32 */ 33 34 /** 35 @file 36 @ingroup SingletonScope 37 @brief Definition of the Singleton template that is used as base class for classes that allow only one instance. 38 39 @anchor SingletonExample 40 41 Classes that inherit from orxonox::Singleton follow the singleton pattern and thus 42 allow only one instance of the class to exist. This istance is stored in a static 43 variable called @c singletonPtr_s. orxonox::Singleton will access this variable, but 44 it must be implemented in the deriving class. 45 46 Example: 47 @code 48 class TestSingleton : public Singleton<TestSingleton> // inherit from Singleton, pass the own class as template argument 49 { 50 friend class Singleton<TestSingleton>; // friend declaration so Singleton can access singletonPtr_s 51 52 public: 53 TestSingleton(); // public constructor because we may want to manage this singleton 54 // with an orxonox::ScopedSingletonManager (see below) 55 virtual ~TestSingleton(); // public destructor 56 57 void testFunction(); // put your functions here 58 59 private: 60 int testValue_; // put your variables here 61 62 static TestSingleton* singletonPtr_s; // static singleton instance pointer, used by the Singleton template 63 }; 64 @endcode 65 66 And don't forget to initialize the static singleton pointer in the source (*.cc) %file: 67 @code 68 TestSingleton* TestSingleton::singletonPtr_s = NULL; 69 @endcode 70 71 Usually a singleton gets created automatically when it is first used, but it will never 72 be destroyed (unless the singleton explicitly deletes itself). To allow controlled 73 construction and destruction, the singleton can be put within a virtual scope. This is 74 done by registering the singleton class with orxonox::ScopedSingletonManager. To 75 do so, the ManageScopedSingleton() macro has to be called: 76 77 @code 78 ManageScopedSingleton(TestSingleton, ScopeID::Graphics, false); // muste be called in a source (*.cc) file 79 @endcode 80 81 @b Important: If you call ManageScopedSingleton(), you don't have to initialize singletonPtr_s anymore, 82 because that's already done by the macro. 83 84 Now the singleton TestSingleton gets automatically created if the scope Graphics becomes 85 active and also gets destroyed if the scope is deactivated. 86 87 Note that not all singletons must register with a scope, but it's recommended. 88 89 If a class inherits from orxonox::Singleton, it also inherits its functions. The most important 90 function is orxonox::Singleton::getInstance() which returns a reference to the only instance 91 of the singleton. 92 93 Example: 94 @code 95 TestSingleton::TestSingleton() // implement the constructor 96 { 97 this->testValue_ = 15; 98 } 99 100 void TestSingleton::testFunction() // implement testFunction 101 { 102 COUT(0) << "My value is " << this->testValue_ << std::endl; 103 } 104 105 TestSingleton::getInstance().testFunction(); // prints "My value is 15" 106 @endcode 107 */ 108 29 109 #ifndef __Util_Singleton_H__ 30 110 #define __Util_Singleton_H__ … … 42 122 43 123 Usage: 44 Inherit publicly from Singleton<MyClass> and provide access to 45 MyClass::singletonPtr_s. 124 Inherit publicly from Singleton<MyClass> and provide access to MyClass::singletonPtr_s. 46 125 This can easily be done with a friend declaration. 126 127 See @ref SingletonExample "this example" for an exemplary implementation. 47 128 */ 48 129 template <class T> … … 80 161 } 81 162 82 //! Constructor resets the singleton instance pointer163 //! Destructor resets the singleton instance pointer 83 164 ~Singleton() 84 165 { -
code/trunk/src/libraries/util/SmallObjectAllocator.cc
r7284 r7401 27 27 */ 28 28 29 /** 30 @file 31 @brief Implementation of SmallObjectAllocator 32 */ 33 29 34 #include "SmallObjectAllocator.h" 30 35 31 36 namespace orxonox 32 37 { 38 /** 39 @brief Constructor: initializes the allocator and its values. 40 @param objectSize The size in bytes (returned by sizeof()) of the allocated objects 41 @param numObjects The number of objects that are allocated in one block of memory 42 */ 33 43 SmallObjectAllocator::SmallObjectAllocator(size_t objectSize, size_t numObjects) 34 44 { 35 this-> objectSize_ = std::max(objectSize, sizeof(Chunk));36 this->num Objects_ = numObjects;45 this->chunkSize_ = std::max(objectSize, sizeof(Chunk)); // the chunk's size will be the maximum of the object's size and the size of a Chunk object itself 46 this->numChunksPerBlock_ = numObjects; 37 47 this->first_ = 0; 38 48 } 39 49 50 /** 51 @brief Destructor: deletes the allocated memory blocks. 52 */ 40 53 SmallObjectAllocator::~SmallObjectAllocator() 41 54 { … … 44 57 } 45 58 59 /** 60 @brief Helper function, used to set the next_ pointer of a Chunk. 61 */ 46 62 /* static */ void SmallObjectAllocator::setNext(void* chunk, void* next) 47 63 { … … 49 65 } 50 66 67 /** 68 @brief Helper function, returns the next_ pointer of a Chunk 69 */ 51 70 /* static */ void* SmallObjectAllocator::getNext(void* chunk) 52 71 { … … 54 73 } 55 74 75 /** 76 @brief Returns the first free memory chunk or allocates a new block of memory. 77 */ 56 78 void* SmallObjectAllocator::alloc() 57 79 { 80 // get the first free chunk 58 81 void* chunk = this->first_; 59 82 83 // check if the chunk exists 60 84 if (chunk) 61 85 { 86 // yes it does - the first_ pointer now points to the second element in the list 62 87 this->first_ = getNext(chunk); 63 88 } 64 89 else 65 90 { 66 char* block = new char[this->objectSize_ * this->numObjects_]; 91 // no it doesnt - allocate a new block of memory 92 char* block = new char[this->chunkSize_ * this->numChunksPerBlock_]; 67 93 this->blocks_.push_back(block); 68 94 69 for (size_t i = 1; i < this->numObjects_ - 1; ++i) 70 setNext(block + i * this->objectSize_, block + (i + 1) * this->objectSize_); 95 // iterate through the chunks in the new memory block and link them together to a single linked list 96 for (size_t i = 1; i < this->numChunksPerBlock_ - 1; ++i) 97 setNext(block + i * this->chunkSize_, block + (i + 1) * this->chunkSize_); 71 98 72 setNext(block + (this->numObjects_ - 1) * this->objectSize_, 0); 99 // the next_ pointer of the last chunk must point to NULL 100 setNext(block + (this->numChunksPerBlock_ - 1) * this->chunkSize_, 0); 73 101 74 this->first_ = block + this->objectSize_; 102 // The second chunk in the block is assigned to the first_ pointer 103 this->first_ = block + this->chunkSize_; 75 104 105 // The first chunk in the block is returned 76 106 chunk = block; 77 107 } 78 108 109 // return the pointer to the chunk 79 110 return chunk; 80 111 } 81 112 113 /** 114 @brief Puts the memory chunk back on the list of free memory. 115 */ 82 116 void SmallObjectAllocator::free(void* chunk) 83 117 { 118 // The first_ pointer points to the freed chunk, its next_ pointer points to the rest of the list 84 119 setNext(chunk, this->first_); 85 120 this->first_ = chunk; -
code/trunk/src/libraries/util/SmallObjectAllocator.h
r7284 r7401 27 27 */ 28 28 29 /** 30 @defgroup SmallObjectAllocator SmallObjectAllocator 31 @ingroup Util 32 */ 33 34 /** 35 @file 36 @ingroup SmallObjectAllocator 37 @brief Declaration of SmallObjectAllocator 38 39 @anchor SmallObjectAllocatorExample 40 41 The default implementations of new and delete are designed to work with objects of 42 arbitrary size. They are thus not optimal for small objects. 43 @ref orxonox::SmallObjectAllocator "SmallObjectAllocator" allocates a large memory 44 block and divides it into small chunks. These chunks are returned by the function 45 @ref orxonox::SmallObjectAllocator::alloc() "alloc()" and can be used to create a 46 new object using the placement new operator. Instead of delete, the function 47 @ref orxonox::SmallObjectAllocator::free() "free()" is used to give the memory 48 back to SmallObjectAllocator. 49 50 Example: 51 @code 52 SmallObjectAllocator allocator(sizeof(MySmallObject)); // Create an allocator. The size of the memory chunks must equal the size of the desired class 53 54 void* chunk = allocator.alloc(); // Allocate a memory chunk 55 MySmallObject* object = new (chunk) MySmallObject(); // Call the placement new operator 56 57 object->someFunction(); // Do something with the object 58 59 object->~MySmallObject(); // Call the destructor 60 allocator.free(object); // Free the allocated memory 61 @endcode 62 63 @b Important: You have to call the destructor of the object manually, because this 64 is not automatically done by the allocator nor free(). 65 66 @note The destructor can be ignored if it is empty or not implemented. This saves 67 another amount of time. 68 69 @remarks For a distributed usage of SmallObjectAllocator it may be a good idea to 70 create a static function that returns an instance to it. The allocator then works 71 like a singleton and can be accesses from everywhere. 72 */ 73 29 74 #ifndef _SmallObjectAllocator_H__ 30 75 #define _SmallObjectAllocator_H__ … … 35 80 namespace orxonox 36 81 { 82 /** 83 @brief This class is used to allocate and free small objects (usually not polymorphic). 84 85 SmallObjectAllocator provides a fast alternative to new and delete for small objects. 86 87 @see See @ref SmallObjectAllocatorExample "this description" for more information and an example. 88 */ 37 89 class _UtilExport SmallObjectAllocator 38 90 { 91 /// The memory chunk is at the same time an element of a single linked list. 39 92 struct Chunk 40 93 { 41 Chunk* next_; 94 Chunk* next_; ///< A pointer to the next chunk in the list 42 95 }; 43 96 … … 53 106 static void* getNext(void* chunk); 54 107 55 void* first_; 56 size_t objectSize_;57 size_t num Objects_;108 void* first_; ///< A pointer to the first free memory chunk 109 size_t chunkSize_; ///< The size of each chunk (and usually also the size of the created objects) 110 size_t numChunksPerBlock_; ///< The number of chunks per memory block 58 111 59 std::vector<char*> blocks_; 112 std::vector<char*> blocks_; ///< A list of all allocated memory blocks (used to destroy them again) 60 113 }; 61 114 } -
code/trunk/src/libraries/util/StringUtils.cc
r7284 r7401 41 41 namespace orxonox 42 42 { 43 /// A blank string (""). Used to return a blank string by reference. 43 44 std::string BLANKSTRING; 44 45 46 /// Returns a string of a unique number. This function is guaranteed to never return the same string twice. 45 47 std::string getUniqueNumberString() 46 48 { … … 48 50 } 49 51 50 /** 51 @brief Removes all whitespaces from a string. 52 @param str The string to strip 53 */ 52 /// Removes all whitespaces from a string. 54 53 void strip(std::string* str) 55 54 { … … 63 62 } 64 63 65 /** 66 @brief Returns a copy of a string without whitespaces. 67 @param str The string to strip 68 @return The stripped line 69 */ 64 /// Returns a copy of a string without whitespaces. 70 65 std::string getStripped(const std::string& str) 71 66 { … … 75 70 } 76 71 77 /** 78 @brief Returns a copy of a string without trailing whitespaces. 79 @param str The string 80 @return The modified copy 81 */ 72 /// Returns a copy of a string without trailing whitespaces. 82 73 std::string removeTrailingWhitespaces(const std::string& str) 83 74 { … … 90 81 91 82 /** 92 @brief Returns the position of the next quot ein the string, starting with start.83 @brief Returns the position of the next quotation mark in the string, starting with start. 93 84 @param str The string 94 @param start The startposition95 @return The position of the next quot e (std::string::npos if there is no next quote)85 @param start The first position to look at 86 @return The position of the next quotation mark (@c std::string::npos if there is none) 96 87 */ 97 88 size_t getNextQuote(const std::string& str, size_t start) … … 115 106 116 107 /** 117 @brief Returns true if pos is between two quot es.108 @brief Returns true if pos is between two quotation marks. 118 109 @param str The string 119 110 @param pos The position to check 120 @return True if pos is between two quot es111 @return True if pos is between two quotation marks 121 112 */ 122 113 bool isBetweenQuotes(const std::string& str, size_t pos) … … 140 131 } 141 132 142 /** 143 @brief Returns true if the string contains something like '..."between quotes"...'. 144 @param The string 145 @return True if there is something between quotes 146 */ 133 /// Returns true if the string contains something like '..."between quotaton marks"...'. 147 134 bool hasStringBetweenQuotes(const std::string& str) 148 135 { … … 152 139 } 153 140 154 /** 155 @brief If the string contains something like '..."between quotes"...' then 'between quotes' gets returned (without quotes). 156 @param The string 157 @param The string between the quotes 158 */ 141 /// If the string contains something like '..."between quotaton marks"...' then 'between quotaton marks' gets returned, otherwise "". 159 142 std::string getStringBetweenQuotes(const std::string& str) 160 143 { … … 168 151 169 152 /** 170 @brief Removes enclosing quotes if available (including whitespaces at the outside of the quotes). 171 @brief str The string to strip 172 @return The string with removed quotes 153 @brief Removes enclosing quotation marks if available (including whitespaces at the outside of the quotation marks). 154 @return The striped string without quotation marks 173 155 */ 174 156 std::string stripEnclosingQuotes(const std::string& str) … … 208 190 209 191 /** 210 @brief Removes enclosing {braces} (braces must be exactly on the beginning and the end of the string). 211 @param str The string to strip 212 @return The striped string 192 @brief Removes enclosing braces '{' and '}' (the braces must be exactly on the beginning and the end of the string). 193 @return The striped string without braces 213 194 */ 214 195 std::string stripEnclosingBraces(const std::string& str) … … 224 205 /** 225 206 @brief Determines if a string is a comment (starts with a comment-symbol). 226 @param str The string to check227 @return True = it's a comment228 207 229 208 A comment is defined by a leading '#', '%', ';' or '//'. … … 253 232 } 254 233 255 /** 256 @brief Determines if a string is empty (contains only whitespaces). 257 @param str The string to check 258 @return True = it's empty 259 */ 234 /// Determines if a string is empty (contains only whitespaces). 260 235 bool isEmpty(const std::string& str) 261 236 { … … 263 238 } 264 239 265 /** 266 @brief Determines if a string contains only numbers and maximal one '.'. 267 @param str The string to check 268 @return True = it's a number 269 */ 240 /// Determines if a string contains only numbers and maximal one '.'. 270 241 bool isNumeric(const std::string& str) 271 242 { … … 288 259 /** 289 260 @brief Adds backslashes to the given string which makes special chars visible. Existing slashes will be doubled. 290 @param str The string to manipulate 291 @return The string with added slashes 261 262 This function converts all special chars like line breaks, tabs, quotation marks etc. into 263 a human readable format by adding a backslash. So for example "\n" will be converted to 264 "\\" + "n". 265 266 This is usually used when a string is written to a file. 267 268 @see removeSlashes 292 269 */ 293 270 std::string addSlashes(const std::string& str) … … 320 297 /** 321 298 @brief Removes backslashes from the given string. Double backslashes are interpreted as one backslash. 322 @param str The string to manipulate 323 @return The string with removed slashes 299 300 This function removes all backslashes and converts the human readable equivalents of 301 special chars like "\\" + "n" into their real meaning (in this case a line break or "\n"). 302 303 This is usually used when reading a string from a file. 304 305 @see addSlashes 324 306 */ 325 307 std::string removeSlashes(const std::string& str) … … 361 343 } 362 344 363 /** 364 @brief Replaces each char between A and Z with its lowercase equivalent. 365 @param str The string to convert 366 */ 345 /// Replaces each char between A and Z with its lowercase equivalent. 367 346 void lowercase(std::string* str) 368 347 { … … 373 352 } 374 353 375 /** 376 @brief Returns a copy of the given string without uppercase chars. 377 @param str The string 378 @return The copy 379 */ 354 /// Returns a copy of the given string where all chars are converted to lowercase. 380 355 std::string getLowercase(const std::string& str) 381 356 { … … 385 360 } 386 361 387 /** 388 @brief Replaces each char between a and z with its uppercase equivalent. 389 @param str The string to convert 390 */ 362 /// Replaces each char between a and z with its uppercase equivalent. 391 363 void uppercase(std::string* str) 392 364 { … … 397 369 } 398 370 399 /** 400 @brief Returns a copy of the given string without lowercase chars. 401 @param str The string 402 @return The copy 403 */ 371 /// Returns a copy of the given string where all chars are converted to uppercase. 404 372 std::string getUppercase(const std::string& str) 405 373 { … … 411 379 /** 412 380 @brief Compares two strings ignoring different casing. 413 @param s1 First string 414 @param s2 Second string 381 @return s1 == s1 -> returns 0 / s1 < s2 -> returns -1 / s1 >= s2 -> returns 1 415 382 */ 416 383 int nocaseCmp(const std::string& s1, const std::string& s2) … … 438 405 439 406 /** 440 @brief Compares the first 'len'chars of two strings ignoring different casing.407 @brief Compares the first @a len chars of two strings ignoring different casing. 441 408 @param s1 First string 442 409 @param s2 Second string … … 463 430 } 464 431 465 /** 466 @brief Returns true if the string contains a comment, introduced by #, %, ; or //. 432 /// Returns true if the string contains a comment, introduced by #, %, ; or //. 433 bool hasComment(const std::string& str) 434 { 435 return (getCommentPosition(str) != std::string::npos); 436 } 437 438 /// If the string contains a comment, the comment gets returned (including the comment symbol), an empty string otherwise. 439 std::string getComment(const std::string& str) 440 { 441 return str.substr(getCommentPosition(str)); 442 } 443 444 /// If the string contains a comment, the position of the comment-symbol gets returned, @c std::string::npos otherwise. 445 size_t getCommentPosition(const std::string& str) 446 { 447 return getNextCommentPosition(str, 0); 448 } 449 450 /** 451 @brief Returns the position of the next comment-symbol, starting with @a start. 467 452 @param str The string 468 @return True if the string contains a comment 469 */ 470 bool hasComment(const std::string& str) 471 { 472 return (getCommentPosition(str) != std::string::npos); 473 } 474 475 /** 476 @brief If the string contains a comment, the comment gets returned (including the comment symbol), an empty string otherwise. 477 @param str The string 478 @return The comment 479 */ 480 std::string getComment(const std::string& str) 481 { 482 return str.substr(getCommentPosition(str)); 483 } 484 485 /** 486 @brief If the string contains a comment, the position of the comment-symbol gets returned, std::string::npos otherwise. 487 @param str The string 488 @return The position 489 */ 490 size_t getCommentPosition(const std::string& str) 491 { 492 return getNextCommentPosition(str, 0); 493 } 494 495 /** 496 @brief Returns the position of the next comment-symbol, starting with start. 497 @param str The string 498 @param start The startposition 499 @return The position 453 @param start The first position to look at 500 454 */ 501 455 size_t getNextCommentPosition(const std::string& str, size_t start) -
code/trunk/src/libraries/util/StringUtils.h
r7284 r7401 28 28 29 29 /** 30 @defgroup String String functions 31 @ingroup Util 32 */ 33 34 /** 30 35 @file 36 @ingroup String 31 37 @brief Declaration of several string manipulation functions, used in many parts of the game. 32 38 */ -
code/trunk/src/libraries/util/SubString.cc
r7284 r7401 38 38 */ 39 39 40 /** 41 @file 42 @brief Implementation of the SubString class. 43 */ 44 40 45 #include "SubString.h" 41 46 #include <cstdio> 47 #include "Debug.h" 42 48 43 49 namespace orxonox 44 50 { 45 /** 46 * @brief default constructor 47 */ 51 const std::string SubString::WhiteSpaces = " \n\t"; 52 const std::string SubString::WhiteSpacesWithComma = " \n\t,"; 53 const SubString SubString::NullSubString = SubString(); 54 55 /** 56 @brief Default constructor. 57 */ 48 58 SubString::SubString() 49 {} 50 51 52 /** 53 * @brief create a SubString from 54 * @param string the String to Split 55 * @param delimiter the Character at which to split string (delimiter) 56 */ 57 SubString::SubString(const std::string& string, char delimiter) 58 { 59 this->split(string, delimiter); 60 } 61 62 63 /** 64 * @brief Splits a String into multiple splitters. 65 * @param string the String to split 66 * @param delimiters multiple set of characters at what to split. (delimiters) 67 * @param delimiterNeighbours neighbours of the delimiters, that will be erased only when near a delimiter. 68 * @param emptyEntries If empty entries should be allewed or removed. 69 * @param escapeChar The Escape Character that overrides splitters commends and so on... 70 * @param safemode_char within these characters splitting won't happen 71 * @param comment_char the Comment character. 72 */ 73 SubString::SubString(const std::string& string, 74 const std::string& delimiters, const std::string& delimiterNeighbours, bool emptyEntries, 75 char escapeChar, bool removeEscapeChar, char safemode_char, bool removeSafemodeChar, 76 char openparenthesis_char, char closeparenthesis_char, bool removeParenthesisChars, char comment_char) 77 { 78 SubString::splitLine(this->strings, this->bInSafemode, string, delimiters, delimiterNeighbours, emptyEntries, escapeChar, removeEscapeChar, safemode_char, removeSafemodeChar, openparenthesis_char, closeparenthesis_char, removeParenthesisChars, comment_char); 79 } 80 81 /** 82 * @brief creates a SubSet of a SubString. 83 * @param subString the SubString to take a set from. 84 * @param subSetBegin the beginning to the end 85 */ 86 SubString::SubString(const SubString& subString, unsigned int subSetBegin) 87 { 88 for (unsigned int i = subSetBegin; i < subString.size(); i++) 89 { 90 this->strings.push_back(subString[i]); 91 this->bInSafemode.push_back(subString.isInSafemode(i)); 92 } 93 } 94 95 96 /** 97 * @brief creates a SubSet of a SubString. 98 * @param subString the SubString to take a Set from 99 * @param subSetBegin the beginning to the end 100 * @param subSetEnd the end of the SubSet (max subString.size() will be checked internaly) 101 */ 102 SubString::SubString(const SubString& subString, unsigned int subSetBegin, unsigned int subSetEnd) 103 { 104 for (unsigned int i = subSetBegin; i < subString.size() && i < subSetEnd; i++) 105 { 106 this->strings.push_back(subString[i]); 107 this->bInSafemode.push_back(subString.isInSafemode(i)); 108 } 109 } 110 111 /** 112 * @brief creates a Substring from a count and values set. 113 * @param argc: the Arguments Count. 114 * @param argv: Argument Values. 115 */ 59 { 60 } 61 62 /** 63 @brief Splits a string into multiple tokens. 64 @param line The line to split 65 @param delimiters Multiple characters at which to split the line 66 @param delimiterNeighbours Neighbours of the delimiters that will be erased as well (for example white-spaces) 67 @param bAllowEmptyEntries If true, empty tokens are also added to the SubString (if there are two delimiters without a char in between) 68 @param escapeChar The escape character that is used to escape safemode chars (for example if you want to use a quotation mark between two other quotation marks). 69 @param bRemoveEscapeChar If true, the escape char is removed from the tokens 70 @param safemodeChar Within these characters splitting won't happen (usually the quotation marks) 71 @param bRemoveSafemodeChar Removes the safemodeChar from the beginning and the ending of a token 72 @param openparenthesisChar The beginning of a safemode is marked with this (usually an opening brace) 73 @param closeparenthesisChar The ending of a safemode is marked with this (usually a closing brace) 74 @param bRemoveParenthesisChars Removes the parenthesis chars from the beginning and the ending of a token 75 @param commentChar The comment character (used to ignore the part of the line after the comment char). 76 */ 77 SubString::SubString(const std::string& line, 78 const std::string& delimiters, const std::string& delimiterNeighbours, bool bAllowEmptyEntries, 79 char escapeChar, bool bRemoveEscapeChar, char safemodeChar, bool bRemoveSafemodeChar, 80 char openparenthesisChar, char closeparenthesisChar, bool bRemoveParenthesisChars, char commentChar) 81 { 82 SubString::splitLine(this->tokens_, this->bTokenInSafemode_, line, delimiters, delimiterNeighbours, bAllowEmptyEntries, escapeChar, bRemoveEscapeChar, safemodeChar, bRemoveSafemodeChar, openparenthesisChar, closeparenthesisChar, bRemoveParenthesisChars, commentChar); 83 } 84 85 /** 86 @brief creates a new SubString based on a subset of an other SubString. 87 @param other The other SubString 88 @param begin The beginning of the subset 89 90 The subset ranges from the token with index @a begin to the end of the tokens. 91 If @a begin is greater than the greatest index, the new SubString will be empty. 92 */ 93 SubString::SubString(const SubString& other, unsigned int begin) 94 { 95 for (unsigned int i = begin; i < other.size(); ++i) 96 { 97 this->tokens_.push_back(other[i]); 98 this->bTokenInSafemode_.push_back(other.isInSafemode(i)); 99 } 100 } 101 102 /** 103 @brief creates a new SubString based on a subset of an other SubString. 104 @param other The other SubString 105 @param begin The beginning of the subset 106 @param end The end of the subset 107 108 The subset ranges from the token with index @a begin until (but not including) the token with index @a end. 109 If @a begin or @a end are beyond the allowed index, the resulting SubString will be empty. 110 */ 111 SubString::SubString(const SubString& other, unsigned int begin, unsigned int end) 112 { 113 for (unsigned int i = begin; i < std::min(other.size(), end); ++i) 114 { 115 this->tokens_.push_back(other[i]); 116 this->bTokenInSafemode_.push_back(other.isInSafemode(i)); 117 } 118 } 119 120 /** 121 @brief Creates a SubString from a count and values set. 122 @param argc The number of arguments 123 @param argv An array of pointers to the arguments 124 */ 116 125 SubString::SubString(unsigned int argc, const char** argv) 117 126 { 118 127 for(unsigned int i = 0; i < argc; ++i) 119 128 { 120 this-> strings.push_back(std::string(argv[i]));121 this->b InSafemode.push_back(false);122 } 123 } 124 125 /** 126 * @brief removes the object from memory127 129 this->tokens_.push_back(std::string(argv[i])); 130 this->bTokenInSafemode_.push_back(false); 131 } 132 } 133 134 /** 135 @brief Destructor 136 */ 128 137 SubString::~SubString() 129 138 { } 130 139 131 /** @brief An empty String */ 132 // const std::string SubString::emptyString = ""; 133 /** @brief Helper that gets you a String consisting of all White Spaces */ 134 const std::string SubString::WhiteSpaces = " \n\t"; 135 /** @brief Helper that gets you a String consisting of all WhiteSpaces and the Comma */ 136 const std::string SubString::WhiteSpacesWithComma = " \n\t,"; 137 /** An Empty SubString */ 138 const SubString SubString::NullSubString = SubString(); 139 140 /** 141 * @brief stores the Value of subString in this SubString 142 * @param subString will be copied into this String. 143 * @returns this SubString. 144 */ 145 SubString& SubString::operator=(const SubString& subString) 146 { 147 this->strings = subString.strings; 148 this->bInSafemode = subString.bInSafemode; 140 /** 141 @brief Stores the tokens of @a other in this SubString 142 @return This SubString. 143 */ 144 SubString& SubString::operator=(const SubString& other) 145 { 146 this->tokens_ = other.tokens_; 147 this->bTokenInSafemode_ = other.bTokenInSafemode_; 149 148 return *this; 150 149 } 151 150 152 153 /** 154 * @brief comparator. 155 * @param subString the SubString to compare against this one. 156 * @returns true if the Stored Strings match 157 */ 158 bool SubString::operator==(const SubString& subString) const 159 { 160 return ((this->strings == subString.strings) && (this->bInSafemode == subString.bInSafemode)); 161 } 162 163 /** 164 * @brief comparator. 165 * @param subString the SubString to compare against this one. 166 * @returns true if the Stored Strings match 167 */ 168 bool SubString::compare(const SubString& subString) const 169 { 170 return (*this == subString); 171 } 172 173 /** 174 * @brief comparator. 175 * @param subString the SubString to compare against this one. 176 * @param length how many entries to compare. (from 0 to length) 177 * @returns true if the Stored Strings match 178 */ 179 bool SubString::compare(const SubString& subString, unsigned int length) const 180 { 181 if (length > this->size() || length > subString.size()) 151 /** 152 @brief Compares this SubString to another SubString and returns true if they contain the same values. 153 */ 154 bool SubString::operator==(const SubString& other) const 155 { 156 return ((this->tokens_ == other.tokens_) && (this->bTokenInSafemode_ == other.bTokenInSafemode_)); 157 } 158 159 /** 160 @copydoc operator== 161 */ 162 bool SubString::compare(const SubString& other) const 163 { 164 return (*this == other); 165 } 166 167 /** 168 @brief Compares this SubString to another SubString and returns true if the first @a length values match. 169 @param other The other SubString 170 @param length How many tokens to compare 171 */ 172 bool SubString::compare(const SubString& other, unsigned int length) const 173 { 174 if (length > this->size() || length > other.size()) 182 175 return false; 183 176 184 for (unsigned int i = 0; i < length; i++)185 if ((this-> strings[i] != subString.strings[i]) || (this->bInSafemode[i] != subString.bInSafemode[i]))177 for (unsigned int i = 0; i < length; ++i) 178 if ((this->tokens_[i] != other.tokens_[i]) || (this->bTokenInSafemode_[i] != other.bTokenInSafemode_[i])) 186 179 return false; 187 180 return true; 188 181 } 189 182 190 191 /** 192 * @brief append operator 193 * @param subString the String to append. 194 * @returns a SubString where this and subString are appended. 195 */ 196 SubString SubString::operator+(const SubString& subString) const 197 { 198 return SubString(*this) += subString; 199 } 200 201 202 /** 203 * @brief append operator. 204 * @param subString append subString to this SubString. 205 * @returns this substring appended with subString 206 */ 207 SubString& SubString::operator+=(const SubString& subString) 208 { 209 for (unsigned int i = 0; i < subString.size(); i++) 210 { 211 this->strings.push_back(subString[i]); 212 this->bInSafemode.push_back(subString.isInSafemode(i)); 183 /** 184 @brief Concatenates the tokens of two SubStrings and returns the resulting new SubString 185 @return A new SubString that contains the tokens of this and the other SubString 186 */ 187 SubString SubString::operator+(const SubString& other) const 188 { 189 return SubString(*this) += other; 190 } 191 192 /** 193 @brief Appends the tokens of @a other to this SubString 194 @return This SubString 195 */ 196 SubString& SubString::operator+=(const SubString& other) 197 { 198 for (unsigned int i = 0; i < other.size(); ++i) 199 { 200 this->tokens_.push_back(other[i]); 201 this->bTokenInSafemode_.push_back(other.isInSafemode(i)); 213 202 } 214 203 return *this; 215 204 } 216 205 217 218 /** 219 * @brief Split the String at 220 * @param string where to split 221 * @param splitter delimiter. 222 */ 223 unsigned int SubString::split(const std::string& string, char splitter) 224 { 225 this->strings.clear(); 226 this->bInSafemode.clear(); 227 char split[2]; 228 split[0] = splitter; 229 split[1] = '\0'; 230 SubString::splitLine(this->strings, this->bInSafemode, string, split); 231 return strings.size(); 232 } 233 234 235 /** 236 * @brief Splits a String into multiple splitters. 237 * @param string the String to split 238 * @param delimiters multiple set of characters at what to split. (delimiters) 239 * @param delimiterNeighbours: Neighbours to the Delimiters that will be erased too. 240 * @param emptyEntries: If empty entries are added to the List of SubStrings 241 * @param escapeChar The Escape Character that overrides splitters commends and so on... 242 * @param safemode_char within these characters splitting won't happen 243 * @param comment_char the Comment character. 244 */ 245 unsigned int SubString::split(const std::string& string, 246 const std::string& delimiters, const std::string& delimiterNeighbours, bool emptyEntries, 247 char escapeChar, bool removeExcapeChar, char safemode_char, bool removeSafemodeChar, 248 char openparenthesis_char, char closeparenthesis_char, bool removeParenthesisChars, char comment_char) 249 { 250 this->strings.clear(); 251 this->bInSafemode.clear(); 252 SubString::splitLine(this->strings, this->bInSafemode, string, delimiters, delimiterNeighbours, emptyEntries, escapeChar, removeExcapeChar, safemode_char, removeSafemodeChar, openparenthesis_char, closeparenthesis_char, removeParenthesisChars, comment_char); 253 return this->strings.size(); 254 } 255 256 257 /** 258 * @brief joins together all Strings of this Substring. 259 * @param delimiter the String between the subStrings. 260 * @returns the joined String. 261 */ 206 /** 207 @copydoc SubString(const std::string&,const std::string&,const std::string&,bool,char,bool,char,bool,char,char,bool,char) 208 */ 209 unsigned int SubString::split(const std::string& line, 210 const std::string& delimiters, const std::string& delimiterNeighbours, bool bAllowEmptyEntries, 211 char escapeChar, bool bRemoveEscapeChar, char safemodeChar, bool bRemoveSafemodeChar, 212 char openparenthesisChar, char closeparenthesisChar, bool bRemoveParenthesisChars, char commentChar) 213 { 214 this->tokens_.clear(); 215 this->bTokenInSafemode_.clear(); 216 SubString::splitLine(this->tokens_, this->bTokenInSafemode_, line, delimiters, delimiterNeighbours, bAllowEmptyEntries, escapeChar, bRemoveEscapeChar, safemodeChar, bRemoveSafemodeChar, openparenthesisChar, closeparenthesisChar, bRemoveParenthesisChars, commentChar); 217 return this->tokens_.size(); 218 } 219 220 /** 221 @brief Joins the tokens of this SubString using the given delimiter and returns a string. 222 @param delimiter This delimiter will be placed between each two tokens 223 @return The joined string. 224 */ 262 225 std::string SubString::join(const std::string& delimiter) const 263 226 { 264 if (!this-> strings.empty())265 { 266 std::string retVal = this-> strings[0];267 for (unsigned int i = 1; i < this-> strings.size(); i++)268 retVal += delimiter + this-> strings[i];227 if (!this->tokens_.empty()) 228 { 229 std::string retVal = this->tokens_[0]; 230 for (unsigned int i = 1; i < this->tokens_.size(); ++i) 231 retVal += delimiter + this->tokens_[i]; 269 232 return retVal; 270 233 } … … 273 236 } 274 237 275 276 /** 277 * @brief creates a SubSet of a SubString. 278 * @param subSetBegin the beginning to the end 279 * @returns the SubSet 280 * 281 * This function is added for your convenience, and does the same as 282 * SubString::SubString(const SubString& subString, unsigned int subSetBegin) 283 */ 284 SubString SubString::subSet(unsigned int subSetBegin) const 285 { 286 return SubString(*this, subSetBegin); 287 } 288 289 290 /** 291 * @brief creates a SubSet of a SubString. 292 * @param subSetBegin the beginning to 293 * @param subSetEnd the end of the SubSet to select (if bigger than subString.size() it will be downset.) 294 * @returns the SubSet 295 * 296 * This function is added for your convenience, and does the same as 297 * SubString::SubString(const SubString& subString, unsigned int subSetBegin) 298 */ 299 SubString SubString::subSet(unsigned int subSetBegin, unsigned int subSetEnd) const 300 { 301 return SubString(*this, subSetBegin, subSetEnd); 302 } 303 304 305 /** 306 * @brief splits line into tokens and stores them in ret. 307 * @param ret the Array, where the Splitted strings will be stored in 308 * to the beginning of the current token is stored 309 * @param line the inputLine to split 310 * @param delimiters a String of Delimiters (here the input will be splitted) 311 * @param delimiterNeighbours Neighbours to the Delimiter, that will be removed if they are to the left or the right of a Delimiter. 312 * @param emptyEntries: if empty Strings are added to the List of Strings. 313 * @param escape_char: Escape carater (escapes splitters) 314 * @param safemode_char: the beginning of the safemode is marked with this 315 * @param removeSafemodeChar removes the safemode_char from the beginning and the ending of a token 316 * @param openparenthesis_char the beginning of a safemode is marked with this 317 * @param closeparenthesis_char the ending of a safemode is marked with this 318 * @param removeParenthesisChars removes the parenthesis from the beginning and the ending of a token 319 * @param comment_char: the beginning of a comment is marked with this: (until the end of a Line) 320 * @param start_state: the Initial state on how to parse the String. 321 * @return SPLIT_LINE_STATE the parser was in when returning 322 * 323 * This is the Actual Splitting Algorithm from Clemens Wacha 324 * Supports delimiters, escape characters, 325 * ignores special characters between safemode_char and between comment_char and linend '\n'. 326 */ 238 /** 239 @brief Creates a subset of this SubString. 240 @param begin The beginning of the subset 241 @return A new SubString containing the defined subset. 242 243 The subset ranges from the token with index @a begin to the end of the tokens. 244 If @a begin is greater than the greatest index, the new SubString will be empty. 245 246 This function is added for your convenience, and does the same as 247 SubString::SubString(const SubString& other, unsigned int begin) 248 */ 249 SubString SubString::subSet(unsigned int begin) const 250 { 251 return SubString(*this, begin); 252 } 253 254 /** 255 @brief Creates a subset of this SubString. 256 @param begin The beginning of the subset 257 @param end The ending of the subset 258 @return A new SubString containing the defined subset. 259 260 The subset ranges from the token with index @a begin until (but not including) the token with index @a end. 261 If @a begin or @a end are beyond the allowed index, the resulting SubString will be empty. 262 263 This function is added for your convenience, and does the same as 264 SubString::SubString(const SubString& other, unsigned int begin, unsigned int end) 265 */ 266 SubString SubString::subSet(unsigned int begin, unsigned int end) const 267 { 268 return SubString(*this, begin, end); 269 } 270 271 /** 272 @copydoc SubString(const std::string&,const std::string&,const std::string&,bool,char,bool,char,bool,char,char,bool,char) 273 @param tokens The array, where the splitted strings will be stored in 274 @param bTokenInSafemode A vector wich stores for each character of the string if it is in safemode or not 275 @param start_state The internal state of the parser 276 277 This is the actual splitting algorithm from Clemens Wacha. 278 Supports delimiters, escape characters, ignores special characters between safemodeChar and between commentChar and line end "\n". 279 280 Extended by Orxonox to support parenthesis as additional safe-mode. 281 */ 327 282 SubString::SPLIT_LINE_STATE 328 SubString::splitLine(std::vector<std::string>& ret,329 std::vector<bool>& b InSafemode,283 SubString::splitLine(std::vector<std::string>& tokens, 284 std::vector<bool>& bTokenInSafemode, 330 285 const std::string& line, 331 286 const std::string& delimiters, 332 287 const std::string& delimiterNeighbours, 333 bool emptyEntries,334 char escape _char,335 bool removeExcapeChar,336 char safemode _char,337 bool removeSafemodeChar,338 char openparenthesis _char,339 char closeparenthesis _char,340 bool removeParenthesisChars,341 char comment _char,288 bool bAllowEmptyEntries, 289 char escapeChar, 290 bool bRemoveEscapeChar, 291 char safemodeChar, 292 bool bRemoveSafemodeChar, 293 char openparenthesisChar, 294 char closeparenthesisChar, 295 bool bRemoveParenthesisChars, 296 char commentChar, 342 297 SPLIT_LINE_STATE start_state) 343 298 { … … 349 304 bool inSafemode = false; 350 305 351 if(start_state != SL_NORMAL && ret.size() > 0)352 { 353 token = ret[ret.size()-1];354 ret.pop_back();355 } 356 if(start_state != SL_NORMAL && b InSafemode.size() > 0)357 { 358 inSafemode = b InSafemode[bInSafemode.size()-1];359 b InSafemode.pop_back();306 if(start_state != SL_NORMAL && tokens.size() > 0) 307 { 308 token = tokens[tokens.size()-1]; 309 tokens.pop_back(); 310 } 311 if(start_state != SL_NORMAL && bTokenInSafemode.size() > 0) 312 { 313 inSafemode = bTokenInSafemode[bTokenInSafemode.size()-1]; 314 bTokenInSafemode.pop_back(); 360 315 } 361 316 … … 365 320 { 366 321 case SL_NORMAL: 367 if(line[i] == escape _char)322 if(line[i] == escapeChar) 368 323 { 369 324 state = SL_ESCAPE; 370 if (! removeExcapeChar)325 if (!bRemoveEscapeChar) 371 326 token += line[i]; 372 } 373 else if(line[i] == safemode_char) 327 fallBackNeighbours = 0; 328 } 329 else if(line[i] == safemodeChar) 374 330 { 375 331 state = SL_SAFEMODE; 376 332 inSafemode = true; 377 if (! removeSafemodeChar)333 if (!bRemoveSafemodeChar) 378 334 token += line[i]; 379 } 380 else if(line[i] == openparenthesis_char) 335 fallBackNeighbours = 0; 336 } 337 else if(line[i] == openparenthesisChar) 381 338 { 382 339 state = SL_PARENTHESES; 383 340 inSafemode = true; 384 if (! removeParenthesisChars)341 if (!bRemoveParenthesisChars) 385 342 token += line[i]; 386 } 387 else if(line[i] == comment_char) 343 fallBackNeighbours = 0; 344 } 345 else if(line[i] == commentChar) 388 346 { 389 347 if (fallBackNeighbours > 0) 390 348 token = token.substr(0, token.size() - fallBackNeighbours); 391 /// FINISH 392 if(emptyEntries || token.size() > 0) 349 fallBackNeighbours = 0; 350 // FINISH 351 if(bAllowEmptyEntries || token.size() > 0) 393 352 { 394 ret.push_back(token);353 tokens.push_back(token); 395 354 token.clear(); 396 b InSafemode.push_back(inSafemode);355 bTokenInSafemode.push_back(inSafemode); 397 356 inSafemode = false; 398 357 } … … 405 364 if (fallBackNeighbours > 0) 406 365 token = token.substr(0, token.size() - fallBackNeighbours); 407 /// FINISH 408 if(emptyEntries || token.size() > 0) 366 fallBackNeighbours = 0; 367 // FINISH 368 if(bAllowEmptyEntries || token.size() > 0) 409 369 { 410 ret.push_back(token);370 tokens.push_back(token); 411 371 token.clear(); 412 b InSafemode.push_back(inSafemode);372 bTokenInSafemode.push_back(inSafemode); 413 373 inSafemode = false; 414 374 } … … 423 383 else 424 384 { 425 i++;385 ++i; 426 386 continue; 427 387 } … … 433 393 break; 434 394 case SL_ESCAPE: 435 if (! removeSafemodeChar)395 if (!bRemoveSafemodeChar) 436 396 token += line[i]; 437 397 else … … 450 410 break; 451 411 case SL_SAFEMODE: 452 if(line[i] == safemode _char)412 if(line[i] == safemodeChar) 453 413 { 454 414 state = SL_NORMAL; 455 if (! removeSafemodeChar)415 if (!bRemoveSafemodeChar) 456 416 token += line[i]; 457 417 } 458 else if(line[i] == escape _char)418 else if(line[i] == escapeChar) 459 419 { 460 420 state = SL_SAFEESCAPE; … … 480 440 481 441 case SL_PARENTHESES: 482 if(line[i] == closeparenthesis _char)442 if(line[i] == closeparenthesisChar) 483 443 { 484 444 state = SL_NORMAL; 485 if (! removeParenthesisChars)445 if (!bRemoveParenthesisChars) 486 446 token += line[i]; 487 447 } 488 else if(line[i] == escape _char)448 else if(line[i] == escapeChar) 489 449 { 490 450 state = SL_PARENTHESESESCAPE; … … 512 472 if(line[i] == '\n') 513 473 { 514 // /FINISH474 // FINISH 515 475 if(token.size() > 0) 516 476 { 517 ret.push_back(token);477 tokens.push_back(token); 518 478 token.clear(); 519 b InSafemode.push_back(inSafemode);479 bTokenInSafemode.push_back(inSafemode); 520 480 inSafemode = false; 521 481 } … … 532 492 break; 533 493 } 534 i++;535 } 536 537 // /FINISH494 ++i; 495 } 496 497 // FINISH 538 498 if (fallBackNeighbours > 0) 539 499 token = token.substr(0, token.size() - fallBackNeighbours); 540 if( emptyEntries || token.size() > 0)541 { 542 ret.push_back(token);500 if(bAllowEmptyEntries || token.size() > 0) 501 { 502 tokens.push_back(token); 543 503 token.clear(); 544 b InSafemode.push_back(inSafemode);504 bTokenInSafemode.push_back(inSafemode); 545 505 inSafemode = false; 546 506 } … … 548 508 } 549 509 550 551 /** 552 * @brief Some nice debug information about this SubString 553 */ 510 /** 511 @brief Some nice debug information about this SubString. 512 */ 554 513 void SubString::debug() const 555 514 { 556 printf("Substring-information::count=%d ::", this->strings.size());557 for (unsigned int i = 0; i < this-> strings.size(); i++)558 printf("s%d='%s'::", i, this->strings[i].c_str());559 printf("\n");515 COUT(0) << "Substring-information::count=" << this->tokens_.size() << " ::"; 516 for (unsigned int i = 0; i < this->tokens_.size(); ++i) 517 COUT(0) << "s" << i << "='" << this->tokens_[i].c_str() << "'::"; 518 COUT(0) << std::endl; 560 519 } 561 520 } -
code/trunk/src/libraries/util/SubString.h
r7284 r7401 37 37 */ 38 38 39 /*! 40 * @file 41 * @brief a small class to get the parts of a string separated by commas 42 * 43 * This class is also identified as a Tokenizer. It splits up one long 44 * String into multiple small ones by a designated Delimiter. 45 * 46 * Substring is Advanced, and it is possible, to split a string by ',' 47 * but also removing leading and trailing spaces around the comma. 48 * 49 * @example 50 * Split the String std::string st = "1345, The new empire , is , orxonox" 51 * is splitted with: 52 * SubString(st, ',', " \n\t") 53 * into 54 * "1345", "The new empire", "is", "orxonox" 55 * As you can see, the useless spaces around ',' were removed. 56 */ 39 /** 40 @file 41 @ingroup String 42 @brief A helper class to split a string into several tokens. 43 44 @anchor SubStringExample 45 46 The class SubString can be used to split an std::string into multiple tokens, using 47 a delimiter. SubString allows different options, for example to remove whitespaces 48 around the delimiters or different safe-mode chars, like quotation marks and braces. 49 50 You can access the tokens of the SubString using the [] operator like an array. 51 SubString also supports to join the tokens (or a subset of the tokens) again using 52 @ref orxonox::SubString::join() "join()". It's even possible to get a subset of the 53 SubString as another SubString using @ref orxonox::SubString::subSet() "subSet()". 54 55 Example: 56 @code 57 std::string text = "This is a test, \"Hello \\\" World\" and vector {1, 2, 3}"; 58 SubString tokens(text, SubString::WhiteSpaces, "", false, '\\', true, '"', true, '{', '}', true, '\0'); 59 60 for (unsigned int i = 0; i < tokens.size(); ++i) 61 COUT(0) << i << ": " << tokens[i] << std::endl; 62 @endcode 63 64 The output of this code is: 65 - 0: This 66 - 1: is 67 - 2: a 68 - 3: test, 69 - 4: Hello " World 70 - 5: and 71 - 6: vector 72 - 7: 1, 2, 3 73 74 The string was split using the delimiter " ". A string between quotation mark is not 75 split, the same holds for strings between '{' and '}'. Note how the quotation marks and 76 the braces were removed from the tokens, because the corresponding argument is 'true'. 77 78 Also note that the comma after "test" in token 3 is still there - it is neither part of the 79 delimiters SubString::WhiteSpaces nor part of the delimiterNeighbours parameter, so it 80 remains a part of the token. 81 */ 57 82 58 83 #ifndef __SubString_H__ … … 66 91 namespace orxonox 67 92 { 68 //! A class that can load one string and split it in multipe ones69 93 /** 70 * SubString is a very Powerfull way to create a SubSet from a String 71 * It can be used, to Split strings append them and join them again. 72 */ 94 @brief A class that splits a string into multiple tokens using different options. 95 96 The string is split into multiple tokens using a delimiter. Different options like 97 escape character, quotation marks, and more can be used to satisfy your needs. 98 99 See @ref SubStringExample "this description" for an example. 100 */ 73 101 class _UtilExport SubString 74 102 { 75 public:76 //! An enumerator for the State the Parser is in77 typedef enum{103 /// An enumerator for the internal state of the parser 104 enum SPLIT_LINE_STATE 105 { 78 106 SL_NORMAL, //!< Normal state 79 107 SL_ESCAPE, //!< After an escape character 80 SL_SAFEMODE, //!< In safe mode ( between "" mostly).108 SL_SAFEMODE, //!< In safe mode (usually between quotation marks). 81 109 SL_SAFEESCAPE, //!< In safe mode with the internal escape character, that escapes even the savemode character. 82 110 SL_COMMENT, //!< In Comment mode. 83 111 SL_PARENTHESES, //!< Between parentheses (usually '{' and '}') 84 112 SL_PARENTHESESESCAPE, //!< Between parentheses with the internal escape character, that escapes even the closing paranthesis character. 85 } SPLIT_LINE_STATE; 86 113 }; 87 114 88 115 public: 89 116 SubString(); 90 SubString(const std::string& string, char delimiter = ','); 91 SubString(const std::string& string, 92 const std::string& delimiters, const std::string& delimiterNeighbours = "", bool emptyEntries=false, 93 char escapeChar ='\\', bool removeEscapeChar = true, char safemode_char = '"', bool removeSafemodeChar = true, 94 char openparenthesis_char = '{', char closeparenthesis_char = '}', bool removeParenthesisChars = true, char comment_char = '\0'); 117 SubString(const std::string& line, 118 const std::string& delimiters = SubString::WhiteSpaces, 119 const std::string& delimiterNeighbours = "", 120 bool bAllowEmptyEntries=false, 121 char escapeChar ='\\', 122 bool bRemoveEscapeChar = true, 123 char safemodeChar = '"', 124 bool bRemoveSafemodeChar = true, 125 char openparenthesisChar = '{', 126 char closeparenthesisChar = '}', 127 bool bRemoveParenthesisChars = true, 128 char commentChar = '\0'); 95 129 SubString(unsigned int argc, const char** argv); 96 /** @brief create a Substring as a copy of another one. @param subString the SubString to copy. */ 97 SubString(const SubString& subString) { *this = subString; }; 98 SubString(const SubString& subString, unsigned int subSetBegin); 99 SubString(const SubString& subString, unsigned int subSetBegin, unsigned int subSetEnd); 130 SubString(const SubString& other, unsigned int begin); 131 SubString(const SubString& other, unsigned int begin, unsigned int end); 100 132 ~SubString(); 101 133 102 134 // operate on the SubString 103 SubString& operator=(const SubString& subString);104 bool operator==(const SubString& subString) const;105 bool compare(const SubString& subString) const;106 bool compare(const SubString& subString, unsigned int length) const;107 SubString operator+(const SubString& subString) const;108 SubString& operator+=(const SubString& subString);109 / ** @param subString the String to append @returns appended String. @brief added for convenience */110 SubString& append(const SubString subString) { return (*this += subString); };135 SubString& operator=(const SubString& other); 136 bool operator==(const SubString& other) const; 137 bool compare(const SubString& other) const; 138 bool compare(const SubString& other, unsigned int length) const; 139 SubString operator+(const SubString& other) const; 140 SubString& operator+=(const SubString& other); 141 /// Appends the tokens of another SubString to this. @return This SubString. 142 inline SubString& append(const SubString& other) { return (*this += other); } 111 143 112 144 ///////////////////////////////////////// 113 145 // Split and Join the any String. /////// 114 unsigned int split(const std::string& string = "", char delimiter = ','); 115 unsigned int split(const std::string& string, 116 const std::string& delimiters, const std::string& delimiterNeighbours = "", bool emptyEntries = false, 117 char escapeChar ='\\', bool removeExcapeChar = true, char safemode_char = '"', bool removeSafemodeChar = true, 118 char openparenthesis_char = '{', char closeparenthesis_char = '}', bool removeParenthesisChars = true, char comment_char = '\0'); 146 unsigned int split(const std::string& line, 147 const std::string& delimiters = SubString::WhiteSpaces, 148 const std::string& delimiterNeighbours = "", 149 bool bAllowEmptyEntries = false, 150 char escapeChar ='\\', 151 bool bRemoveEscapeChar = true, 152 char safemodeChar = '"', 153 bool bRemoveSafemodeChar = true, 154 char openparenthesisChar = '{', 155 char closeparenthesisChar = '}', 156 bool bRemoveParenthesisChars = true, 157 char commentChar = '\0'); 158 119 159 std::string join(const std::string& delimiter = " ") const; 120 160 //////////////////////////////////////// 121 161 122 162 // retrieve a SubSet from the String 123 SubString subSet(unsigned int subSetBegin) const;124 SubString subSet(unsigned int subSetBegin, unsigned int subSetEnd) const;163 SubString subSet(unsigned int begin) const; 164 SubString subSet(unsigned int begin, unsigned int end) const; 125 165 126 166 // retrieve Information from within 127 /** @brief Returns true if the SubString is empty */ 128 inline bool empty() const { return this->strings.empty(); }; 129 /** @brief Returns the count of Strings stored in this substring */ 130 inline unsigned int size() const { return this->strings.size(); }; 131 /** @brief Returns the i'th string from the subset of Strings @param i the i'th String */ 132 inline const std::string& operator[](unsigned int i) const { return this->strings[i]; }; 133 /** @brief Returns the i'th string from the subset of Strings @param i the i'th String */ 134 inline const std::string& getString(unsigned int i) const { return (*this)[i]; }; 135 /** @brief Returns all Strings as std::vector */ 136 inline const std::vector<std::string>& getAllStrings() const { return this->strings; } 137 /** @brief Returns true if the token is in safemode. @param i the i'th token */ 138 inline bool isInSafemode(unsigned int i) const { return this->bInSafemode[i]; } 139 /** @brief Returns the front of the StringList. */ 140 inline const std::string& front() const { return this->strings.front(); }; 141 /** @brief Returns the back of the StringList. */ 142 inline const std::string& back() const { return this->strings.back(); }; 143 /** @brief removes the back of the strings list. */ 144 inline void pop_back() { this->strings.pop_back(); this->bInSafemode.pop_back(); }; 145 167 /// Returns true if the SubString is empty 168 inline bool empty() const { return this->tokens_.empty(); } 169 /// Returns the number of tokens stored in this SubString 170 inline unsigned int size() const { return this->tokens_.size(); } 171 /// Returns the i'th token from the subset of strings @param index The index of the requested doken 172 inline const std::string& operator[](unsigned int index) const { return this->tokens_[index]; } 173 /// Returns the i'th token from the subset of strings @param index The index of the requested token 174 inline const std::string& getString(unsigned int index) const { return (*this)[index]; } 175 /// Returns all tokens as std::vector 176 inline const std::vector<std::string>& getAllStrings() const { return this->tokens_; } 177 /// Returns true if the token is in safemode. @param index The index of the token 178 inline bool isInSafemode(unsigned int index) const { return this->bTokenInSafemode_[index]; } 179 /// Returns the front of the list of tokens. 180 inline const std::string& front() const { return this->tokens_.front(); } 181 /// Returns the back of the list of tokens. 182 inline const std::string& back() const { return this->tokens_.back(); } 183 /// Removes the back of the list of tokens. 184 inline void pop_back() { this->tokens_.pop_back(); this->bTokenInSafemode_.pop_back(); } 185 186 void debug() const; 187 188 public: 189 static const std::string WhiteSpaces; ///< All whitespaces (usually used as delimiters or delimiterNeighbours 190 static const std::string WhiteSpacesWithComma; ///< All whitespaces and the comma (usually used as delimiters) 191 static const SubString NullSubString; ///< An empty SubString 192 193 private: 146 194 // the almighty algorithm. 147 static SPLIT_LINE_STATE splitLine(std::vector<std::string>& ret,148 std::vector<bool>& b InSafemode,195 static SPLIT_LINE_STATE splitLine(std::vector<std::string>& tokens, 196 std::vector<bool>& bTokenInSafemode, 149 197 const std::string& line, 150 198 const std::string& delimiters = SubString::WhiteSpaces, 151 199 const std::string& delimiterNeighbours = "", 152 bool emptyEntries = false,153 char escape _char = '\\',154 bool removeExcapeChar = true,155 char safemode _char = '"',156 bool removeSafemodeChar = true,157 char openparenthesis _char = '{',158 char closeparenthesis _char = '}',159 bool removeParenthesisChars = true,160 char comment _char = '\0',200 bool bAllowEmptyEntries = false, 201 char escapeChar = '\\', 202 bool bRemoveEscapeChar = true, 203 char safemodeChar = '"', 204 bool bRemoveSafemodeChar = true, 205 char openparenthesisChar = '{', 206 char closeparenthesisChar = '}', 207 bool bRemoveParenthesisChars = true, 208 char commentChar = '\0', 161 209 SPLIT_LINE_STATE start_state = SL_NORMAL); 162 // debugging. 163 void debug() const; 164 165 public: 166 static const std::string WhiteSpaces; 167 static const std::string WhiteSpacesWithComma; 168 static const SubString NullSubString; 169 170 private: 171 std::vector<std::string> strings; //!< strings produced from a single string splitted in multiple strings 172 std::vector<bool> bInSafemode; 210 211 std::vector<std::string> tokens_; ///< The tokens after spliting the input line 212 std::vector<bool> bTokenInSafemode_; ///< Saves for each token if it was in safe mode (between quotation marks or parenthesis) 173 213 }; 174 214 } -
code/trunk/src/libraries/util/TriBool.h
r6746 r7401 27 27 */ 28 28 29 /** 30 @file 31 @ingroup Util 32 */ 33 29 34 #ifndef _TriBool_H__ 30 35 #define _TriBool_H__ … … 35 40 namespace orxonox 36 41 { 42 /** Sort of a boolean value that also has state \c Dontcare 43 @remarks 44 Even though \c False has the value 0, both \c True and \c Dontcare have 45 a value other than 0. Keep that in mind when using TriBools in if statements. 46 */ 37 47 namespace TriBool 38 48 { -
code/trunk/src/libraries/util/VA_NARGS.h
r7284 r7401 29 29 /** 30 30 @file 31 @ingroup Util 31 32 @brief Declaration of the ORXONOX_VA_NARGS macro which returns the number of arguments passed to a variadic macro. 33 34 With this utility you can overload a macro for different numbers of arguments 35 (of course overloading is not possible for different types, as macros are not 36 type aware, but for different numbers of arguments is still very powerful). 37 38 Example: A macro to call functions 39 @code 40 myfunction(); // A static function 41 MyClass::myStaticFunction(); // A static class function 42 MyClass::myFunction(); // A member function 43 44 #define CallFunction(...) \ // Define a variadic macro that passes the arguments to the overloaded implementations 45 BOOST_PP_EXPAND(BOOST_PP_CAT(CallFunction, ORXONOX_VA_NARGS(__VA_ARGS__))(__VA_ARGS__)) 46 47 #define CallFunction1(function) \ // Overloaded macro for 1 argument 48 function() // Calls the static function 49 50 #define CallFunction2(class, function) \ // Overloaded macro for 2 arguments 51 class::function() // Calls the static class function 52 53 #define CallFunction3(class, function, object) \ // Overloaded macro for 3 arguments 54 object->class::function() // Calls the function on the object 55 56 57 CallFunction(myFunction); // Call the macro with 1 argument 58 CallFunction(MyClass, myStaticFunction); // Call the macro with 2 arguments 59 CallFunction(MyClass, myFunction, new MyClass()); // Call the macro with 3 arguments 60 @endcode 61 62 Note that the first (variadic) macro concatenates the name "CallFunction" with 63 the number of arguments ("1" - "N"). Then all arguments are passed to the right macro. 32 64 */ 33 65 -
code/trunk/src/libraries/util/mbool.h
r7268 r7401 27 27 */ 28 28 29 /** 30 @file 31 @ingroup Util 32 @brief Declaration and implementation of the @ref orxonox::mbool class. 33 */ 34 29 35 #ifndef _mbool_H__ 30 36 #define _mbool_H__ … … 34 40 namespace orxonox 35 41 { 42 /** 43 @brief mbool is a small helper class that acts like a bool, but keeps track of the number of its state changes. 44 45 The mbool class acts like a bool, but it has an internal counter that counts 46 the number state changes (i.e. when the bool changes from true to false or 47 back). This is used in the network if a boolean value is synchronized, because 48 if a value changes quickly from false to true and back in the same tick, the 49 clients will never be notified of this action. By using mbool however this 50 behaviour is fixed, which is important for triggers and other objects. 51 52 @note This is efficiently solved by using a union that combines a counter and a 53 boolean bitfield of size 1. The boolean value corresponds always to the first 54 bit of the counter - this means, if the counter is incremented, the boolean state 55 changes. On the other hand, if you want to change the state, you can simply increase 56 the counter. 57 */ 36 58 struct _UtilExport mbool 37 59 { 38 60 public: 61 /// Constructor: Creates the mbool and initializes the boolean value (default to false). 39 62 inline mbool(bool value = false) 40 63 { this->value_.memory_ = 0; this->value_.bool_ = value; } 64 /// Copy-constructor, copies state and memory. 41 65 inline mbool(const mbool& value) 42 66 { this->value_.memory_ = value.value_.memory_; } 43 67 68 /// Assigns a boolean value (and increases the memory value if the value is different to the old value). 44 69 inline mbool& operator=(bool value) 45 70 { if (value != this->value_.bool_) { ++this->value_.memory_; } return (*this); } 71 /// Assigns another mbool, copies state and memory. 46 72 inline mbool& operator=(const mbool& value) 47 73 { this->value_.memory_ = value.value_.memory_; return (*this); } 48 74 75 /// Increases the memory which also inverts it's state (++mbool). 49 76 inline mbool& operator++() 50 77 { ++this->value_.memory_; return (*this); } 51 inline mbool operator++(int i) 78 /// Increases the memory which also inverts it's state (mbool++). 79 inline mbool operator++(int) 52 80 { mbool temp = (*this); ++this->value_.memory_; return temp; } 53 81 82 /// Implicitly converts the mbool to a bool. 54 83 inline operator bool() const 55 84 { return this->value_.bool_; } 56 85 86 /// Compares the mbool to a bool, returns true if the bool has the same value as the state of the mbool. 57 87 inline bool operator==(bool other) const 58 88 { return this->value_.bool_ == other; } 89 /// Compares the mbool to a bool, returns true if the bool has a different value than the state of the mbool. 59 90 inline bool operator!=(bool other) const 60 91 { return this->value_.bool_ != other; } 61 92 93 /// Compares two mbools, returns true if their memory matches. 62 94 inline bool operator==(const mbool& other) const 63 95 { return this->value_.memory_ == other.value_.memory_; } 96 /// Compares two mbools, returns true if they have a different memory value. 64 97 inline bool operator!=(const mbool& other) const 65 98 { return this->value_.memory_ != other.value_.memory_; } 66 99 100 /// Returns the inverted state of the bool (doesn't change the internal state). 67 101 inline bool operator!() const 68 102 { return (!this->value_.bool_); } 69 103 104 /// Returns the memory value. 70 105 inline unsigned char& getMemory(){ return value_.memory_; } 71 106 … … 73 108 union 74 109 { 75 bool bool_ : 1; 76 unsigned char memory_; 77 } value_; 110 bool bool_ : 1; ///< The boolean state of the mbool, is located on the first bit of the memory variable 111 unsigned char memory_; ///< The memory of the mbool, counts the state-changes (and the first bit represents also the boolean value) 112 } value_; ///< A union containing the state and the memory of the mbool 78 113 }; 79 114 }
Note: See TracChangeset
for help on using the changeset viewer.