- Timestamp:
- Dec 4, 2007, 11:48:28 PM (17 years ago)
- Location:
- code/branches/FICN/src/orxonox
- Files:
-
- 2 added
- 19 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/FICN/src/orxonox/core/ClassFactory.h
r258 r384 1 /*! 2 @file ClassFactory.h 3 @brief Definition of the ClassFactory class 4 5 The ClassFactory is able to create new objects of a specific class. 6 */ 7 1 8 #ifndef _ClassFactory_H__ 2 9 #define _ClassFactory_H__ … … 9 16 // ### ClassFactory ### 10 17 // ############################### 18 //! The ClassFactory is able to create new objects of a specific class. 11 19 template <class T> 12 20 class ClassFactory : public BaseFactory … … 17 25 18 26 private: 19 ClassFactory() {} 20 ClassFactory(const ClassFactory& factory) {} 21 ~ClassFactory() {} 27 ClassFactory() {} // Don't create 28 ClassFactory(const ClassFactory& factory) {} // Don't copy 29 ~ClassFactory() {} // Don't delete 22 30 23 31 static T* createNewObject(); 24 32 }; 25 33 34 /** 35 @brief Adds the ClassFactory to the Identifier of the same type and creates a new object to retrieve the parents. 36 @return True, because the compiler only allows assignments before main() 37 */ 26 38 template <class T> 27 39 bool ClassFactory<T>::create() 28 40 { 41 // Add the ClassFactory to the Classidentifier of type T 29 42 ClassIdentifier<T>::getIdentifier()->addFactory(new ClassFactory<T>); 30 43 44 // To create the new branch of the class-hierarchy, we create a new object and delete it afterwards. 31 45 ClassIdentifier<T>::getIdentifier()->startCreatingHierarchy(); 32 46 #if HIERARCHY_VERBOSE … … 40 54 } 41 55 56 /** 57 @brief Creates and returns a new object of class T. 58 @return The new object 59 */ 42 60 template <class T> 43 61 BaseObject* ClassFactory<T>::fabricate() … … 46 64 } 47 65 66 /** 67 @brief Creates and returns a new object of class T; this is a wrapper for the new operator. 68 @return The new object 69 */ 48 70 template <class T> 49 71 T* ClassFactory<T>::createNewObject() -
code/branches/FICN/src/orxonox/core/Factory.cc
r363 r384 1 /*! 2 @file Factory.cc 3 @brief Implementation of the Factory class. 4 */ 5 1 6 #include "Factory.h" 2 7 #include "Identifier.h" … … 4 9 namespace orxonox 5 10 { 6 Factory* Factory::pointer_s = NULL; 11 Factory* Factory::pointer_s = NULL; // Set the static member variable pointer_s to zero 7 12 13 /** 14 @returns the Identifier with a given name. 15 @param name The name of the wanted Identifier 16 */ 8 17 Identifier* Factory::getIdentifier(const std::string& name) 9 18 { … … 14 23 } 15 24 25 /** 26 @returns the Identifier with a given networkID. 27 @param id The networkID of the wanted Identifier 28 */ 16 29 Identifier* Factory::getIdentifier(const unsigned int id) 17 30 { … … 22 35 } 23 36 37 /** 38 @brief Adds a new Identifier to both maps. 39 @param name The name of the identifier 40 @param identifier The identifier to add 41 */ 24 42 void Factory::add(const std::string& name, Identifier* identifier) 25 43 { … … 31 49 } 32 50 51 /** 52 @brief Removes the entry with the old networkID and adds a new one. 53 @param identifier The identifier to change 54 @param oldID The old networkID 55 @param newID The new networkID 56 */ 33 57 void Factory::changeNetworkID(Identifier* identifier, const unsigned int oldID, const unsigned int newID) 34 58 { -
code/branches/FICN/src/orxonox/core/Factory.h
r363 r384 1 /*! 2 @file Factory.h 3 @brief Definition of the Factory and the BaseFactory class. 4 5 The Factory is a singleton, containing two maps to map either the name or the networkID 6 of a class with the corresponding Identifier. 7 8 Usage: 9 ID(classname) or ID(networkID) returns the corresponding Identifier. 10 11 12 BaseObject is the parent of ClassFactory which is defined in ClassFactory.h. 13 It can't be defined in ClassFactory.h, because of circular dependencies. 14 */ 15 1 16 #ifndef _Factory_H__ 2 17 #define _Factory_H__ … … 7 22 namespace orxonox 8 23 { 9 class BaseObject; 10 class Identifier; 24 class BaseObject; // Forward declaration 25 class Identifier; // Forward declaration 11 26 12 27 // ############################### 13 28 // ### Factory ### 14 29 // ############################### 30 //! The Factory is used to map name or networkID of a class with its Identifier. 15 31 class Factory 16 32 { … … 22 38 23 39 private: 24 Factory() {} 25 Factory(const Factory& factory) {} 26 ~Factory() {} 40 Factory() {} // don't create 41 Factory(const Factory& factory) {} // don't copy 42 ~Factory() {} // don't delete 27 43 28 static Factory* pointer_s; 29 std::map<std::string, Identifier*> identifierStringMap_; 30 std::map<unsigned int, Identifier*> identifierNetworkIDMap_; 44 static Factory* pointer_s; //!< The pointer to the singleton 45 std::map<std::string, Identifier*> identifierStringMap_; //!< The map mapping string with Identifier 46 std::map<unsigned int, Identifier*> identifierNetworkIDMap_; //!< The map mapping networkID with Identifier 31 47 }; 32 48 … … 34 50 // ### BaseFactory ### 35 51 // ############################### 52 //! Base-class of ClassFactory. Has to be defined separate because of circular dependencies. 36 53 class BaseFactory 37 54 { 38 55 public: 39 56 virtual BaseObject* fabricate() = 0; 57 virtual ~BaseFactory() {}; 40 58 }; 41 59 } -
code/branches/FICN/src/orxonox/core/Identifier.cc
r363 r384 1 /*! 2 @file Identifier.cc 3 @brief Implementation of the Identifier class. 4 */ 5 1 6 #include "Identifier.h" 2 7 … … 6 11 // ### Identifier ### 7 12 // ############################### 8 int Identifier::hierarchyCreatingCounter_s = 0; 9 unsigned int Identifier::classIDcounter_s = 0; 13 int Identifier::hierarchyCreatingCounter_s = 0; // Set the static member variable hierarchyCreatingCounter_s to zero 14 unsigned int Identifier::classIDcounter_s = 0; // Set the static member variable classIDcounter_s to zero 10 15 16 /** 17 @brief Constructor: No factory, no object created, new ObjectList and a unique networkID. 18 */ 11 19 Identifier::Identifier() 12 20 { … … 18 26 } 19 27 28 /** 29 @brief Destructor: Deletes the name and the IdentifierList containing the children. 30 */ 20 31 Identifier::~Identifier() 21 32 { 22 33 delete &this->name_; 23 24 34 delete this->children_; 25 35 } 26 36 37 /** 38 @brief Initializes the Identifier with an IdentifierList containing all parents of the class the Identifier belongs to. 39 @param parents The IdentifierList containing all parents 40 */ 27 41 void Identifier::initialize(const IdentifierList* parents) 28 42 { … … 38 52 { 39 53 this->parents_.add(temp1->identifier_); 40 temp1->identifier_->getChildren().add(this); 54 temp1->identifier_->getChildren().add(this); // We're a child of our parents 41 55 42 56 temp1 = temp1->next_; … … 45 59 } 46 60 61 /** 62 @brief Creates an object of the type the Identifier belongs to. 63 @return The new object 64 */ 47 65 BaseObject* Identifier::fabricate() 48 66 { 49 67 if (this->factory_) 50 68 { 51 return this->factory_->fabricate(); 69 return this->factory_->fabricate(); // We have to return a BaseObject, because we don't know the exact type. 52 70 } 53 71 else 54 72 { 73 // Abstract classes don't have a factory and therefore can't create new objects 55 74 std::cout << "Error: Cannot create an object of type '" << this->name_ << "'. Class is abstract.\n"; 56 75 std::cout << "Aborting..."; … … 59 78 } 60 79 80 /** 81 @brief Sets the networkID to a new value and changes the entry in the Factory. 82 @param id The new networkID 83 */ 61 84 void Identifier::setNetworkID(unsigned int id) 62 85 { … … 65 88 } 66 89 90 /** 91 @returns true, if the Identifier is at least of the given type. 92 @param identifier The identifier to compare with 93 */ 67 94 bool Identifier::isA(const Identifier* identifier) const 68 95 { … … 70 97 } 71 98 99 /** 100 @returns true, if the Identifier is exactly of the given type. 101 @param identifier The identifier to compare with 102 */ 72 103 bool Identifier::isDirectlyA(const Identifier* identifier) const 73 104 { … … 75 106 } 76 107 108 /** 109 @returns true, if the assigned identifier is a child of the given identifier. 110 @param identifier The identifier to compare with 111 */ 77 112 bool Identifier::isChildOf(const Identifier* identifier) const 78 113 { … … 80 115 } 81 116 117 /** 118 @returns true, if the assigned identifier is a parent of the given identifier. 119 @param identifier The identifier to compare with 120 */ 82 121 bool Identifier::isParentOf(const Identifier* identifier) const 83 122 { -
code/branches/FICN/src/orxonox/core/Identifier.h
r367 r384 1 /*! 2 @file Identifier.h 3 @brief Definition of the Identifier, ClassIdentifier and SubclassIdentifier classes. 4 5 The Identifier contains all needed informations about the class it belongs to: 6 - the name 7 - a list with all objects 8 - parents and childs 9 - the factory, if available 10 - the networkID that can be synchronised with the server 11 12 Every object has a pointer to the Identifier of its class. This allows the use isA(...), 13 isDirectlyA(...), isChildOf(...) and isParentOf(...). 14 15 To create the class-hierarchy, the Identifier has some intern functions and variables. 16 17 Every Identifier is in fact a ClassIdentifier, but they are derived from Identifier. 18 19 SubclassIdentifier is a separated class, acting like an Identifier, but has a given class. 20 You can only assign Identifiers of the given class or a derivative to a SubclassIdentifier. 21 */ 22 1 23 #ifndef _Identifier_H__ 2 24 #define _Identifier_H__ … … 8 30 #include "Factory.h" 9 31 10 #ifdef WIN3211 #define HIERARCHY_VERBOSE 012 #else13 32 #define HIERARCHY_VERBOSE false 14 #endif15 33 16 34 17 35 namespace orxonox 18 36 { 19 class BaseObject; 37 class BaseObject; // Forward declaration 20 38 21 39 // ############################### 22 40 // ### Identifier ### 23 41 // ############################### 42 //! The Identifier is used to identify the class of an object and to store informations about the class. 43 /** 44 The Identifier contains all needed informations about the class it belongs to: 45 - the name 46 - a list with all objects 47 - parents and childs 48 - the factory, if available 49 - the networkID that can be synchronised with the server 50 51 Every object has a pointer to the Identifier of its class. This allows the use isA(...), 52 isDirectlyA(...), isChildOf(...) and isParentOf(...). 53 54 You can't directly create an Identifier, it's just the base-class for ClassIdentifier. 55 */ 24 56 class Identifier 25 57 { 26 58 template <class T> 27 friend class ClassIdentifier; 59 friend class ClassIdentifier; // Forward declaration 28 60 29 61 template <class T> 30 friend class SubclassIdentifier; 62 friend class SubclassIdentifier; // Forward declaration 31 63 32 64 template <class T> 33 friend class ClassFactory; 65 friend class ClassFactory; // Forward declaration 34 66 35 67 public: 68 /** @brief Sets the Factory. @param facotry The factory to assign */ 36 69 inline void addFactory(BaseFactory* factory) { this->factory_ = factory; } 70 37 71 BaseObject* fabricate(); 38 72 … … 42 76 bool isParentOf(const Identifier* identifier) const; 43 77 78 /** @returns the name of the class the Identifier belongs to. */ 44 79 inline const std::string& getName() const { return this->name_; } 80 81 /** @returns the parents of the class the Identifier belongs to. */ 45 82 inline const IdentifierList& getParents() const { return this->parents_; } 83 84 /** @returns the children of the class the Identifier belongs to. */ 46 85 inline IdentifierList& getChildren() const { return *this->children_; } 47 86 87 /** @returns true, if a branch of the class-hierarchy is getting created, causing all new objects to store their parents. */ 48 88 inline static bool isCreatingHierarchy() { return (hierarchyCreatingCounter_s > 0); } 49 89 90 /** @returns the NetworkID to identify a class through the network. */ 50 91 inline const unsigned int getNetworkID() const { return this->classID_; } 92 51 93 void setNetworkID(unsigned int id); 52 94 53 95 private: 54 96 Identifier(); 55 Identifier(const Identifier& identifier) {} 97 Identifier(const Identifier& identifier) {} // don't copy 56 98 virtual ~Identifier(); 57 99 void initialize(const IdentifierList* parents); 58 100 101 /** 102 @brief Increases the hierarchyCreatingCounter_s variable, causing all new objects to store their parents. 103 */ 59 104 inline static void startCreatingHierarchy() 60 105 { … … 65 110 } 66 111 112 /** 113 @brief Decreases the hierarchyCreatingCounter_s variable, causing the objects to stop storing their parents. 114 */ 67 115 inline static void stopCreatingHierarchy() 68 116 { … … 73 121 } 74 122 75 IdentifierList parents_; 76 IdentifierList* children_; 77 78 std::string name_; 79 80 BaseFactory* factory_; 81 bool bCreatedOneObject_; 82 static int hierarchyCreatingCounter_s; 83 static unsigned int classIDcounter_s; 84 unsigned int classID_; 123 IdentifierList parents_; //!< The Parents of the class the Identifier belongs to 124 IdentifierList* children_; //!< The Children of the class the Identifier belongs to 125 126 std::string name_; //!< The name of the class the Identifier belongs to 127 128 BaseFactory* factory_; //!< The Factory, able to create new objects of the given class 129 bool bCreatedOneObject_; //!< True if at least one object of the given type was created (used to determine the need of storing the parents) 130 static int hierarchyCreatingCounter_s; //!< Bigger than zero if at least one Identifier stores its parents (its an int instead of a bool to avoid conflicts with multithreading) 131 static unsigned int classIDcounter_s; //!< The number of unique Identifiers 132 unsigned int classID_; //!< The networkID to identify a class through the network 85 133 }; 86 134 … … 89 137 // ### ClassIdentifier ### 90 138 // ############################### 139 //! The ClassIdentifier is derived from Identifier and holds all class-specific functions and variables the Identifier cannot have. 140 /** 141 ClassIdentifier is a Singleton, which means that only one object of a given type T exists. 142 This makes it possible to store informations about a class, sharing them with all 143 objects of that class without defining static variables in every class. 144 */ 91 145 template <class T> 92 146 class ClassIdentifier : public Identifier … … 99 153 private: 100 154 ClassIdentifier(); 101 ClassIdentifier(const ClassIdentifier<T>& identifier) {} 155 ClassIdentifier(const ClassIdentifier<T>& identifier) {} // don't copy 102 156 ~ClassIdentifier(); 103 157 104 static ClassIdentifier<T>* pointer_s; 105 ObjectList<T>* objects_; 158 static ClassIdentifier<T>* pointer_s; //!< A pointer to the singleton-object 159 ObjectList<T>* objects_; //!< The ObjectList, containing all objects of type T 106 160 }; 107 161 108 162 template <class T> 109 ClassIdentifier<T>* ClassIdentifier<T>::pointer_s = NULL; 110 163 ClassIdentifier<T>* ClassIdentifier<T>::pointer_s = NULL; // Set the static member variable pointer_s to zero 164 165 /** 166 @brief Constructor: Create the ObjectList. 167 */ 111 168 template <class T> 112 169 ClassIdentifier<T>::ClassIdentifier() … … 115 172 } 116 173 174 /** 175 @brief Destructor: Delete the ObjectList, set the singleton-pointer to zero. 176 */ 117 177 template <class T> 118 178 ClassIdentifier<T>::~ClassIdentifier() … … 122 182 } 123 183 184 /** 185 @brief Registers a class, which means that the name and the parents get stored. 186 @param parents An IdentifierList, containing the Identifiers of all parents of the class 187 @param name A string, containing exactly the name of the class 188 @param bRootClass True if the class is either an Interface or BaseObject itself 189 @return The ClassIdentifier itself 190 */ 124 191 template <class T> 125 192 ClassIdentifier<T>* ClassIdentifier<T>::registerClass(const IdentifierList* parents, const std::string& name, bool bRootClass) … … 128 195 std::cout << "*** Register Class in " << name << "-Singleton.\n"; 129 196 #endif 197 198 // It's a singleton, so maybe we have to create it first 130 199 if (!pointer_s) 131 200 { … … 136 205 } 137 206 207 // Check if at least one object of the given type was created 138 208 if (!pointer_s->bCreatedOneObject_) 139 209 { 210 // If no: We have to store the informations and initialize the Identifier 211 140 212 #if HIERARCHY_VERBOSE 141 213 std::cout << "*** Register Class in " << name << "-Singleton -> Initialize Singleton.\n"; 142 214 #endif 143 215 pointer_s->name_ = name; 144 Factory::add(name, pointer_s); 216 Factory::add(name, pointer_s); // Add the Identifier to the Factory 145 217 146 218 if (bRootClass) 147 pointer_s->initialize(NULL); 219 pointer_s->initialize(NULL); // If a class is derived from two interfaces, the second interface might think it's derived from the first because of the order of constructor-calls. Thats why we set parents to zero in that case. 148 220 else 149 221 pointer_s->initialize(parents); … … 153 225 } 154 226 227 /** 228 @returns the Identifier itself 229 */ 155 230 template <class T> 156 231 ClassIdentifier<T>* ClassIdentifier<T>::getIdentifier() … … 167 242 } 168 243 244 /** 245 @brief Adds an object of the given type to the ObjectList. 246 @param object The object to add 247 */ 169 248 template <class T> 170 249 void ClassIdentifier<T>::addObject(T* object) … … 173 252 std::cout << "*** Added object to " << ClassIdentifier<T>::getIdentifier()->getName() << "-list.\n"; 174 253 #endif 175 object->getMetaList() ->add(ClassIdentifier<T>::getIdentifier()->objects_, ClassIdentifier<T>::getIdentifier()->objects_->add(object));254 object->getMetaList().add(ClassIdentifier<T>::getIdentifier()->objects_, ClassIdentifier<T>::getIdentifier()->objects_->add(object)); 176 255 } 177 256 … … 180 259 // ### SubclassIdentifier ### 181 260 // ############################### 182 template <class B> 261 //! The SubclassIdentifier acts almost like an Identifier, but has some prerequisites. 262 /** 263 You can only assign Identifiers that belong to a class of at least B (or derived) to a SubclassIdentifier<T>. 264 If you assign something else, the program aborts. 265 Because we know the minimal type, a dynamic_cast is done, which makes it easier to create a new object. 266 */ 267 template <class T> 183 268 class SubclassIdentifier 184 269 { 185 270 public: 186 SubclassIdentifier(); 187 188 SubclassIdentifier<B>& operator=(Identifier* identifier) 189 { 190 if (!identifier->isA(ClassIdentifier<B>::getIdentifier())) 271 /** 272 @brief Constructor: Automaticaly assigns the Identifier of the given class. 273 */ 274 SubclassIdentifier() 275 { 276 this->identifier_ = ClassIdentifier<T>::getIdentifier(); 277 } 278 279 /** 280 @brief Overloading of the = operator: assigns the identifier and checks its type. 281 @param identifier The Identifier to assign 282 @return The SubclassIdentifier itself 283 */ 284 SubclassIdentifier<T>& operator=(Identifier* identifier) 285 { 286 if (!identifier->isA(ClassIdentifier<T>::getIdentifier())) 191 287 { 192 std::cout << "Error: Class " << identifier->getName() << " is not a " << ClassIdentifier< B>::getIdentifier()->getName() << "!\n";193 std::cout << "Error: SubclassIdentifier<" << ClassIdentifier< B>::getIdentifier()->getName() << "> = Class(" << identifier->getName() << ") is forbidden.\n";288 std::cout << "Error: Class " << identifier->getName() << " is not a " << ClassIdentifier<T>::getIdentifier()->getName() << "!\n"; 289 std::cout << "Error: SubclassIdentifier<" << ClassIdentifier<T>::getIdentifier()->getName() << "> = Class(" << identifier->getName() << ") is forbidden.\n"; 194 290 std::cout << "Aborting...\n"; 195 291 abort(); … … 199 295 } 200 296 297 /** 298 @brief Overloading of the * operator: returns the assigned identifier. 299 @return The assigned identifier 300 */ 201 301 Identifier* operator*() 202 302 { … … 204 304 } 205 305 306 /** 307 @brief Overloading of the -> operator: returns the assigned identifier. 308 @return The assigned identifier 309 */ 206 310 Identifier* operator->() const 207 311 { … … 209 313 } 210 314 211 B* fabricate() 315 /** 316 @brief Creates a new object of the type of the assigned identifier and dynamic_casts it to the minimal type given by the SubclassIdentifier. 317 @return The new object 318 */ 319 T* fabricate() 212 320 { 213 321 BaseObject* newObject = this->identifier_->fabricate(); 322 323 // Check if the creation worked 214 324 if (newObject) 215 325 { 216 return dynamic_cast<B*>(newObject); 326 // Do a dynamic_cast, because an object of type T is much better than of type BaseObject 327 return dynamic_cast<T*>(newObject); 217 328 } 218 329 else 219 330 { 331 // Something went terribly wrong 220 332 if (this->identifier_) 221 333 { 222 std::cout << "Error: Class " << this->identifier_->getName() << " is not a " << ClassIdentifier< B>::getIdentifier()->getName() << "!\n";334 std::cout << "Error: Class " << this->identifier_->getName() << " is not a " << ClassIdentifier<T>::getIdentifier()->getName() << "!\n"; 223 335 std::cout << "Error: Couldn't fabricate a new Object.\n"; 224 336 std::cout << "Aborting...\n"; … … 234 346 } 235 347 348 /** @returns the assigned identifier. */ 236 349 inline const Identifier* getIdentifier() const 237 350 { return this->identifier_; } 351 352 /** @returns true, if the assigned identifier is at least of the given type. @param identifier The identifier to compare with */ 238 353 inline bool isA(const Identifier* identifier) const 239 354 { return this->identifier_->isA(identifier); } 355 356 /** @returns true, if the assigned identifier is exactly of the given type. @param identifier The identifier to compare with */ 240 357 inline bool isDirectlyA(const Identifier* identifier) const 241 358 { return this->identifier_->isDirectlyA(identifier); } 359 360 /** @returns true, if the assigned identifier is a child of the given identifier. @param identifier The identifier to compare with */ 242 361 inline bool isChildOf(const Identifier* identifier) const 243 362 { return this->identifier_->isChildOf(identifier); } 363 364 /** @returns true, if the assigned identifier is a parent of the given identifier. @param identifier The identifier to compare with */ 244 365 inline bool isParentOf(const Identifier* identifier) const 245 366 { return this->identifier_->isParentOf(identifier); } 246 367 247 368 private: 248 Identifier* identifier_; 369 Identifier* identifier_; //!< The assigned identifier 249 370 }; 250 251 template <class B>252 SubclassIdentifier<B>::SubclassIdentifier()253 {254 this->identifier_ = ClassIdentifier<B>::getIdentifier();255 }256 371 } 257 372 -
code/branches/FICN/src/orxonox/core/IdentifierIncludes.h
r363 r384 1 /** 2 @file IDentifierIncludes.h 3 @brief Definition of macros for the class-hierarchy and the factory. 4 5 Every class needs the RegisterObject(class) macro in its constructor. If the class is an interface 6 or the BaseObject itself, it needs the macro RegisterRootObject(class) instead. 7 8 To allow the object being created through the factory, use the CreateFactory(class) macro outside 9 the of the class implementation, so it gets executed before main(). 10 */ 11 12 // All needed header-files 1 13 #include "Identifier.h" 2 14 #include "Factory.h" … … 6 18 7 19 20 // Intern macro, containing the common parts of RegisterObject and RegisterRootObject 8 21 #define InternRegisterObject(ClassName, bRootClass) \ 9 22 this->setIdentifier(ClassIdentifier<ClassName>::registerClass(this->getParents(), #ClassName, bRootClass)); \ … … 12 25 ClassIdentifier<ClassName>::addObject(this) 13 26 27 // Intern macro, containing the specific part of RegisterRootObject 14 28 #define InternRegisterRootObject(ClassName) \ 15 29 if (Identifier::isCreatingHierarchy() && !this->getParents()) \ … … 17 31 InternRegisterObject(ClassName, true) 18 32 33 // RegisterObject - with and without debug output 19 34 #if HIERARCHY_VERBOSE 20 35 #define RegisterObject(ClassName) \ … … 26 41 #endif 27 42 43 // RegisterRootObject - with and without debug output 28 44 #if HIERARCHY_VERBOSE 29 45 #define RegisterRootObject(ClassName) \ … … 35 51 #endif 36 52 53 // Class(ClassName) returns the Identifier of the given class 37 54 #define Class(ClassName) \ 38 55 ClassIdentifier<ClassName>::getIdentifier() 39 56 57 // Creates the entry in the Factory 40 58 #define CreateFactory(ClassName) \ 41 59 bool bCreated##ClassName##Factory = ClassFactory<ClassName>::create() 42 60 43 #define ID(NameOrID) \ 44 Factory::getIdentifier(NameOrID) 61 // ID(StringOrInt) returns the Identifier with either a given name or a given NetworkID through the factory 62 #define ID(StringOrInt) \ 63 Factory::getIdentifier(StringOrInt) -
code/branches/FICN/src/orxonox/core/IdentifierList.cc
r258 r384 1 /*! 2 @file IdentifierList.cc 3 @brief Implementation of the IdentifierList class. 4 */ 5 1 6 #include "IdentifierList.h" 2 7 #include "Identifier.h" … … 7 12 // ### IdentifierList ### 8 13 // ############################### 14 /** 15 @brief Constructor: Sets first_ to zero. 16 */ 9 17 IdentifierList::IdentifierList() 10 18 { … … 12 20 } 13 21 22 /** 23 @brief Destructor: Deletes all elements in the list, but NOT THE IDENTIFIERS. 24 */ 14 25 IdentifierList::~IdentifierList() 15 26 { … … 23 34 } 24 35 36 /** 37 @brief Adds an Identifier to the list. 38 @param identifier The Identifier to add 39 */ 25 40 void IdentifierList::add(const Identifier* identifier) 26 41 { … … 30 45 } 31 46 47 /** 48 @brief Removes an Identifier from the list. 49 @param identifier The Identifier to remove 50 */ 32 51 void IdentifierList::remove(const Identifier* identifier) 33 52 { … … 35 54 return; 36 55 56 // Check if we have to delete the first element 37 57 if (this->first_->identifier_ == identifier) 38 58 { … … 44 64 } 45 65 66 // Iterate through the list 46 67 IdentifierListElement* temp = this->first_; 47 68 while (temp->next_) … … 60 81 } 61 82 83 /** 84 @brief Checks if a given Identifier is in the list and returns true if yes. 85 @param identifier The Identifier to check 86 @return True if the Identifier is in the list 87 */ 62 88 bool IdentifierList::isInList(const Identifier* identifier) const 63 89 { … … 74 100 } 75 101 102 /** 103 @returns a string, containing the names of all Identifiers in the list. 104 */ 76 105 std::string IdentifierList::toString() const 77 106 { … … 94 123 // ### IdentifierListElement ### 95 124 // ############################### 125 /** 126 @brief Constructor: Creates the list-element with a given identifier. 127 @param identifier The Identifier to store 128 */ 96 129 IdentifierListElement::IdentifierListElement(const Identifier* identifier) 97 130 { … … 99 132 this->next_ = 0; 100 133 } 101 102 IdentifierListElement::~IdentifierListElement()103 {104 }105 134 } -
code/branches/FICN/src/orxonox/core/IdentifierList.h
r258 r384 1 1 #ifndef _IdentifierList_H__ 2 /*! 3 @file IdentifierList.h 4 @brief Definition of the IdentifierList class 5 6 The IdentifierList is a single-linked list, containing Identifiers. 7 The IdentifierList is used to store parents and childs of each Identifier. 8 */ 9 2 10 #define _IdentifierList_H__ 3 11 … … 6 14 namespace orxonox 7 15 { 8 class Identifier; 16 class Identifier; // Forward declaration 9 17 18 //! The list-element of the IdentifierList 10 19 class IdentifierListElement 11 20 { 12 21 public: 13 22 IdentifierListElement(const Identifier* identifier); 14 ~IdentifierListElement();15 23 16 const Identifier* identifier_; 17 IdentifierListElement* next_; 24 const Identifier* identifier_; //!< The identifier 25 IdentifierListElement* next_; //!< The next element in the list 18 26 }; 19 27 28 //! The IdentifierList contains Identifiers 20 29 class IdentifierList 21 30 { … … 28 37 std::string toString() const; 29 38 30 IdentifierListElement* first_; 39 IdentifierListElement* first_; //!< The first element in the list 31 40 }; 32 41 } -
code/branches/FICN/src/orxonox/core/Iterator.h
r337 r384 1 #ifndef _Iterator_H2__ 2 #define _Iterator_H2__ 1 /*! 2 @file Iterator.h 3 @brief Definition of the Iterator class. 4 5 The Iterator of a given class allows to iterate through an ObjectList, containing all objects of that type. 6 This is the only way to access the objects in an ObjectList. 7 8 Usage: 9 for (Iterator<class> it = ObjectList<class>::start(); it != 0; ++it) 10 { 11 it->someFunction(...); 12 class* myObject = *it; 13 } 14 15 Warning: Don't delete an object directly through the iterator. 16 */ 17 18 #ifndef _Iterator_H__ 19 #define _Iterator_H__ 3 20 4 21 namespace orxonox 5 22 { 23 //! The iterator allows to iterate through an ObjectList of a given class. 6 24 template <class T> 7 25 class Iterator 8 26 { 9 27 public: 28 /** 29 @brief Constructor: Sets the element whereon the iterator points to zero. 30 */ 10 31 Iterator() 11 32 { … … 13 34 } 14 35 36 /** 37 @brief Constructor: Sets the element whereon the iterator points to a given element. 38 @param element The element to start with 39 */ 15 40 Iterator(ObjectListElement<T>* element) 16 41 { … … 18 43 } 19 44 45 /** 46 @brief Overloading of the ++it operator: Iterator iterates to the next object in the list. 47 @return The Iterator itself 48 */ 20 49 Iterator<T> operator++() 21 50 { … … 24 53 } 25 54 55 /** 56 @brief Overloading of the --it operator: Iterator iterates to the previous object in the list. 57 @return The Iterator itself 58 */ 26 59 Iterator<T> operator--() 27 60 { … … 30 63 } 31 64 65 /** 66 @brief Overloading of the *it operator: returns the pointer to the object. 67 @return The object the Iterator points at 68 */ 32 69 T* operator*() 33 70 { … … 35 72 } 36 73 74 /** 75 @brief Overloading of the it-> operator: returns the pointer to the object. 76 @return The object the Iterator points at 77 */ 37 78 T* operator->() const 38 79 { … … 41 82 } 42 83 84 /** 85 @brief Overloading of the typecast-operator to bool: returns true if the iterator points to an existing object. 86 @return True if the iterator points to an existing object. 87 */ 43 88 operator bool() 44 89 { … … 46 91 } 47 92 93 /** 94 @brief Overloading of the (it != int) operator: Used for (it != 0) instead of typecast-operator to bool. 95 @param compare The integer (must be zero, everything else makes no sense). 96 @return True if the iterator points to an existing object. 97 */ 48 98 bool operator!=(int compare) 49 99 { 100 // Comparing with something except zero makes no sense 50 101 if (compare != 0) 51 102 std::cout << "Warning: Comparing the " << ClassIdentifier<T>::getIdentifier()->getName() << "-List-Iterator with " << compare << " has no effect. Only comparison with 0 works.\n"; … … 55 106 56 107 private: 57 ObjectListElement<T>* element_; 108 ObjectListElement<T>* element_; //!< The element the Iterator points to 58 109 }; 59 110 } -
code/branches/FICN/src/orxonox/core/MetaObjectList.cc
r258 r384 1 /*! 2 @file MetaObjectList.cc 3 @brief Implementation of the MetaObjectList class. 4 */ 5 1 6 #include "MetaObjectList.h" 2 7 3 8 namespace orxonox 4 9 { 10 /** 11 @brief Constructor: Sets first_ to zero. 12 */ 5 13 MetaObjectList::MetaObjectList() 6 14 { … … 8 16 } 9 17 18 /** 19 @brief Destructor: Removes all elements from the list, causing them to remove the stored ObjectListElement from the ObjectList. 20 */ 10 21 MetaObjectList::~MetaObjectList() 11 22 { -
code/branches/FICN/src/orxonox/core/MetaObjectList.h
r258 r384 1 /*! 2 @file MetaObjectList.h 3 @brief Definition of the MetaObjectList class. 4 5 The MetaObjectList is a single-linked list, containing all list-elements and their 6 lists wherein the object that owns the MetaObjectList is registered. 7 This allows much faster deleting of objects. 8 */ 9 1 10 #ifndef _MetaObjectList_H__ 2 11 #define _MetaObjectList_H__ … … 7 16 namespace orxonox 8 17 { 18 //! Base-class of MetaObjectListElement, because those is a template 9 19 class BaseMetaObjectListElement 10 20 { 11 21 public: 22 /** @brief Defaultdestructor */ 12 23 virtual ~BaseMetaObjectListElement() {}; 13 24 14 BaseMetaObjectListElement* next_; 25 BaseMetaObjectListElement* next_; //!< The next Element in the list 15 26 }; 16 27 … … 18 29 // ### MetaObjectListElement ### 19 30 // ############################### 31 //! The list-element of the MetaObjectList 20 32 template <class T> 21 33 class MetaObjectListElement : public BaseMetaObjectListElement … … 25 37 ~MetaObjectListElement(); 26 38 27 ObjectListElement<T>* element_; 28 ObjectList<T>* list_; 39 ObjectListElement<T>* element_; //!< The list element, containing the object 40 ObjectList<T>* list_; //!< The list, containing the element 29 41 }; 30 42 43 /** 44 @brief Constructor: Creates the list-element with given list and element. 45 */ 31 46 template <class T> 32 47 MetaObjectListElement<T>::MetaObjectListElement(ObjectList<T>* list, ObjectListElement<T>* element) … … 37 52 } 38 53 54 /** 55 @brief Destructor: Removes the ObjectListElement from the ObjectList by linking next_ and prev_ of the ObjectListElement. 56 */ 39 57 template <class T> 40 58 MetaObjectListElement<T>::~MetaObjectListElement() … … 43 61 this->element_->next_->prev_ = this->element_->prev_; 44 62 else 45 this->list_->last_ = this->element_->prev_; 63 this->list_->last_ = this->element_->prev_; // If there is no next_, we deleted the last object and have to update the last_ pointer of the list 46 64 47 65 if (this->element_->prev_) 48 66 this->element_->prev_->next_ = this->element_->next_; 49 67 else 50 this->list_->first_ = this->element_->next_; 68 this->list_->first_ = this->element_->next_; // If there is no prev_, we deleted the first object and have to update the first_ pointer of the list 51 69 52 70 … … 61 79 // ### ObjectList ### 62 80 // ############################### 81 //! The MetaObjectList contains ObjectListElements and their ObjectLists. 82 /** 83 The MetaObjectList is a single-linked list, containing all list-elements and their 84 lists wherein the object that owns the MetaObjectList is registered. 85 This allows much faster deleting of objects. 86 */ 63 87 class MetaObjectList 64 88 { … … 69 93 void add(ObjectList<T>* list, ObjectListElement<T>* element); 70 94 71 BaseMetaObjectListElement* first_; 95 BaseMetaObjectListElement* first_; //!< The first element in the list 72 96 }; 73 97 98 /** 99 @brief Adds an ObjectList and an element of that list to the MetaObjectList. 100 @param list The ObjectList wherein the element is 101 @param element The element wherein the object is 102 */ 74 103 template <class T> 75 104 void MetaObjectList::add(ObjectList<T>* list, ObjectListElement<T>* element) -
code/branches/FICN/src/orxonox/core/ObjectList.h
r258 r384 1 /*! 2 @file ObjectList.h 3 @brief Definition of the ObjectList class. 4 5 The ObjectList is a double-linked list, used by Identifiers to store all objects of a specific class in it. 6 Created objects are added through the RegisterObject-macro in its constructor. 7 Use Iterator<class> to iterate through all objects of the class. 8 */ 9 1 10 #ifndef _ObjectList_H__ 2 11 #define _ObjectList_H__ … … 4 13 namespace orxonox 5 14 { 6 class OrxonoxClass; 15 class OrxonoxClass; // Forward declaration 7 16 8 17 // ############################### 9 18 // ### ObjectListElement ### 10 19 // ############################### 20 //! The list-element of the ObjectList 11 21 template <class T> 12 22 class ObjectListElement … … 14 24 public: 15 25 ObjectListElement(T* object); 16 ~ObjectListElement(); 17 18 T* object_; 19 ObjectListElement* next_; 20 ObjectListElement* prev_; 26 27 T* object_; //!< The object 28 ObjectListElement* next_; //!< The next element in the list 29 ObjectListElement* prev_; //!< The previous element in the list 21 30 }; 22 31 32 /** 33 @brief Constructor: Creates the list-element with an object. 34 @param Object The object to store 35 */ 23 36 template <class T> 24 37 ObjectListElement<T>::ObjectListElement(T* object) … … 29 42 } 30 43 31 template <class T>32 ObjectListElement<T>::~ObjectListElement()33 {34 }35 36 44 37 45 // ############################### … … 39 47 // ############################### 40 48 template <class T> 41 class Iterator; 42 49 class Iterator; // Forward declaration 50 51 //! The ObjectList contains all objects of a specific class. 52 /** 53 The ObjectList is used by Identifiers to store all objects of a specific class in it. 54 Use Iterator<class> to iterate through all objects in the list. 55 */ 43 56 template <class T> 44 57 class ObjectList … … 48 61 ~ObjectList(); 49 62 ObjectListElement<T>* add(T* object); 50 void remove(OrxonoxClass* object, bool bIterateForwards = true); 51 63 // void remove(OrxonoxClass* object, bool bIterateForwards = true); 64 65 /** @returns the first element in the list */ 52 66 inline static Iterator<T> start() 53 67 { return Iterator<T>(pointer_s->first_); } 68 69 /** @returns the last element in the list */ 54 70 inline static Iterator<T> end() 55 71 { return Iterator<T>(pointer_s->last_); } 56 72 57 ObjectListElement<T>* first_; 58 ObjectListElement<T>* last_; 73 ObjectListElement<T>* first_; //!< The first element in the list 74 ObjectListElement<T>* last_; //!< The last element in the list 59 75 60 76 private: 61 static ObjectList<T>* pointer_s; 77 static ObjectList<T>* pointer_s; //!< A static pointer to the last created list (different for all T) 62 78 }; 63 79 64 80 template <class T> 65 ObjectList<T>* ObjectList<T>::pointer_s = 0; 66 81 ObjectList<T>* ObjectList<T>::pointer_s = 0; // Set the static member variable pointer_s to zero 82 83 /** 84 @brief Constructor: Sets first_ and last_ to zero and the static member variable pointer_s to _this_ 85 */ 67 86 template <class T> 68 87 ObjectList<T>::ObjectList() … … 71 90 this->last_ = 0; 72 91 92 // ObjectLists are only created by Identifiers and therefore only one ObjectList of each T will exist. 93 // Thats why pointer_s is in fact a pointer to the only ObjectList for a type, which makes it almost a singleton. 73 94 this->pointer_s = this; 74 95 } 75 96 97 /** 98 @brief Destructor: Deletes all list-elements, but NOT THE OBJECTS. 99 */ 76 100 template <class T> 77 101 ObjectList<T>::~ObjectList() … … 86 110 } 87 111 112 /** 113 @brief Adds a new object to the end of the list. 114 @param object The object to add 115 @return The pointer to the new ObjectListElement, needed by the MetaObjectList of the added object 116 */ 88 117 template <class T> 89 118 ObjectListElement<T>* ObjectList<T>::add(T* object) … … 91 120 if (!this->last_) 92 121 { 122 // If the list is empty 93 123 this->last_ = new ObjectListElement<T>(object); 94 this->first_ = this->last_; 124 this->first_ = this->last_; // There's only one object in the list now 95 125 } 96 126 else 97 127 { 128 // If the list isn't empty 98 129 ObjectListElement<T>* temp = this->last_; 99 130 this->last_ = new ObjectListElement<T>(object); … … 105 136 } 106 137 138 139 // /** 140 // @brief Removes an object from the list. 141 // @param object The object to remove 142 // @param bIterateForwards If true: Start searching the object at the beginning of the list 143 // */ 144 /* 107 145 template <class T> 108 146 void ObjectList<T>::remove(OrxonoxClass* object, bool bIterateForwards) … … 111 149 return; 112 150 151 // If there's only one object in the list, we have to set first_ and last_ to zero 113 152 if (this->first_ == this->last_) 114 153 { … … 123 162 } 124 163 164 // Now we are sure we have more than one element in the list 125 165 if (bIterateForwards) 126 166 { 167 // Start at the beginning of the list 168 169 // Check if it's the first object 127 170 if (this->first_->object_ == object) 128 171 { … … 135 178 } 136 179 180 // Iterate through the whole list 137 181 ObjectListElement<T>* temp = this->first_; 138 182 while (temp->next_) … … 146 190 temp2->prev_ = temp; 147 191 else 148 this->last_ = temp; 192 this->last_ = temp; // If there is no next_, we deleted the last element and have to update the last_ pointer. 149 193 150 194 return; … … 156 200 else 157 201 { 202 // Start at the end of the list 203 204 // Check if it's the last object 158 205 if (this->last_->object_ == object) 159 206 { … … 166 213 } 167 214 215 // Iterate through the whole list 168 216 ObjectListElement<T>* temp = this->last_; 169 217 while (temp->prev_) … … 177 225 temp2->next_ = temp; 178 226 else 179 this->first_ = temp; 227 this->first_ = temp; // If there is no prev_, we deleted the first element and have to update the first_ pointer. 180 228 181 229 return; … … 186 234 } 187 235 } 236 */ 188 237 } 189 238 -
code/branches/FICN/src/orxonox/core/OrxonoxClass.cc
r258 r384 1 /*! 2 @file OrxonoxClass.cc 3 @brief Implementation of the OrxonoxClass Class. 4 */ 5 1 6 #include "OrxonoxClass.h" 2 7 3 8 namespace orxonox 4 9 { 10 /** @brief Constructor: Sets the default values. */ 5 11 OrxonoxClass::OrxonoxClass() 6 12 { … … 8 14 this->parents_ = 0; 9 15 10 this->metaList_ = new MetaObjectList; 16 this->bActive_ = true; 17 this->bVisible_ = true; 11 18 } 12 19 20 /** @brief Destructor: Deletes, if existing, the list of the parents. */ 13 21 OrxonoxClass::~OrxonoxClass() 14 22 { 23 // parents_ exists only if isCreatingHierarchy() of the associated Identifier returned true while creating the class 15 24 if (this->parents_) 16 25 delete this->parents_; 17 18 delete this->metaList_;19 26 } 20 27 } -
code/branches/FICN/src/orxonox/core/OrxonoxClass.h
r258 r384 1 /*! 2 @file OrxonoxClass.h 3 @brief Definition of the OrxonoxClass Class. 4 5 All objects and interfaces of the game-logic are derived from OrxonoxClass. 6 It stores the Identifier and the MetaObjectList and has all needed functions to create the class-hierarchy. 7 */ 8 1 9 #ifndef _OrxonoxClass_H__ 2 10 #define _OrxonoxClass_H__ … … 9 17 namespace orxonox 10 18 { 19 //! The class all objects and interfaces of the game-logic are derived from. 20 /** 21 BaseObject and Interaces are derived with 'virtual public OrxonoxClass' from OrxonoxClass. 22 OrxonoxClass is needed to create the class-hierarchy at startup and to store the Identifier and the MetaObjectList. 23 */ 11 24 class OrxonoxClass 12 25 { … … 14 27 OrxonoxClass(); 15 28 virtual ~OrxonoxClass(); 29 30 /** @returns the Identifier of the object */ 16 31 inline Identifier* getIdentifier() const { return this->identifier_; } 32 33 /** @brief Sets the Identifier of the object. Used by the RegisterObject-macro. */ 17 34 inline void setIdentifier(Identifier* identifier) { this->identifier_ = identifier; } 35 36 /** @returns the list of all parents of the object */ 18 37 inline IdentifierList* getParents() const { return this->parents_; } 38 39 /** @brief Sets the Parents of the object. Used by the RegisterObject-macro. */ 19 40 inline void setParents(IdentifierList* parents) { this->parents_ = parents; } 20 inline MetaObjectList* getMetaList() { return this->metaList_; } 41 42 /** @returns the MetaObjectList of the object, containing a link to all ObjectLists and ObjectListElements the object is registered in. */ 43 inline MetaObjectList& getMetaList() { return this->metaList_; } 44 45 inline bool isA(const Identifier* identifier) 46 { return this->getIdentifier()->isA(identifier); } 47 inline bool isDirectlyA(const Identifier* identifier) 48 { return this->getIdentifier()->isDirectlyA(identifier); } 49 inline bool isChildOf(const Identifier* identifier) 50 { return this->getIdentifier()->isChildOf(identifier); } 51 inline bool isParentOf(const Identifier* identifier) 52 { return this->getIdentifier()->isParentOf(identifier); } 53 54 inline bool isA(const SubclassIdentifier<class B>* identifier) 55 { return this->getIdentifier()->isA(identifier->getIdentifier()); } 56 inline bool isDirectlyA(const SubclassIdentifier<class B>* identifier) 57 { return this->getIdentifier()->isDirectlyA(identifier->getIdentifier()); } 58 inline bool isChildOf(const SubclassIdentifier<class B>* identifier) 59 { return this->getIdentifier()->isChildOf(identifier->getIdentifier()); } 60 inline bool isParentOf(const SubclassIdentifier<class B>* identifier) 61 { return this->getIdentifier()->isParentOf(identifier->getIdentifier()); } 62 63 inline bool isA(const SubclassIdentifier<class B> identifier) 64 { return this->getIdentifier()->isA(identifier.getIdentifier()); } 65 inline bool isDirectlyA(const SubclassIdentifier<class B> identifier) 66 { return this->getIdentifier()->isDirectlyA(identifier.getIdentifier()); } 67 inline bool isChildOf(const SubclassIdentifier<class B> identifier) 68 { return this->getIdentifier()->isChildOf(identifier.getIdentifier()); } 69 inline bool isParentOf(const SubclassIdentifier<class B> identifier) 70 { return this->getIdentifier()->isParentOf(identifier.getIdentifier()); } 71 72 inline bool isA(const OrxonoxClass* object) 73 { return this->getIdentifier()->isA(object->getIdentifier()); } 74 inline bool isDirectlyA(const OrxonoxClass* object) 75 { return this->getIdentifier()->isDirectlyA(object->getIdentifier()); } 76 inline bool isChildOf(const OrxonoxClass* object) 77 { return this->getIdentifier()->isChildOf(object->getIdentifier()); } 78 inline bool isParentOf(const OrxonoxClass* object) 79 { return this->getIdentifier()->isParentOf(object->getIdentifier()); } 80 81 82 inline void setName(const std::string& name) { this->name_ = name; } 83 inline const std::string& getName() const { return this->name_; } 84 85 inline void setActive(bool bActive) { this->bActive_ = bActive; } 86 inline const bool isActive() const { return this->bActive_; } 87 88 inline void setVisible(bool bVisible) { this->bVisible_ = bVisible; } 89 inline const bool isVisible() const { return this->bVisible_; } 21 90 22 91 private: 23 Identifier* identifier_; 24 IdentifierList* parents_; 25 MetaObjectList* metaList_; 92 Identifier* identifier_; //!< The Identifier of the object 93 IdentifierList* parents_; //!< List of all parents of the object 94 MetaObjectList metaList_; //!< MetaObjectList, containing all ObjectLists and ObjectListElements the object is registered in 95 96 std::string name_; 97 bool bActive_; 98 bool bVisible_; 26 99 }; 27 100 } -
code/branches/FICN/src/orxonox/objects/BaseObject.h
r341 r384 2 2 #define _BaseObject_H__ 3 3 4 #include " orxonox/core/IdentifierIncludes.h"4 #include "../core/IdentifierIncludes.h" 5 5 6 6 namespace orxonox … … 11 11 BaseObject(); 12 12 virtual ~BaseObject(); 13 14 inline bool isA(const Identifier* identifier)15 { this->getIdentifier()->isA(identifier); }16 inline bool isDirectlyA(const Identifier* identifier)17 { this->getIdentifier()->isDirectlyA(identifier); }18 inline bool isChildOf(const Identifier* identifier)19 { this->getIdentifier()->isChildOf(identifier); }20 inline bool isParentOf(const Identifier* identifier)21 { this->getIdentifier()->isParentOf(identifier); }22 23 inline bool isA(const SubclassIdentifier<class B>* identifier)24 { this->getIdentifier()->isA(identifier->getIdentifier()); }25 inline bool isDirectlyA(const SubclassIdentifier<class B>* identifier)26 { this->getIdentifier()->isDirectlyA(identifier->getIdentifier()); }27 inline bool isChildOf(const SubclassIdentifier<class B>* identifier)28 { this->getIdentifier()->isChildOf(identifier->getIdentifier()); }29 inline bool isParentOf(const SubclassIdentifier<class B>* identifier)30 { this->getIdentifier()->isParentOf(identifier->getIdentifier()); }31 32 inline bool isA(const SubclassIdentifier<class B> identifier)33 { this->getIdentifier()->isA(identifier.getIdentifier()); }34 inline bool isDirectlyA(const SubclassIdentifier<class B> identifier)35 { this->getIdentifier()->isDirectlyA(identifier.getIdentifier()); }36 inline bool isChildOf(const SubclassIdentifier<class B> identifier)37 { this->getIdentifier()->isChildOf(identifier.getIdentifier()); }38 inline bool isParentOf(const SubclassIdentifier<class B> identifier)39 { this->getIdentifier()->isParentOf(identifier.getIdentifier()); }40 41 inline bool isA(const OrxonoxClass* object)42 { this->getIdentifier()->isA(object->getIdentifier()); }43 inline bool isDirectlyA(const OrxonoxClass* object)44 { this->getIdentifier()->isDirectlyA(object->getIdentifier()); }45 inline bool isChildOf(const OrxonoxClass* object)46 { this->getIdentifier()->isChildOf(object->getIdentifier()); }47 inline bool isParentOf(const OrxonoxClass* object)48 { this->getIdentifier()->isParentOf(object->getIdentifier()); }49 50 std::string name_; // test51 52 13 }; 53 14 } -
code/branches/FICN/src/orxonox/objects/test1.cc
r258 r384 18 18 Test1::~Test1() 19 19 { 20 } 21 22 void Test1::tick(float dt) 23 { 24 std::cout << "Test1: " << this << "\n"; 20 25 } 21 26 -
code/branches/FICN/src/orxonox/objects/test1.h
r258 r384 3 3 4 4 #include "BaseObject.h" 5 #include "Tickable.h" 5 6 #include "test3.h" 6 7 7 8 namespace orxonox 8 9 { 9 class Test1 : public BaseObject 10 class Test1 : public BaseObject, public Tickable 10 11 { 11 12 public: 12 13 Test1(); 13 14 virtual ~Test1(); 15 16 virtual void tick(float dt); 14 17 15 18 bool usefullClass1isA(Identifier* identifier); -
code/branches/FICN/src/orxonox/objects/test2.cc
r258 r384 14 14 this->usefullClass2_ = Class(Test2); 15 15 this->usefullClass3_ = Class(Test3); 16 17 timer1.setTimer(1, true, this, &Test2::timerFunction1); 18 timer2.setTimer(5, true, this, &Test2::timerFunction2); 19 timer3.setTimer(10, false, this, &Test2::timerFunction3); 16 20 } 17 21 18 22 Test2::~Test2() 19 23 { 24 } 25 26 void Test2::timerFunction1() 27 { 28 std::cout << "Test2: 1 Sekunde\n"; 29 } 30 31 void Test2::timerFunction2() 32 { 33 std::cout << "Test2: 5 Sekunden\n"; 34 } 35 36 void Test2::timerFunction3() 37 { 38 std::cout << "Test2: 10 Sekunden sind um!\n"; 20 39 } 21 40 -
code/branches/FICN/src/orxonox/objects/test2.h
r258 r384 3 3 4 4 #include "BaseObject.h" 5 #include "Timer.h" 5 6 6 7 namespace orxonox … … 21 22 void setUsefullClassOfTypeTest3(Identifier* identifier); 22 23 24 void timerFunction1(); 25 void timerFunction2(); 26 void timerFunction3(); 27 23 28 private: 24 29 Identifier* usefullClass1_; … … 26 31 SubclassIdentifier<Test3> usefullClass3_; 27 32 33 Timer<Test2> timer1; 34 Timer<Test2> timer2; 35 Timer<Test2> timer3; 28 36 }; 29 37 }
Note: See TracChangeset
for help on using the changeset viewer.