- Timestamp:
- Mar 24, 2013, 6:34:23 PM (11 years ago)
- File:
-
- 1 copied
Legend:
- Unmodified
- Added
- Removed
-
code/branches/core6/src/libraries/core/class/Identifiable.h
r9563 r9565 28 28 29 29 /** 30 @ defgroup OrxonoxClass OrxonoxClass31 @ingroup Class 32 */ 30 @file 31 @ingroup Class Identifier 32 @brief Declaration of Identifiable, the base of all classes that should own an Identifier. 33 33 34 /**35 @file36 @ingroup Class OrxonoxClass37 @brief Declaration of OrxonoxClass, the base class of all objects and interfaces in Orxonox.38 39 All objects and interfaces of the game-logic (not the engine) are derived from OrxonoxClass.40 34 It stores the Identifier and the MetaObjectList and has all needed functions to create and use the class-hierarchy. 41 35 */ 42 36 43 #ifndef _ OrxonoxClass_H__44 #define _ OrxonoxClass_H__37 #ifndef _Identifiable_H__ 38 #define _Identifiable_H__ 45 39 46 40 #include "core/CorePrereqs.h" … … 48 42 #include <set> 49 43 #include <vector> 50 #include "Super.h"51 44 52 45 namespace orxonox 53 46 { 54 47 /** 55 @brief The class all objects and interfaces of the game-logic (not the engine) are derived from. 56 57 The BaseObject and Interfaces are derived with @c virtual @c public @c OrxonoxClass from OrxonoxClass. 58 OrxonoxClass is needed to create the class-hierarchy at startup and to store the Identifier and the 59 MetaObjectList, as well as to provide an interface for SmartPtr and WeakPtr. 48 @brief Identifiable is needed to create the class-hierarchy at startup and to store the Identifier and the MetaObjectList. 60 49 */ 61 class _CoreExport OrxonoxClass50 class _CoreExport Identifiable 62 51 { 63 52 template <class T> 64 53 friend class ClassIdentifier; 65 54 66 template <class T>67 friend class SmartPtr;68 69 friend class DestructionListener;70 71 55 public: 72 OrxonoxClass();73 virtual ~ OrxonoxClass();56 Identifiable(); 57 virtual ~Identifiable(); 74 58 75 59 void destroy(); 76 60 void unregisterObject(); 77 78 /// Function to collect the SetConfigValue-macro calls.79 void setConfigValues() {};80 61 81 62 /// Returns the Identifier of the object. … … 108 89 { return this->isDirectParentOf(*identifier); } 109 90 110 bool isA(const OrxonoxClass* object); 111 bool isExactlyA(const OrxonoxClass* object); 112 bool isChildOf(const OrxonoxClass* object); 113 bool isDirectChildOf(const OrxonoxClass* object); 114 bool isParentOf(const OrxonoxClass* object); 115 bool isDirectParentOf(const OrxonoxClass* object); 116 117 /// Returns the number of @ref orxonox::SmartPtr "smart pointers" that point to this object. 118 inline unsigned int getReferenceCount() const 119 { return this->referenceCount_; } 91 bool isA(const Identifiable* object); 92 bool isExactlyA(const Identifiable* object); 93 bool isChildOf(const Identifiable* object); 94 bool isDirectChildOf(const Identifiable* object); 95 bool isParentOf(const Identifiable* object); 96 bool isDirectParentOf(const Identifiable* object); 120 97 121 98 /** … … 141 118 /// Const version of getDerivedPointer with template 142 119 template <class T> ORX_FORCEINLINE const T* getDerivedPointer(unsigned int classID) const 143 { return const_cast<OrxonoxClass*>(this)->getDerivedPointer<T>(classID); } 144 145 protected: 146 /// 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. 147 virtual void preDestroy() {} 120 { return const_cast<Identifiable*>(this)->getDerivedPointer<T>(classID); } 148 121 149 122 private: 150 /// Increments the reference counter (for smart pointers).151 inline void incrementReferenceCount()152 { ++this->referenceCount_; }153 /// Decrements the reference counter (for smart pointers).154 inline void decrementReferenceCount()155 {156 --this->referenceCount_;157 if (this->referenceCount_ == 0 && this->requestedDestruction_)158 this->destroy();159 }160 161 /// Register a destruction listener (for example a weak pointer which points to this object).162 inline void registerDestructionListener(DestructionListener* pointer)163 { this->destructionListeners_.insert(pointer); }164 /// Unegister a destruction listener (for example a weak pointer which pointed to this object before).165 inline void unregisterDestructionListener(DestructionListener* pointer)166 { this->destructionListeners_.erase(pointer); }167 168 123 Identifier* identifier_; //!< The Identifier of the object 169 124 std::set<const Identifier*>* parents_; //!< List of all parents of the object 170 125 MetaObjectList* metaList_; //!< MetaObjectList, containing all ObjectLists and ObjectListElements the object is registered in 171 int referenceCount_; //!< Counts the references from smart pointers to this object172 bool requestedDestruction_; //!< Becomes true after someone called delete on this object173 std::set<DestructionListener*> destructionListeners_; //!< All destruction listeners (for example weak pointers which point to this object and like to get notified if it dies)174 126 175 127 /// 'Fast map' that holds this-pointers of all derived types 176 128 std::vector<std::pair<unsigned int, void*> > objectPointers_; 177 129 }; 178 179 /**180 @brief This listener is used to inform weak pointers if an object of type OrxonoxClass gets destroyed.181 */182 class _CoreExport DestructionListener183 {184 friend class OrxonoxClass;185 186 protected:187 virtual ~DestructionListener() {}188 189 inline void registerAsDestructionListener(OrxonoxClass* object)190 { if (object) { object->registerDestructionListener(this); } }191 inline void unregisterAsDestructionListener(OrxonoxClass* object)192 { if (object) { object->unregisterDestructionListener(this); } }193 194 virtual void objectDeleted() = 0;195 };196 197 130 } 198 131 199 #endif /* _ OrxonoxClass_H__ */132 #endif /* _Identifiable_H__ */
Note: See TracChangeset
for help on using the changeset viewer.