Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 9565 for code/branches/core6


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

Location:
code/branches/core6/src/libraries/core
Files:
4 edited
2 copied

Legend:

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

    r9561 r9565  
    155155    class GraphicsManager;
    156156    class GUIManager;
     157    class Identifiable;
    157158    class Identifier;
    158159    template <class T>
  • code/branches/core6/src/libraries/core/class/CMakeLists.txt

    r9564 r9565  
    11ADD_SOURCE_FILES(CORE_SRC_FILES
     2  Identifiable.cc
    23  Identifier.cc
    34  IdentifierManager.cc
  • code/branches/core6/src/libraries/core/class/Identifiable.cc

    r9563 r9565  
    3232*/
    3333
    34 #include "OrxonoxClass.h"
     34#include "Identifiable.h"
    3535
    3636#include <cassert>
     
    4444        @brief Constructor: Sets the default values.
    4545    */
    46     OrxonoxClass::OrxonoxClass()
     46    Identifiable::Identifiable()
    4747    {
    4848        this->identifier_ = 0;
    4949        this->parents_ = 0;
    5050        this->metaList_ = new MetaObjectList();
    51         this->referenceCount_ = 0;
    52         this->requestedDestruction_ = false;
    5351        // Optimisation
    5452        this->objectPointers_.reserve(6);
     
    5654
    5755    /**
    58         @brief Destructor: Removes the object from the object-lists, notifies all DestructionListener (for example @ref WeakPtr "weak pointers") that this object is being deleted.
     56        @brief Destructor: Removes the object from the object-lists
    5957    */
    60     OrxonoxClass::~OrxonoxClass()
     58    Identifiable::~Identifiable()
    6159    {
    6260//        if (!this->requestedDestruction_)
    6361//            orxout(internal_warning) << "Destroyed object without destroy() (" << this->getIdentifier()->getName() << ')' << endl;
    64 
    65         assert(this->referenceCount_ <= 0);
    6662
    6763        this->unregisterObject();
     
    7066        if (this->parents_)
    7167            delete this->parents_;
    72 
    73         // notify all destruction listeners
    74         for (std::set<DestructionListener*>::iterator it = this->destructionListeners_.begin(); it != this->destructionListeners_.end(); )
    75             (*(it++))->objectDeleted();
    76     }
    77 
    78     /**
    79         @brief Deletes the object if no @ref orxonox::SmartPtr "smart pointers" point to this object. Otherwise schedules the object to be deleted as soon as possible.
    80     */
    81     void OrxonoxClass::destroy()
    82     {
    83         assert(this); // Just in case someone tries to delete a NULL pointer
    84         this->requestedDestruction_ = true;
    85         if (this->referenceCount_ == 0)
    86         {
    87             this->preDestroy();
    88             if (this->referenceCount_ == 0)
    89                 delete this;
    90         }
    9168    }
    9269
     
    9471        @brief Removes this object from the object-lists.
    9572    */
    96     void OrxonoxClass::unregisterObject()
     73    void Identifiable::unregisterObject()
    9774    {
    9875        if (this->metaList_)
     
    10279
    10380    /// Returns true if the object's class is of the given type or a derivative.
    104     bool OrxonoxClass::isA(const Identifier* identifier)
     81    bool Identifiable::isA(const Identifier* identifier)
    10582        { return this->getIdentifier()->isA(identifier); }
    10683    /// Returns true if the object's class is exactly of the given type.
    107     bool OrxonoxClass::isExactlyA(const Identifier* identifier)
     84    bool Identifiable::isExactlyA(const Identifier* identifier)
    10885        { return this->getIdentifier()->isExactlyA(identifier); }
    10986    /// Returns true if the object's class is a child of the given type.
    110     bool OrxonoxClass::isChildOf(const Identifier* identifier)
     87    bool Identifiable::isChildOf(const Identifier* identifier)
    11188        { return this->getIdentifier()->isChildOf(identifier); }
    11289    /// Returns true if the object's class is a direct child of the given type.
    113     bool OrxonoxClass::isDirectChildOf(const Identifier* identifier)
     90    bool Identifiable::isDirectChildOf(const Identifier* identifier)
    11491        { return this->getIdentifier()->isDirectChildOf(identifier); }
    11592    /// Returns true if the object's class is a parent of the given type.
    116     bool OrxonoxClass::isParentOf(const Identifier* identifier)
     93    bool Identifiable::isParentOf(const Identifier* identifier)
    11794        { return this->getIdentifier()->isParentOf(identifier); }
    11895    /// Returns true if the object's class is a direct parent of the given type.
    119     bool OrxonoxClass::isDirectParentOf(const Identifier* identifier)
     96    bool Identifiable::isDirectParentOf(const Identifier* identifier)
    12097        { return this->getIdentifier()->isDirectParentOf(identifier); }
    12198
    12299
    123100    /// Returns true if the object's class is of the given type or a derivative.
    124     bool OrxonoxClass::isA(const OrxonoxClass* object)
     101    bool Identifiable::isA(const Identifiable* object)
    125102        { return this->getIdentifier()->isA(object->getIdentifier()); }
    126103    /// Returns true if the object's class is exactly of the given type.
    127     bool OrxonoxClass::isExactlyA(const OrxonoxClass* object)
     104    bool Identifiable::isExactlyA(const Identifiable* object)
    128105        { return this->getIdentifier()->isExactlyA(object->getIdentifier()); }
    129106    /// Returns true if the object's class is a child of the given type.
    130     bool OrxonoxClass::isChildOf(const OrxonoxClass* object)
     107    bool Identifiable::isChildOf(const Identifiable* object)
    131108        { return this->getIdentifier()->isChildOf(object->getIdentifier()); }
    132109    /// Returns true if the object's class is a direct child of the given type.
    133     bool OrxonoxClass::isDirectChildOf(const OrxonoxClass* object)
     110    bool Identifiable::isDirectChildOf(const Identifiable* object)
    134111        { return this->getIdentifier()->isDirectChildOf(object->getIdentifier()); }
    135112    /// Returns true if the object's class is a parent of the given type.
    136     bool OrxonoxClass::isParentOf(const OrxonoxClass* object)
     113    bool Identifiable::isParentOf(const Identifiable* object)
    137114        { return this->getIdentifier()->isParentOf(object->getIdentifier()); }
    138115    /// Returns true if the object's class is a direct child of the given type.
    139     bool OrxonoxClass::isDirectParentOf(const OrxonoxClass* object)
     116    bool Identifiable::isDirectParentOf(const Identifiable* object)
    140117        { return this->getIdentifier()->isDirectParentOf(object->getIdentifier()); }
    141118}
  • 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__ */
  • code/branches/core6/src/libraries/core/class/OrxonoxClass.cc

    r9563 r9565  
    4646    OrxonoxClass::OrxonoxClass()
    4747    {
    48         this->identifier_ = 0;
    49         this->parents_ = 0;
    50         this->metaList_ = new MetaObjectList();
    5148        this->referenceCount_ = 0;
    5249        this->requestedDestruction_ = false;
    53         // Optimisation
    54         this->objectPointers_.reserve(6);
    5550    }
    5651
    5752    /**
    58         @brief Destructor: Removes the object from the object-lists, notifies all DestructionListener (for example @ref WeakPtr "weak pointers") that this object is being deleted.
     53        @brief Destructor: Notifies all DestructionListener (for example @ref WeakPtr "weak pointers") that this object is being deleted.
    5954    */
    6055    OrxonoxClass::~OrxonoxClass()
    6156    {
    62 //        if (!this->requestedDestruction_)
    63 //            orxout(internal_warning) << "Destroyed object without destroy() (" << this->getIdentifier()->getName() << ')' << endl;
    64 
    6557        assert(this->referenceCount_ <= 0);
    66 
    67         this->unregisterObject();
    68 
    69         // parents_ exists only if isCreatingHierarchy() of the associated Identifier returned true while creating the class
    70         if (this->parents_)
    71             delete this->parents_;
    7258
    7359        // notify all destruction listeners
     
    9076        }
    9177    }
    92 
    93     /**
    94         @brief Removes this object from the object-lists.
    95     */
    96     void OrxonoxClass::unregisterObject()
    97     {
    98         if (this->metaList_)
    99             delete this->metaList_;
    100         this->metaList_ = 0;
    101     }
    102 
    103     /// Returns true if the object's class is of the given type or a derivative.
    104     bool OrxonoxClass::isA(const Identifier* identifier)
    105         { return this->getIdentifier()->isA(identifier); }
    106     /// Returns true if the object's class is exactly of the given type.
    107     bool OrxonoxClass::isExactlyA(const Identifier* identifier)
    108         { return this->getIdentifier()->isExactlyA(identifier); }
    109     /// Returns true if the object's class is a child of the given type.
    110     bool OrxonoxClass::isChildOf(const Identifier* identifier)
    111         { return this->getIdentifier()->isChildOf(identifier); }
    112     /// Returns true if the object's class is a direct child of the given type.
    113     bool OrxonoxClass::isDirectChildOf(const Identifier* identifier)
    114         { return this->getIdentifier()->isDirectChildOf(identifier); }
    115     /// Returns true if the object's class is a parent of the given type.
    116     bool OrxonoxClass::isParentOf(const Identifier* identifier)
    117         { return this->getIdentifier()->isParentOf(identifier); }
    118     /// Returns true if the object's class is a direct parent of the given type.
    119     bool OrxonoxClass::isDirectParentOf(const Identifier* identifier)
    120         { return this->getIdentifier()->isDirectParentOf(identifier); }
    121 
    122 
    123     /// Returns true if the object's class is of the given type or a derivative.
    124     bool OrxonoxClass::isA(const OrxonoxClass* object)
    125         { return this->getIdentifier()->isA(object->getIdentifier()); }
    126     /// Returns true if the object's class is exactly of the given type.
    127     bool OrxonoxClass::isExactlyA(const OrxonoxClass* object)
    128         { return this->getIdentifier()->isExactlyA(object->getIdentifier()); }
    129     /// Returns true if the object's class is a child of the given type.
    130     bool OrxonoxClass::isChildOf(const OrxonoxClass* object)
    131         { return this->getIdentifier()->isChildOf(object->getIdentifier()); }
    132     /// Returns true if the object's class is a direct child of the given type.
    133     bool OrxonoxClass::isDirectChildOf(const OrxonoxClass* object)
    134         { return this->getIdentifier()->isDirectChildOf(object->getIdentifier()); }
    135     /// Returns true if the object's class is a parent of the given type.
    136     bool OrxonoxClass::isParentOf(const OrxonoxClass* object)
    137         { return this->getIdentifier()->isParentOf(object->getIdentifier()); }
    138     /// Returns true if the object's class is a direct child of the given type.
    139     bool OrxonoxClass::isDirectParentOf(const OrxonoxClass* object)
    140         { return this->getIdentifier()->isDirectParentOf(object->getIdentifier()); }
    14178}
  • code/branches/core6/src/libraries/core/class/OrxonoxClass.h

    r9563 r9565  
    3636    @ingroup Class OrxonoxClass
    3737    @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.
    40     It stores the Identifier and the MetaObjectList and has all needed functions to create and use the class-hierarchy.
    4138*/
    4239
     
    4744
    4845#include <set>
    49 #include <vector>
    50 #include "Super.h"
     46//#include "Super.h"
     47#include "Identifiable.h"
    5148
    5249namespace orxonox
     
    5653
    5754        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.
    6055    */
    61     class _CoreExport OrxonoxClass
     56    class _CoreExport OrxonoxClass : public Identifiable
    6257    {
    63         template <class T>
    64         friend class ClassIdentifier;
    65 
    6658        template <class T>
    6759        friend class SmartPtr;
     
    7466
    7567            void destroy();
    76             void unregisterObject();
    7768
    7869            /// Function to collect the SetConfigValue-macro calls.
    7970            void setConfigValues() {};
    8071
    81             /// Returns the Identifier of the object.
    82             inline Identifier* getIdentifier() const { return this->identifier_; }
    83 
    84             bool isA(const Identifier* identifier);
    85             bool isExactlyA(const Identifier* identifier);
    86             bool isChildOf(const Identifier* identifier);
    87             bool isDirectChildOf(const Identifier* identifier);
    88             bool isParentOf(const Identifier* identifier);
    89             bool isDirectParentOf(const Identifier* identifier);
    90 
    91             /// Returns true if the object's class is of the given type or a derivative.
    92             template <class B> inline bool isA(const SubclassIdentifier<B>* identifier)
    93                 { return this->isA(*identifier); }
    94             /// Returns true if the object's class is exactly of the given type.
    95             template <class B> inline bool isExactlyA(const SubclassIdentifier<B>* identifier)
    96                 { return this->isExactlyA(*identifier); }
    97             /// Returns true if the object's class is a child of the given type.
    98             template <class B> inline bool isChildOf(const SubclassIdentifier<B>* identifier)
    99                 { return this->isChildOf(*identifier); }
    100             /// Returns true if the object's class is a direct child of the given type.
    101             template <class B> inline bool isDirectChildOf(const SubclassIdentifier<B>* identifier)
    102                 { return this->isDirectChildOf(*identifier); }
    103             /// Returns true if the object's class is a parent of the given type.
    104             template <class B> inline bool isParentOf(const SubclassIdentifier<B>* identifier)
    105                 { return this->isParentOf(*identifier); }
    106             /// Returns true if the object's class is a direct parent of the given type.
    107             template <class B> inline bool isDirectParentOf(const SubclassIdentifier<B>* identifier)
    108                 { return this->isDirectParentOf(*identifier); }
    109 
    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 
    11772            /// Returns the number of @ref orxonox::SmartPtr "smart pointers" that point to this object.
    11873            inline unsigned int getReferenceCount() const
    11974                { return this->referenceCount_; }
    120 
    121             /**
    122             @brief
    123                 Returns a valid pointer of any derived type that is
    124                 registered in the class hierarchy.
    125             @return
    126                 Returns NULL if the no pointer was found.
    127             */
    128             ORX_FORCEINLINE void* getDerivedPointer(unsigned int classID)
    129             {
    130                 for (int i = this->objectPointers_.size() - 1; i >= 0; --i)
    131                 {
    132                     if (this->objectPointers_[i].first == classID)
    133                         return this->objectPointers_[i].second;
    134                 }
    135                 return NULL;
    136             }
    137 
    138             /// Version of getDerivedPointer with template
    139             template <class T> ORX_FORCEINLINE T* getDerivedPointer(unsigned int classID)
    140             {   return static_cast<T*>(this->getDerivedPointer(classID));   }
    141             /// Const version of getDerivedPointer with template
    142             template <class T> ORX_FORCEINLINE const T* getDerivedPointer(unsigned int classID) const
    143             {   return const_cast<OrxonoxClass*>(this)->getDerivedPointer<T>(classID);   }
    14475
    14576        protected:
     
    16697                { this->destructionListeners_.erase(pointer); }
    16798
    168             Identifier* identifier_;                                //!< The Identifier of the object
    169             std::set<const Identifier*>* parents_;                  //!< List of all parents of the object
    170             MetaObjectList* metaList_;                              //!< MetaObjectList, containing all ObjectLists and ObjectListElements the object is registered in
    17199            int referenceCount_;                                    //!< Counts the references from smart pointers to this object
    172100            bool requestedDestruction_;                             //!< Becomes true after someone called delete on this object
    173101            std::set<DestructionListener*> destructionListeners_;   //!< All destruction listeners (for example weak pointers which point to this object and like to get notified if it dies)
    174 
    175             /// 'Fast map' that holds this-pointers of all derived types
    176             std::vector<std::pair<unsigned int, void*> > objectPointers_;
    177102    };
    178103
Note: See TracChangeset for help on using the changeset viewer.