[Orxonox-commit 4896] r9565 - in code/branches/core6/src/libraries/core: . class

landauf at orxonox.net landauf at orxonox.net
Sun Mar 24 18:34:23 CET 2013


Author: landauf
Date: 2013-03-24 18:34:23 +0100 (Sun, 24 Mar 2013)
New Revision: 9565

Added:
   code/branches/core6/src/libraries/core/class/Identifiable.cc
   code/branches/core6/src/libraries/core/class/Identifiable.h
Modified:
   code/branches/core6/src/libraries/core/CorePrereqs.h
   code/branches/core6/src/libraries/core/class/CMakeLists.txt
   code/branches/core6/src/libraries/core/class/OrxonoxClass.cc
   code/branches/core6/src/libraries/core/class/OrxonoxClass.h
Log:
moved functions and attributes needed to identify the class from OrxonoxClass to Identifiable

Modified: code/branches/core6/src/libraries/core/CorePrereqs.h
===================================================================
--- code/branches/core6/src/libraries/core/CorePrereqs.h	2013-03-24 17:08:42 UTC (rev 9564)
+++ code/branches/core6/src/libraries/core/CorePrereqs.h	2013-03-24 17:34:23 UTC (rev 9565)
@@ -154,6 +154,7 @@
     struct GameStateTreeNode;
     class GraphicsManager;
     class GUIManager;
+    class Identifiable;
     class Identifier;
     template <class T>
     class Iterator;

Modified: code/branches/core6/src/libraries/core/class/CMakeLists.txt
===================================================================
--- code/branches/core6/src/libraries/core/class/CMakeLists.txt	2013-03-24 17:08:42 UTC (rev 9564)
+++ code/branches/core6/src/libraries/core/class/CMakeLists.txt	2013-03-24 17:34:23 UTC (rev 9565)
@@ -1,4 +1,5 @@
 ADD_SOURCE_FILES(CORE_SRC_FILES
+  Identifiable.cc
   Identifier.cc
   IdentifierManager.cc
   OrxonoxClass.cc

Copied: code/branches/core6/src/libraries/core/class/Identifiable.cc (from rev 9563, code/branches/core6/src/libraries/core/class/OrxonoxClass.cc)
===================================================================
--- code/branches/core6/src/libraries/core/class/Identifiable.cc	                        (rev 0)
+++ code/branches/core6/src/libraries/core/class/Identifiable.cc	2013-03-24 17:34:23 UTC (rev 9565)
@@ -0,0 +1,118 @@
+/*
+ *   ORXONOX - the hottest 3D action shooter ever to exist
+ *                    > www.orxonox.net <
+ *
+ *
+ *   License notice:
+ *
+ *   This program is free software; you can redistribute it and/or
+ *   modify it under the terms of the GNU General Public License
+ *   as published by the Free Software Foundation; either version 2
+ *   of the License, or (at your option) any later version.
+ *
+ *   This program is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *   GNU General Public License for more details.
+ *
+ *   You should have received a copy of the GNU General Public License
+ *   along with this program; if not, write to the Free Software
+ *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ *
+ *   Author:
+ *      Fabian 'x3n' Landau
+ *   Co-authors:
+ *      ...
+ *
+ */
+
+/**
+    @file
+    @brief Implementation of OrxonoxClass.
+*/
+
+#include "Identifiable.h"
+
+#include <cassert>
+#include "core/object/MetaObjectList.h"
+#include "core/object/Context.h"
+#include "Identifier.h"
+
+namespace orxonox
+{
+    /**
+        @brief Constructor: Sets the default values.
+    */
+    Identifiable::Identifiable()
+    {
+        this->identifier_ = 0;
+        this->parents_ = 0;
+        this->metaList_ = new MetaObjectList();
+        // Optimisation
+        this->objectPointers_.reserve(6);
+    }
+
+    /**
+        @brief Destructor: Removes the object from the object-lists
+    */
+    Identifiable::~Identifiable()
+    {
+//        if (!this->requestedDestruction_)
+//            orxout(internal_warning) << "Destroyed object without destroy() (" << this->getIdentifier()->getName() << ')' << endl;
+
+        this->unregisterObject();
+
+        // parents_ exists only if isCreatingHierarchy() of the associated Identifier returned true while creating the class
+        if (this->parents_)
+            delete this->parents_;
+    }
+
+    /**
+        @brief Removes this object from the object-lists.
+    */
+    void Identifiable::unregisterObject()
+    {
+        if (this->metaList_)
+            delete this->metaList_;
+        this->metaList_ = 0;
+    }
+
+    /// Returns true if the object's class is of the given type or a derivative.
+    bool Identifiable::isA(const Identifier* identifier)
+        { return this->getIdentifier()->isA(identifier); }
+    /// Returns true if the object's class is exactly of the given type.
+    bool Identifiable::isExactlyA(const Identifier* identifier)
+        { return this->getIdentifier()->isExactlyA(identifier); }
+    /// Returns true if the object's class is a child of the given type.
+    bool Identifiable::isChildOf(const Identifier* identifier)
+        { return this->getIdentifier()->isChildOf(identifier); }
+    /// Returns true if the object's class is a direct child of the given type.
+    bool Identifiable::isDirectChildOf(const Identifier* identifier)
+        { return this->getIdentifier()->isDirectChildOf(identifier); }
+    /// Returns true if the object's class is a parent of the given type.
+    bool Identifiable::isParentOf(const Identifier* identifier)
+        { return this->getIdentifier()->isParentOf(identifier); }
+    /// Returns true if the object's class is a direct parent of the given type.
+    bool Identifiable::isDirectParentOf(const Identifier* identifier)
+        { return this->getIdentifier()->isDirectParentOf(identifier); }
+
+
+    /// Returns true if the object's class is of the given type or a derivative.
+    bool Identifiable::isA(const Identifiable* object)
+        { return this->getIdentifier()->isA(object->getIdentifier()); }
+    /// Returns true if the object's class is exactly of the given type.
+    bool Identifiable::isExactlyA(const Identifiable* object)
+        { return this->getIdentifier()->isExactlyA(object->getIdentifier()); }
+    /// Returns true if the object's class is a child of the given type.
+    bool Identifiable::isChildOf(const Identifiable* object)
+        { return this->getIdentifier()->isChildOf(object->getIdentifier()); }
+    /// Returns true if the object's class is a direct child of the given type.
+    bool Identifiable::isDirectChildOf(const Identifiable* object)
+        { return this->getIdentifier()->isDirectChildOf(object->getIdentifier()); }
+    /// Returns true if the object's class is a parent of the given type.
+    bool Identifiable::isParentOf(const Identifiable* object)
+        { return this->getIdentifier()->isParentOf(object->getIdentifier()); }
+    /// Returns true if the object's class is a direct child of the given type.
+    bool Identifiable::isDirectParentOf(const Identifiable* object)
+        { return this->getIdentifier()->isDirectParentOf(object->getIdentifier()); }
+}

Copied: code/branches/core6/src/libraries/core/class/Identifiable.h (from rev 9563, code/branches/core6/src/libraries/core/class/OrxonoxClass.h)
===================================================================
--- code/branches/core6/src/libraries/core/class/Identifiable.h	                        (rev 0)
+++ code/branches/core6/src/libraries/core/class/Identifiable.h	2013-03-24 17:34:23 UTC (rev 9565)
@@ -0,0 +1,132 @@
+/*
+ *   ORXONOX - the hottest 3D action shooter ever to exist
+ *                    > www.orxonox.net <
+ *
+ *
+ *   License notice:
+ *
+ *   This program is free software; you can redistribute it and/or
+ *   modify it under the terms of the GNU General Public License
+ *   as published by the Free Software Foundation; either version 2
+ *   of the License, or (at your option) any later version.
+ *
+ *   This program is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *   GNU General Public License for more details.
+ *
+ *   You should have received a copy of the GNU General Public License
+ *   along with this program; if not, write to the Free Software
+ *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ *
+ *   Author:
+ *      Fabian 'x3n' Landau
+ *   Co-authors:
+ *      ...
+ *
+ */
+
+/**
+    @file
+    @ingroup Class Identifier
+    @brief Declaration of Identifiable, the base of all classes that should own an Identifier.
+
+    It stores the Identifier and the MetaObjectList and has all needed functions to create and use the class-hierarchy.
+*/
+
+#ifndef _Identifiable_H__
+#define _Identifiable_H__
+
+#include "core/CorePrereqs.h"
+
+#include <set>
+#include <vector>
+
+namespace orxonox
+{
+    /**
+        @brief Identifiable is needed to create the class-hierarchy at startup and to store the Identifier and the MetaObjectList.
+    */
+    class _CoreExport Identifiable
+    {
+        template <class T>
+        friend class ClassIdentifier;
+
+        public:
+            Identifiable();
+            virtual ~Identifiable();
+
+            void destroy();
+            void unregisterObject();
+
+            /// Returns the Identifier of the object.
+            inline Identifier* getIdentifier() const { return this->identifier_; }
+
+            bool isA(const Identifier* identifier);
+            bool isExactlyA(const Identifier* identifier);
+            bool isChildOf(const Identifier* identifier);
+            bool isDirectChildOf(const Identifier* identifier);
+            bool isParentOf(const Identifier* identifier);
+            bool isDirectParentOf(const Identifier* identifier);
+
+            /// Returns true if the object's class is of the given type or a derivative.
+            template <class B> inline bool isA(const SubclassIdentifier<B>* identifier)
+                { return this->isA(*identifier); }
+            /// Returns true if the object's class is exactly of the given type.
+            template <class B> inline bool isExactlyA(const SubclassIdentifier<B>* identifier)
+                { return this->isExactlyA(*identifier); }
+            /// Returns true if the object's class is a child of the given type.
+            template <class B> inline bool isChildOf(const SubclassIdentifier<B>* identifier)
+                { return this->isChildOf(*identifier); }
+            /// Returns true if the object's class is a direct child of the given type.
+            template <class B> inline bool isDirectChildOf(const SubclassIdentifier<B>* identifier)
+                { return this->isDirectChildOf(*identifier); }
+            /// Returns true if the object's class is a parent of the given type.
+            template <class B> inline bool isParentOf(const SubclassIdentifier<B>* identifier)
+                { return this->isParentOf(*identifier); }
+            /// Returns true if the object's class is a direct parent of the given type.
+            template <class B> inline bool isDirectParentOf(const SubclassIdentifier<B>* identifier)
+                { return this->isDirectParentOf(*identifier); }
+
+            bool isA(const Identifiable* object);
+            bool isExactlyA(const Identifiable* object);
+            bool isChildOf(const Identifiable* object);
+            bool isDirectChildOf(const Identifiable* object);
+            bool isParentOf(const Identifiable* object);
+            bool isDirectParentOf(const Identifiable* object);
+
+            /**
+            @brief
+                Returns a valid pointer of any derived type that is
+                registered in the class hierarchy.
+            @return
+                Returns NULL if the no pointer was found.
+            */
+            ORX_FORCEINLINE void* getDerivedPointer(unsigned int classID)
+            {
+                for (int i = this->objectPointers_.size() - 1; i >= 0; --i)
+                {
+                    if (this->objectPointers_[i].first == classID)
+                        return this->objectPointers_[i].second;
+                }
+                return NULL;
+            }
+
+            /// Version of getDerivedPointer with template
+            template <class T> ORX_FORCEINLINE T* getDerivedPointer(unsigned int classID)
+            {   return static_cast<T*>(this->getDerivedPointer(classID));   }
+            /// Const version of getDerivedPointer with template
+            template <class T> ORX_FORCEINLINE const T* getDerivedPointer(unsigned int classID) const
+            {   return const_cast<Identifiable*>(this)->getDerivedPointer<T>(classID);   }
+
+        private:
+            Identifier* identifier_;                                //!< The Identifier of the object
+            std::set<const Identifier*>* parents_;                  //!< List of all parents of the object
+            MetaObjectList* metaList_;                              //!< MetaObjectList, containing all ObjectLists and ObjectListElements the object is registered in
+
+            /// 'Fast map' that holds this-pointers of all derived types
+            std::vector<std::pair<unsigned int, void*> > objectPointers_;
+    };
+}
+
+#endif /* _Identifiable_H__ */

Modified: code/branches/core6/src/libraries/core/class/OrxonoxClass.cc
===================================================================
--- code/branches/core6/src/libraries/core/class/OrxonoxClass.cc	2013-03-24 17:08:42 UTC (rev 9564)
+++ code/branches/core6/src/libraries/core/class/OrxonoxClass.cc	2013-03-24 17:34:23 UTC (rev 9565)
@@ -45,31 +45,17 @@
     */
     OrxonoxClass::OrxonoxClass()
     {
-        this->identifier_ = 0;
-        this->parents_ = 0;
-        this->metaList_ = new MetaObjectList();
         this->referenceCount_ = 0;
         this->requestedDestruction_ = false;
-        // Optimisation
-        this->objectPointers_.reserve(6);
     }
 
     /**
-        @brief Destructor: Removes the object from the object-lists, notifies all DestructionListener (for example @ref WeakPtr "weak pointers") that this object is being deleted.
+        @brief Destructor: Notifies all DestructionListener (for example @ref WeakPtr "weak pointers") that this object is being deleted.
     */
     OrxonoxClass::~OrxonoxClass()
     {
-//        if (!this->requestedDestruction_)
-//            orxout(internal_warning) << "Destroyed object without destroy() (" << this->getIdentifier()->getName() << ')' << endl;
-
         assert(this->referenceCount_ <= 0);
 
-        this->unregisterObject();
-
-        // parents_ exists only if isCreatingHierarchy() of the associated Identifier returned true while creating the class
-        if (this->parents_)
-            delete this->parents_;
-
         // notify all destruction listeners
         for (std::set<DestructionListener*>::iterator it = this->destructionListeners_.begin(); it != this->destructionListeners_.end(); )
             (*(it++))->objectDeleted();
@@ -89,53 +75,4 @@
                 delete this;
         }
     }
-
-    /**
-        @brief Removes this object from the object-lists.
-    */
-    void OrxonoxClass::unregisterObject()
-    {
-        if (this->metaList_)
-            delete this->metaList_;
-        this->metaList_ = 0;
-    }
-
-    /// Returns true if the object's class is of the given type or a derivative.
-    bool OrxonoxClass::isA(const Identifier* identifier)
-        { return this->getIdentifier()->isA(identifier); }
-    /// Returns true if the object's class is exactly of the given type.
-    bool OrxonoxClass::isExactlyA(const Identifier* identifier)
-        { return this->getIdentifier()->isExactlyA(identifier); }
-    /// Returns true if the object's class is a child of the given type.
-    bool OrxonoxClass::isChildOf(const Identifier* identifier)
-        { return this->getIdentifier()->isChildOf(identifier); }
-    /// Returns true if the object's class is a direct child of the given type.
-    bool OrxonoxClass::isDirectChildOf(const Identifier* identifier)
-        { return this->getIdentifier()->isDirectChildOf(identifier); }
-    /// Returns true if the object's class is a parent of the given type.
-    bool OrxonoxClass::isParentOf(const Identifier* identifier)
-        { return this->getIdentifier()->isParentOf(identifier); }
-    /// Returns true if the object's class is a direct parent of the given type.
-    bool OrxonoxClass::isDirectParentOf(const Identifier* identifier)
-        { return this->getIdentifier()->isDirectParentOf(identifier); }
-
-
-    /// Returns true if the object's class is of the given type or a derivative.
-    bool OrxonoxClass::isA(const OrxonoxClass* object)
-        { return this->getIdentifier()->isA(object->getIdentifier()); }
-    /// Returns true if the object's class is exactly of the given type.
-    bool OrxonoxClass::isExactlyA(const OrxonoxClass* object)
-        { return this->getIdentifier()->isExactlyA(object->getIdentifier()); }
-    /// Returns true if the object's class is a child of the given type.
-    bool OrxonoxClass::isChildOf(const OrxonoxClass* object)
-        { return this->getIdentifier()->isChildOf(object->getIdentifier()); }
-    /// Returns true if the object's class is a direct child of the given type.
-    bool OrxonoxClass::isDirectChildOf(const OrxonoxClass* object)
-        { return this->getIdentifier()->isDirectChildOf(object->getIdentifier()); }
-    /// Returns true if the object's class is a parent of the given type.
-    bool OrxonoxClass::isParentOf(const OrxonoxClass* object)
-        { return this->getIdentifier()->isParentOf(object->getIdentifier()); }
-    /// Returns true if the object's class is a direct child of the given type.
-    bool OrxonoxClass::isDirectParentOf(const OrxonoxClass* object)
-        { return this->getIdentifier()->isDirectParentOf(object->getIdentifier()); }
 }

Modified: code/branches/core6/src/libraries/core/class/OrxonoxClass.h
===================================================================
--- code/branches/core6/src/libraries/core/class/OrxonoxClass.h	2013-03-24 17:08:42 UTC (rev 9564)
+++ code/branches/core6/src/libraries/core/class/OrxonoxClass.h	2013-03-24 17:34:23 UTC (rev 9565)
@@ -35,9 +35,6 @@
     @file
     @ingroup Class OrxonoxClass
     @brief Declaration of OrxonoxClass, the base class of all objects and interfaces in Orxonox.
-
-    All objects and interfaces of the game-logic (not the engine) are derived from OrxonoxClass.
-    It stores the Identifier and the MetaObjectList and has all needed functions to create and use the class-hierarchy.
 */
 
 #ifndef _OrxonoxClass_H__
@@ -46,8 +43,8 @@
 #include "core/CorePrereqs.h"
 
 #include <set>
-#include <vector>
-#include "Super.h"
+//#include "Super.h"
+#include "Identifiable.h"
 
 namespace orxonox
 {
@@ -55,15 +52,10 @@
         @brief The class all objects and interfaces of the game-logic (not the engine) are derived from.
 
         The BaseObject and Interfaces are derived with @c virtual @c public @c OrxonoxClass from OrxonoxClass.
-        OrxonoxClass is needed to create the class-hierarchy at startup and to store the Identifier and the
-        MetaObjectList, as well as to provide an interface for SmartPtr and WeakPtr.
     */
-    class _CoreExport OrxonoxClass
+    class _CoreExport OrxonoxClass : public Identifiable
     {
         template <class T>
-        friend class ClassIdentifier;
-
-        template <class T>
         friend class SmartPtr;
 
         friend class DestructionListener;
@@ -73,75 +65,14 @@
             virtual ~OrxonoxClass();
 
             void destroy();
-            void unregisterObject();
 
             /// Function to collect the SetConfigValue-macro calls.
             void setConfigValues() {};
 
-            /// Returns the Identifier of the object.
-            inline Identifier* getIdentifier() const { return this->identifier_; }
-
-            bool isA(const Identifier* identifier);
-            bool isExactlyA(const Identifier* identifier);
-            bool isChildOf(const Identifier* identifier);
-            bool isDirectChildOf(const Identifier* identifier);
-            bool isParentOf(const Identifier* identifier);
-            bool isDirectParentOf(const Identifier* identifier);
-
-            /// Returns true if the object's class is of the given type or a derivative.
-            template <class B> inline bool isA(const SubclassIdentifier<B>* identifier)
-                { return this->isA(*identifier); }
-            /// Returns true if the object's class is exactly of the given type.
-            template <class B> inline bool isExactlyA(const SubclassIdentifier<B>* identifier)
-                { return this->isExactlyA(*identifier); }
-            /// Returns true if the object's class is a child of the given type.
-            template <class B> inline bool isChildOf(const SubclassIdentifier<B>* identifier)
-                { return this->isChildOf(*identifier); }
-            /// Returns true if the object's class is a direct child of the given type.
-            template <class B> inline bool isDirectChildOf(const SubclassIdentifier<B>* identifier)
-                { return this->isDirectChildOf(*identifier); }
-            /// Returns true if the object's class is a parent of the given type.
-            template <class B> inline bool isParentOf(const SubclassIdentifier<B>* identifier)
-                { return this->isParentOf(*identifier); }
-            /// Returns true if the object's class is a direct parent of the given type.
-            template <class B> inline bool isDirectParentOf(const SubclassIdentifier<B>* identifier)
-                { return this->isDirectParentOf(*identifier); }
-
-            bool isA(const OrxonoxClass* object);
-            bool isExactlyA(const OrxonoxClass* object);
-            bool isChildOf(const OrxonoxClass* object);
-            bool isDirectChildOf(const OrxonoxClass* object);
-            bool isParentOf(const OrxonoxClass* object);
-            bool isDirectParentOf(const OrxonoxClass* object);
-
             /// Returns the number of @ref orxonox::SmartPtr "smart pointers" that point to this object.
             inline unsigned int getReferenceCount() const
                 { return this->referenceCount_; }
 
-            /**
-            @brief
-                Returns a valid pointer of any derived type that is
-                registered in the class hierarchy.
-            @return
-                Returns NULL if the no pointer was found.
-            */
-            ORX_FORCEINLINE void* getDerivedPointer(unsigned int classID)
-            {
-                for (int i = this->objectPointers_.size() - 1; i >= 0; --i)
-                {
-                    if (this->objectPointers_[i].first == classID)
-                        return this->objectPointers_[i].second;
-                }
-                return NULL;
-            }
-
-            /// Version of getDerivedPointer with template
-            template <class T> ORX_FORCEINLINE T* getDerivedPointer(unsigned int classID)
-            {   return static_cast<T*>(this->getDerivedPointer(classID));   }
-            /// Const version of getDerivedPointer with template
-            template <class T> ORX_FORCEINLINE const T* getDerivedPointer(unsigned int classID) const
-            {   return const_cast<OrxonoxClass*>(this)->getDerivedPointer<T>(classID);   }
-
         protected:
             /// 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.
             virtual void preDestroy() {}
@@ -165,15 +96,9 @@
             inline void unregisterDestructionListener(DestructionListener* pointer)
                 { this->destructionListeners_.erase(pointer); }
 
-            Identifier* identifier_;                                //!< The Identifier of the object
-            std::set<const Identifier*>* parents_;                  //!< List of all parents of the object
-            MetaObjectList* metaList_;                              //!< MetaObjectList, containing all ObjectLists and ObjectListElements the object is registered in
             int referenceCount_;                                    //!< Counts the references from smart pointers to this object
             bool requestedDestruction_;                             //!< Becomes true after someone called delete on this object
             std::set<DestructionListener*> destructionListeners_;   //!< All destruction listeners (for example weak pointers which point to this object and like to get notified if it dies)
-
-            /// 'Fast map' that holds this-pointers of all derived types
-            std::vector<std::pair<unsigned int, void*> > objectPointers_;
     };
 
     /**




More information about the Orxonox-commit mailing list