Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 3333


Ignore:
Timestamp:
Jul 22, 2009, 1:00:46 PM (15 years ago)
Author:
rgrieder
Message:

Adjusted orxonox_cast to support const pointers. References shall not be supported unless required.

Location:
code/trunk/src/core
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • code/trunk/src/core/Identifier.h

    r3332 r3333  
    458458
    459459            // Add pointer of type T to the map in the OrxonoxClass instance that enables "dynamic_casts"
    460             object->objectPointers_.push_back(std::make_pair(this->getClassID(), reinterpret_cast<void*>(object)));
     460            object->objectPointers_.push_back(std::make_pair(this->getClassID(), static_cast<void*>(object)));
    461461            return false;
    462462        }
     
    496496    */
    497497    template <class T, class U>
    498     FORCEINLINE T orxonox_cast(U* source)
     498    FORCEINLINE T orxonox_cast(U source)
    499499    {
    500500#ifdef ORXONOX_COMPILER_MSVC
    501         typedef Loki::TypeTraits<T>::PointeeType ClassType;
     501        typedef Loki::TypeTraits<typename Loki::TypeTraits<T>::PointeeType>::NonConstType ClassType;
    502502        return source->template getDerivedPointer<ClassType>(ClassIdentifier<ClassType>::getIdentifier()->getClassID());
    503503#else
  • code/trunk/src/core/OrxonoxClass.h

    r3327 r3333  
    101101            */
    102102            template <class T>
    103             FORCEINLINE T* getDerivedPointer(unsigned int classID) const
     103            FORCEINLINE T* getDerivedPointer(unsigned int classID)
    104104            {
    105105                for (int i = this->objectPointers_.size() - 1; i >= 0; --i)
    106106                {
    107107                    if (this->objectPointers_[i].first == classID)
    108                         return reinterpret_cast<T*>(this->objectPointers_[i].second);
     108                        return static_cast<T*>(this->objectPointers_[i].second);
    109109                }
    110110                return NULL;
     111            }
     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);
    111117            }
    112118
Note: See TracChangeset for help on using the changeset viewer.