Changeset 5929 for code/trunk/src/libraries/core/OrxonoxClass.h
- Timestamp:
- Oct 12, 2009, 8:20:07 PM (15 years ago)
- Location:
- code/trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
code/trunk
- Property svn:mergeinfo changed
/code/branches/core5 (added) merged: 5768-5769,5772,5775-5780,5783-5785,5791-5792,5795-5807,5809-5814,5816-5832,5836-5839,5842-5853,5855-5899,5904-5922,5924-5928
- Property svn:mergeinfo changed
-
code/trunk/src/libraries/core/OrxonoxClass.h
r5738 r5929 55 55 friend class ClassIdentifier; 56 56 57 template <class T> 58 friend class SmartPtr; 59 60 template <class T> 61 friend class WeakPtr; 62 57 63 public: 58 64 OrxonoxClass(); 59 65 virtual ~OrxonoxClass(); 66 67 void destroy(); 60 68 61 69 /** @brief Function to collect the SetConfigValue-macro calls. */ … … 72 80 bool isDirectParentOf(const Identifier* identifier); 73 81 74 template <class B> bool isA(const SubclassIdentifier<B>* identifier); 75 template <class B> bool isExactlyA(const SubclassIdentifier<B>* identifier); 76 template <class B> bool isChildOf(const SubclassIdentifier<B>* identifier); 77 template <class B> bool isDirectChildOf(const SubclassIdentifier<B>* identifier); 78 template <class B> bool isParentOf(const SubclassIdentifier<B>* identifier); 79 template <class B> bool isDirectParentOf(const SubclassIdentifier<B>* identifier); 80 81 template <class B> bool isA(const SubclassIdentifier<B> identifier); 82 template <class B> bool isExactlyA(const SubclassIdentifier<B> identifier); 83 template <class B> bool isChildOf(const SubclassIdentifier<B> identifier); 84 template <class B> bool isDirectChildOf(const SubclassIdentifier<B> identifier); 85 template <class B> bool isParentOf(const SubclassIdentifier<B> identifier); 86 template <class B> bool isDirectParentOf(const SubclassIdentifier<B> identifier); 82 template <class B> inline bool isA(const SubclassIdentifier<B>* identifier) 83 { return this->isA(*identifier); } 84 template <class B> inline bool isExactlyA(const SubclassIdentifier<B>* identifier) 85 { return this->isExactlyA(*identifier); } 86 template <class B> inline bool isChildOf(const SubclassIdentifier<B>* identifier) 87 { return this->isChildOf(*identifier); } 88 template <class B> inline bool isDirectChildOf(const SubclassIdentifier<B>* identifier) 89 { return this->isDirectChildOf(*identifier); } 90 template <class B> inline bool isParentOf(const SubclassIdentifier<B>* identifier) 91 { return this->isParentOf(*identifier); } 92 template <class B> inline bool isDirectParentOf(const SubclassIdentifier<B>* identifier) 93 { return this->isDirectParentOf(*identifier); } 87 94 88 95 bool isA(const OrxonoxClass* object); … … 93 100 bool isDirectParentOf(const OrxonoxClass* object); 94 101 102 inline unsigned int getReferenceCount() const 103 { return this->referenceCount_; } 104 95 105 /** 96 106 @brief … … 100 110 Returns NULL if the no pointer was found. 101 111 */ 102 template <class T> 103 FORCEINLINE T* getDerivedPointer(unsigned int classID) 112 FORCEINLINE void* getDerivedPointer(unsigned int classID) 104 113 { 105 114 for (int i = this->objectPointers_.size() - 1; i >= 0; --i) 106 115 { 107 116 if (this->objectPointers_[i].first == classID) 108 return static_cast<T*>(this->objectPointers_[i].second);117 return this->objectPointers_[i].second; 109 118 } 110 119 return NULL; 111 120 } 112 //! Const version of getDerivedPointer 113 template <class T> 114 FORCEINLINE const T* getDerivedPointer(unsigned int classID) const 115 { 116 return const_cast<OrxonoxClass*>(this)->getDerivedPointer<T>(classID); 117 } 121 122 //! Version of getDerivedPointer with template 123 template <class T> FORCEINLINE T* getDerivedPointer(unsigned int classID) 124 { return static_cast<T*>(this->getDerivedPointer(classID)); } 125 //! Const version of getDerivedPointer with template 126 template <class T> FORCEINLINE const T* getDerivedPointer(unsigned int classID) const 127 { return const_cast<OrxonoxClass*>(this)->getDerivedPointer<T>(classID); } 118 128 119 129 private: 130 /** @brief Increments the reference counter (for smart pointers). */ 131 inline void incrementReferenceCount() 132 { ++this->referenceCount_; } 133 /** @brief Decrements the reference counter (for smart pointers). */ 134 inline void decrementReferenceCount() 135 { --this->referenceCount_; if (this->referenceCount_ == 0 && this->requestedDestruction_) { delete this; } } 136 137 /** @brief Register a weak pointer which points to this object. */ 138 template <class T> 139 inline void registerWeakPtr(WeakPtr<T>* pointer) 140 { this->weakPointers_.insert(reinterpret_cast<WeakPtr<OrxonoxClass>*>(pointer)); } 141 /** @brief Unegister a weak pointer which pointed to this object before. */ 142 template <class T> 143 inline void unregisterWeakPtr(WeakPtr<T>* pointer) 144 { this->weakPointers_.erase(reinterpret_cast<WeakPtr<OrxonoxClass>*>(pointer)); } 145 120 146 Identifier* identifier_; //!< The Identifier of the object 121 147 std::set<const Identifier*>* parents_; //!< List of all parents of the object 122 148 MetaObjectList* metaList_; //!< MetaObjectList, containing all ObjectLists and ObjectListElements the object is registered in 149 int referenceCount_; //!< Counts the references from smart pointers to this object 150 bool requestedDestruction_; //!< Becomes true after someone called delete on this object 151 std::set<WeakPtr<OrxonoxClass>*> weakPointers_; //!< All weak pointers which point to this object (and like to get notified if it dies) 152 123 153 //! 'Fast map' that holds this-pointers of all derived types 124 154 std::vector<std::pair<unsigned int, void*> > objectPointers_;
Note: See TracChangeset
for help on using the changeset viewer.