Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/core6/src/libraries/core/class/OrxonoxClass.h @ 9565

Last change on this file since 9565 was 9565, checked in by landauf, 11 years ago

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

  • Property svn:eol-style set to native
File size: 4.4 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    @defgroup OrxonoxClass OrxonoxClass
31    @ingroup Class
32*/
33
34/**
35    @file
36    @ingroup Class OrxonoxClass
37    @brief Declaration of OrxonoxClass, the base class of all objects and interfaces in Orxonox.
38*/
39
40#ifndef _OrxonoxClass_H__
41#define _OrxonoxClass_H__
42
43#include "core/CorePrereqs.h"
44
45#include <set>
46//#include "Super.h"
47#include "Identifiable.h"
48
49namespace orxonox
50{
51    /**
52        @brief The class all objects and interfaces of the game-logic (not the engine) are derived from.
53
54        The BaseObject and Interfaces are derived with @c virtual @c public @c OrxonoxClass from OrxonoxClass.
55    */
56    class _CoreExport OrxonoxClass : public Identifiable
57    {
58        template <class T>
59        friend class SmartPtr;
60
61        friend class DestructionListener;
62
63        public:
64            OrxonoxClass();
65            virtual ~OrxonoxClass();
66
67            void destroy();
68
69            /// Function to collect the SetConfigValue-macro calls.
70            void setConfigValues() {};
71
72            /// Returns the number of @ref orxonox::SmartPtr "smart pointers" that point to this object.
73            inline unsigned int getReferenceCount() const
74                { return this->referenceCount_; }
75
76        protected:
77            /// 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.
78            virtual void preDestroy() {}
79
80        private:
81            /// Increments the reference counter (for smart pointers).
82            inline void incrementReferenceCount()
83                { ++this->referenceCount_; }
84            /// Decrements the reference counter (for smart pointers).
85            inline void decrementReferenceCount()
86            {
87                --this->referenceCount_;
88                if (this->referenceCount_ == 0 && this->requestedDestruction_)
89                    this->destroy();
90            }
91
92            /// Register a destruction listener (for example a weak pointer which points to this object).
93            inline void registerDestructionListener(DestructionListener* pointer)
94                { this->destructionListeners_.insert(pointer); }
95            /// Unegister a destruction listener (for example a weak pointer which pointed to this object before).
96            inline void unregisterDestructionListener(DestructionListener* pointer)
97                { this->destructionListeners_.erase(pointer); }
98
99            int referenceCount_;                                    //!< Counts the references from smart pointers to this object
100            bool requestedDestruction_;                             //!< Becomes true after someone called delete on this object
101            std::set<DestructionListener*> destructionListeners_;   //!< All destruction listeners (for example weak pointers which point to this object and like to get notified if it dies)
102    };
103
104    /**
105        @brief This listener is used to inform weak pointers if an object of type OrxonoxClass gets destroyed.
106    */
107    class _CoreExport DestructionListener
108    {
109        friend class OrxonoxClass;
110
111        protected:
112            virtual ~DestructionListener() {}
113
114            inline void registerAsDestructionListener(OrxonoxClass* object)
115                { if (object) { object->registerDestructionListener(this); } }
116            inline void unregisterAsDestructionListener(OrxonoxClass* object)
117                { if (object) { object->unregisterDestructionListener(this); } }
118
119            virtual void objectDeleted() = 0;
120    };
121
122}
123
124#endif /* _OrxonoxClass_H__ */
Note: See TracBrowser for help on using the repository browser.