Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Jul 21, 2009, 12:54:15 PM (15 years ago)
Author:
rgrieder
Message:

Added TypeTraits.h from the Loki library (stripped it a bit though). This should make things a bit less error prone since Andrei Alexandrescu really is the master of templates ;)

File:
1 edited

Legend:

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

    r3325 r3332  
    6262
    6363#include "util/Debug.h"
     64#include "util/TypeTraits.h"
    6465#include "MetaObjectList.h"
    6566#include "ObjectList.h"
     
    483484    // ###      orxonox_cast       ###
    484485    // ###############################
    485     //! Helper struct to have orxonox_cast<T*> instead of orxonox_cast<T>
    486     template <class T, class U>
    487     struct OrxonoxCaster
    488     {
    489         static T* cast(U* source)
    490         {
    491             // If you see this function in a compiler error description, it means
    492             // you were misusing orxonox_cast. You must always cast to a pointer type!
    493             *****T();
    494         }
    495     };
    496 
    497     //! Helper struct to have orxonox_cast<T*> instead of orxonox_cast<T*>
    498     template <class T, class U>
    499     struct OrxonoxCaster<T*, U>
    500     {
    501         FORCEINLINE static T* cast(U* source)
    502         {
    503 #ifdef ORXONOX_COMPILER_MSVC
    504             return source->template getDerivedPointer<T>(ClassIdentifier<T>::getIdentifier()->getClassID());
    505 #else
    506             return dynamic_cast<T*>(source);
    507 #endif
    508         }
    509     };
    510 
    511486    /**
    512487    @brief
     
    523498    FORCEINLINE T orxonox_cast(U* source)
    524499    {
    525         return OrxonoxCaster<T, U>::cast(source);
     500#ifdef ORXONOX_COMPILER_MSVC
     501        typedef Loki::TypeTraits<T>::PointeeType ClassType;
     502        return source->template getDerivedPointer<ClassType>(ClassIdentifier<ClassType>::getIdentifier()->getClassID());
     503#else
     504        return dynamic_cast<T>(source);
     505#endif
    526506    }
    527507
Note: See TracChangeset for help on using the changeset viewer.