[Orxonox-commit 812] r3333 - trunk/src/core
rgrieder at orxonox.net
rgrieder at orxonox.net
Wed Jul 22 13:00:46 CEST 2009
Author: rgrieder
Date: 2009-07-22 13:00:46 +0200 (Wed, 22 Jul 2009)
New Revision: 3333
Modified:
trunk/src/core/Identifier.h
trunk/src/core/OrxonoxClass.h
Log:
Adjusted orxonox_cast to support const pointers. References shall not be supported unless required.
Modified: trunk/src/core/Identifier.h
===================================================================
--- trunk/src/core/Identifier.h 2009-07-21 10:54:15 UTC (rev 3332)
+++ trunk/src/core/Identifier.h 2009-07-22 11:00:46 UTC (rev 3333)
@@ -457,7 +457,7 @@
object->metaList_->add(this->objects_, this->objects_->add(new ObjectListElement<T>(object)));
// Add pointer of type T to the map in the OrxonoxClass instance that enables "dynamic_casts"
- object->objectPointers_.push_back(std::make_pair(this->getClassID(), reinterpret_cast<void*>(object)));
+ object->objectPointers_.push_back(std::make_pair(this->getClassID(), static_cast<void*>(object)));
return false;
}
}
@@ -495,10 +495,10 @@
Also note that the function is implemented differently for GCC/MSVC.
*/
template <class T, class U>
- FORCEINLINE T orxonox_cast(U* source)
+ FORCEINLINE T orxonox_cast(U source)
{
#ifdef ORXONOX_COMPILER_MSVC
- typedef Loki::TypeTraits<T>::PointeeType ClassType;
+ typedef Loki::TypeTraits<typename Loki::TypeTraits<T>::PointeeType>::NonConstType ClassType;
return source->template getDerivedPointer<ClassType>(ClassIdentifier<ClassType>::getIdentifier()->getClassID());
#else
return dynamic_cast<T>(source);
Modified: trunk/src/core/OrxonoxClass.h
===================================================================
--- trunk/src/core/OrxonoxClass.h 2009-07-21 10:54:15 UTC (rev 3332)
+++ trunk/src/core/OrxonoxClass.h 2009-07-22 11:00:46 UTC (rev 3333)
@@ -100,15 +100,21 @@
Returns NULL if the no pointer was found.
*/
template <class T>
- FORCEINLINE T* getDerivedPointer(unsigned int classID) const
+ FORCEINLINE T* getDerivedPointer(unsigned int classID)
{
for (int i = this->objectPointers_.size() - 1; i >= 0; --i)
{
if (this->objectPointers_[i].first == classID)
- return reinterpret_cast<T*>(this->objectPointers_[i].second);
+ return static_cast<T*>(this->objectPointers_[i].second);
}
return NULL;
}
+ //! Const version of getDerivedPointer
+ template <class T>
+ FORCEINLINE const T* getDerivedPointer(unsigned int classID) const
+ {
+ return const_cast<OrxonoxClass*>(this)->getDerivedPointer<T>(classID);
+ }
private:
Identifier* identifier_; //!< The Identifier of the object
More information about the Orxonox-commit
mailing list