Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Mar 24, 2013, 6:34:23 PM (11 years ago)
Author:
landauf
Message:

moved functions and attributes needed to identify the class from OrxonoxClass to Identifiable

File:
1 copied

Legend:

Unmodified
Added
Removed
  • code/branches/core6/src/libraries/core/class/Identifiable.h

    r9563 r9565  
    2828
    2929/**
    30     @defgroup OrxonoxClass OrxonoxClass
    31     @ingroup Class
    32 */
     30    @file
     31    @ingroup Class Identifier
     32    @brief Declaration of Identifiable, the base of all classes that should own an Identifier.
    3333
    34 /**
    35     @file
    36     @ingroup Class OrxonoxClass
    37     @brief Declaration of OrxonoxClass, the base class of all objects and interfaces in Orxonox.
    38 
    39     All objects and interfaces of the game-logic (not the engine) are derived from OrxonoxClass.
    4034    It stores the Identifier and the MetaObjectList and has all needed functions to create and use the class-hierarchy.
    4135*/
    4236
    43 #ifndef _OrxonoxClass_H__
    44 #define _OrxonoxClass_H__
     37#ifndef _Identifiable_H__
     38#define _Identifiable_H__
    4539
    4640#include "core/CorePrereqs.h"
     
    4842#include <set>
    4943#include <vector>
    50 #include "Super.h"
    5144
    5245namespace orxonox
    5346{
    5447    /**
    55         @brief The class all objects and interfaces of the game-logic (not the engine) are derived from.
    56 
    57         The BaseObject and Interfaces are derived with @c virtual @c public @c OrxonoxClass from OrxonoxClass.
    58         OrxonoxClass is needed to create the class-hierarchy at startup and to store the Identifier and the
    59         MetaObjectList, as well as to provide an interface for SmartPtr and WeakPtr.
     48        @brief Identifiable is needed to create the class-hierarchy at startup and to store the Identifier and the MetaObjectList.
    6049    */
    61     class _CoreExport OrxonoxClass
     50    class _CoreExport Identifiable
    6251    {
    6352        template <class T>
    6453        friend class ClassIdentifier;
    6554
    66         template <class T>
    67         friend class SmartPtr;
    68 
    69         friend class DestructionListener;
    70 
    7155        public:
    72             OrxonoxClass();
    73             virtual ~OrxonoxClass();
     56            Identifiable();
     57            virtual ~Identifiable();
    7458
    7559            void destroy();
    7660            void unregisterObject();
    77 
    78             /// Function to collect the SetConfigValue-macro calls.
    79             void setConfigValues() {};
    8061
    8162            /// Returns the Identifier of the object.
     
    10889                { return this->isDirectParentOf(*identifier); }
    10990
    110             bool isA(const OrxonoxClass* object);
    111             bool isExactlyA(const OrxonoxClass* object);
    112             bool isChildOf(const OrxonoxClass* object);
    113             bool isDirectChildOf(const OrxonoxClass* object);
    114             bool isParentOf(const OrxonoxClass* object);
    115             bool isDirectParentOf(const OrxonoxClass* object);
    116 
    117             /// Returns the number of @ref orxonox::SmartPtr "smart pointers" that point to this object.
    118             inline unsigned int getReferenceCount() const
    119                 { return this->referenceCount_; }
     91            bool isA(const Identifiable* object);
     92            bool isExactlyA(const Identifiable* object);
     93            bool isChildOf(const Identifiable* object);
     94            bool isDirectChildOf(const Identifiable* object);
     95            bool isParentOf(const Identifiable* object);
     96            bool isDirectParentOf(const Identifiable* object);
    12097
    12198            /**
     
    141118            /// Const version of getDerivedPointer with template
    142119            template <class T> ORX_FORCEINLINE const T* getDerivedPointer(unsigned int classID) const
    143             {   return const_cast<OrxonoxClass*>(this)->getDerivedPointer<T>(classID);   }
    144 
    145         protected:
    146             /// This virtual function is called if destroy() is called and no SmartPtr points to this object. Used in some cases to create a new SmartPtr to prevent destruction.
    147             virtual void preDestroy() {}
     120            {   return const_cast<Identifiable*>(this)->getDerivedPointer<T>(classID);   }
    148121
    149122        private:
    150             /// Increments the reference counter (for smart pointers).
    151             inline void incrementReferenceCount()
    152                 { ++this->referenceCount_; }
    153             /// Decrements the reference counter (for smart pointers).
    154             inline void decrementReferenceCount()
    155             {
    156                 --this->referenceCount_;
    157                 if (this->referenceCount_ == 0 && this->requestedDestruction_)
    158                     this->destroy();
    159             }
    160 
    161             /// Register a destruction listener (for example a weak pointer which points to this object).
    162             inline void registerDestructionListener(DestructionListener* pointer)
    163                 { this->destructionListeners_.insert(pointer); }
    164             /// Unegister a destruction listener (for example a weak pointer which pointed to this object before).
    165             inline void unregisterDestructionListener(DestructionListener* pointer)
    166                 { this->destructionListeners_.erase(pointer); }
    167 
    168123            Identifier* identifier_;                                //!< The Identifier of the object
    169124            std::set<const Identifier*>* parents_;                  //!< List of all parents of the object
    170125            MetaObjectList* metaList_;                              //!< MetaObjectList, containing all ObjectLists and ObjectListElements the object is registered in
    171             int referenceCount_;                                    //!< Counts the references from smart pointers to this object
    172             bool requestedDestruction_;                             //!< Becomes true after someone called delete on this object
    173             std::set<DestructionListener*> destructionListeners_;   //!< All destruction listeners (for example weak pointers which point to this object and like to get notified if it dies)
    174126
    175127            /// 'Fast map' that holds this-pointers of all derived types
    176128            std::vector<std::pair<unsigned int, void*> > objectPointers_;
    177129    };
    178 
    179     /**
    180         @brief This listener is used to inform weak pointers if an object of type OrxonoxClass gets destroyed.
    181     */
    182     class _CoreExport DestructionListener
    183     {
    184         friend class OrxonoxClass;
    185 
    186         protected:
    187             virtual ~DestructionListener() {}
    188 
    189             inline void registerAsDestructionListener(OrxonoxClass* object)
    190                 { if (object) { object->registerDestructionListener(this); } }
    191             inline void unregisterAsDestructionListener(OrxonoxClass* object)
    192                 { if (object) { object->unregisterDestructionListener(this); } }
    193 
    194             virtual void objectDeleted() = 0;
    195     };
    196 
    197130}
    198131
    199 #endif /* _OrxonoxClass_H__ */
     132#endif /* _Identifiable_H__ */
Note: See TracChangeset for help on using the changeset viewer.