Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Jun 28, 2009, 2:45:37 PM (15 years ago)
Author:
rgrieder
Message:

Found a way to write orxonox_cast<T*> instead of orxonox_cast<T> so that the syntax resembles dynamic_cast<T*>.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • code/branches/core4/src/core/Identifier.h

    r3224 r3239  
    483483    // ###      orxonox_cast       ###
    484484    // ###############################
     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
    485511    /**
    486512    @brief
     
    495521    */
    496522    template <class T, class U>
    497     FORCEINLINE T* orxonox_cast(U* source)
    498     {
    499 #ifdef ORXONOX_COMPILER_MSVC
    500         return source->template getDerivedPointer<T>(ClassIdentifier<T>::getIdentifier()->getClassID());
    501 #else
    502         return dynamic_cast<T*>(source);
    503 #endif
     523    FORCEINLINE T orxonox_cast(U* source)
     524    {
     525        return OrxonoxCaster<T, U>::cast(source);
    504526    }
    505527
     
    597619                if (newObject)
    598620                {
    599                     return orxonox_cast<T>(newObject);
     621                    return orxonox_cast<T*>(newObject);
    600622                }
    601623                else
Note: See TracChangeset for help on using the changeset viewer.