Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/core4/src/core/OrxonoxClass.h @ 3238

Last change on this file since 3238 was 3224, checked in by rgrieder, 15 years ago

Removed three macros: Two (ClassByString and ClassByID) by replacing them with an equivalent inline function and the other one by moving some macro-code to an actual function. Most of what RegisterObject() does can simply be done within a template function in the ClassIdentifier.
Also removed some mysterious public functions of OrxonoxClass (WorldEntity::getParents() doesn't exactly do what you would expect) that only served internal purposes. Instead the ClassIdentifier became a friend of OrxonoxClass and now does the necessary work.

  • Property svn:eol-style set to native
File size: 4.9 KB
Line 
1/*
2 *   ORXONOX - the hottest 3D action shooter ever to exist
3 *                    > www.orxonox.net <
4 *
5 *
6 *   License notice:
7 *
8 *   This program is free software; you can redistribute it and/or
9 *   modify it under the terms of the GNU General Public License
10 *   as published by the Free Software Foundation; either version 2
11 *   of the License, or (at your option) any later version.
12 *
13 *   This program is distributed in the hope that it will be useful,
14 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
15 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 *   GNU General Public License for more details.
17 *
18 *   You should have received a copy of the GNU General Public License
19 *   along with this program; if not, write to the Free Software
20 *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
21 *
22 *   Author:
23 *      Fabian 'x3n' Landau
24 *   Co-authors:
25 *      ...
26 *
27 */
28
29/**
30    @file
31    @brief Declaration of the OrxonoxClass Class.
32
33    All objects and interfaces of the game-logic (not the engine) are derived from OrxonoxClass.
34    It stores the Identifier and the MetaObjectList and has all needed functions to create and use the class-hierarchy.
35*/
36
37#ifndef _OrxonoxClass_H__
38#define _OrxonoxClass_H__
39
40#include "CorePrereqs.h"
41#include <set>
42
43namespace orxonox
44{
45    //! The class all objects and interfaces of the game-logic (not the engine) are derived from.
46    /**
47        The BaseObject and Interfaces are derived with 'virtual public OrxonoxClass' from OrxonoxClass.
48        OrxonoxClass is needed to create the class-hierarchy at startup and to store the Identifier and the MetaObjectList.
49    */
50    class _CoreExport OrxonoxClass
51    {
52        template <class T>
53        friend class ClassIdentifier;
54
55        public:
56            OrxonoxClass();
57            virtual ~OrxonoxClass();
58
59            /** @brief Function to collect the SetConfigValue-macro calls. */
60            void setConfigValues() {};
61
62            /** @brief Returns the Identifier of the object. @return The Identifier */
63            inline Identifier* getIdentifier() const { return this->identifier_; }
64
65            bool isA(const Identifier* identifier);
66            bool isExactlyA(const Identifier* identifier);
67            bool isChildOf(const Identifier* identifier);
68            bool isDirectChildOf(const Identifier* identifier);
69            bool isParentOf(const Identifier* identifier);
70            bool isDirectParentOf(const Identifier* identifier);
71
72            bool isA(const SubclassIdentifier<class B>* identifier);
73            bool isExactlyA(const SubclassIdentifier<class B>* identifier);
74            bool isChildOf(const SubclassIdentifier<class B>* identifier);
75            bool isDirectChildOf(const SubclassIdentifier<class B>* identifier);
76            bool isParentOf(const SubclassIdentifier<class B>* identifier);
77            bool isDirectParentOf(const SubclassIdentifier<class B>* identifier);
78
79            bool isA(const SubclassIdentifier<class B> identifier);
80            bool isExactlyA(const SubclassIdentifier<class B> identifier);
81            bool isChildOf(const SubclassIdentifier<class B> identifier);
82            bool isDirectChildOf(const SubclassIdentifier<class B> identifier);
83            bool isParentOf(const SubclassIdentifier<class B> identifier);
84            bool isDirectParentOf(const SubclassIdentifier<class B> identifier);
85
86            bool isA(const OrxonoxClass* object);
87            bool isExactlyA(const OrxonoxClass* object);
88            bool isChildOf(const OrxonoxClass* object);
89            bool isDirectChildOf(const OrxonoxClass* object);
90            bool isParentOf(const OrxonoxClass* object);
91            bool isDirectParentOf(const OrxonoxClass* object);
92
93            /**
94            @brief
95                Returns a valid pointer of any derived type that is
96                registered in the class hierarchy.
97            @return
98                Returns NULL if the no pointer was found.
99            */
100            template <class T>
101            FORCEINLINE T* getDerivedPointer(unsigned int classID) const
102            {
103                for (int i = this->objectPointers_.size() - 1; i >= 0; --i)
104                {
105                    if (this->objectPointers_[i].first == classID)
106                        return reinterpret_cast<T*>(this->objectPointers_[i].second);
107                }
108                return NULL;
109            }
110
111        private:
112            Identifier* identifier_;                   //!< The Identifier of the object
113            std::set<const Identifier*>* parents_;     //!< List of all parents of the object
114            MetaObjectList* metaList_;                 //!< MetaObjectList, containing all ObjectLists and ObjectListElements the object is registered in
115            //! 'Fast map' that holds this-pointers of all derived types
116            std::vector<std::pair<unsigned int, void*> > objectPointers_;
117    };
118}
119
120#endif /* _OrxonoxClass_H__ */
Note: See TracBrowser for help on using the repository browser.