Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Jun 23, 2009, 7:28:48 PM (15 years ago)
Author:
rgrieder
Message:

Add a new core-feature: orxonox_cast<T>()
The functions casts objects like dynamic_cast, but uses the identifier instead for MSVC (much faster) and is just a redirection to dynamic_cast for GCC.
Also replaced almost all dynamic_casts (of course only those related to the class hierarchy).

File:
1 edited

Legend:

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

    r3196 r3223  
    5050    class _CoreExport OrxonoxClass
    5151    {
     52        template <class T>
     53        friend class ClassIdentifier;
     54
    5255        public:
    5356            OrxonoxClass();
     
    101104            bool isDirectParentOf(const OrxonoxClass* object);
    102105
     106            /**
     107            @brief
     108                Returns a valid pointer of any derived type that is
     109                registered in the class hierarchy.
     110            @return
     111                Returns NULL if the no pointer was found.
     112            */
     113            template <class T>
     114            FORCEINLINE T* getDerivedPointer(unsigned int classID) const
     115            {
     116                for (int i = this->objectPointers_.size() - 1; i >= 0; --i)
     117                {
     118                    if (this->objectPointers_[i].first == classID)
     119                        return reinterpret_cast<T*>(this->objectPointers_[i].second);
     120                }
     121                return NULL;
     122            }
     123
    103124        private:
    104125            Identifier* identifier_;                   //!< The Identifier of the object
    105126            std::set<const Identifier*>* parents_;     //!< List of all parents of the object
    106127            MetaObjectList* metaList_;                 //!< MetaObjectList, containing all ObjectLists and ObjectListElements the object is registered in
     128            //! 'Fast map' that holds this-pointers of all derived types
     129            std::vector<std::pair<unsigned int, void*> > objectPointers_;
    107130    };
    108131}
Note: See TracChangeset for help on using the changeset viewer.