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
RevLine 
[1505]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/**
[7401]30    @defgroup OrxonoxClass OrxonoxClass
31    @ingroup Class
32*/
33
34/**
[2171]35    @file
[7401]36    @ingroup Class OrxonoxClass
37    @brief Declaration of OrxonoxClass, the base class of all objects and interfaces in Orxonox.
[1505]38*/
39
40#ifndef _OrxonoxClass_H__
41#define _OrxonoxClass_H__
42
[9563]43#include "core/CorePrereqs.h"
[3327]44
[1505]45#include <set>
[9565]46//#include "Super.h"
47#include "Identifiable.h"
[1505]48
49namespace orxonox
50{
51    /**
[7401]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.
[1505]55    */
[9565]56    class _CoreExport OrxonoxClass : public Identifiable
[1505]57    {
[3325]58        template <class T>
[5929]59        friend class SmartPtr;
60
[7849]61        friend class DestructionListener;
[5929]62
[1505]63        public:
[9562]64            OrxonoxClass();
[1505]65            virtual ~OrxonoxClass();
66
[5929]67            void destroy();
68
[7401]69            /// Function to collect the SetConfigValue-macro calls.
[1505]70            void setConfigValues() {};
71
[7401]72            /// Returns the number of @ref orxonox::SmartPtr "smart pointers" that point to this object.
[5929]73            inline unsigned int getReferenceCount() const
74                { return this->referenceCount_; }
75
[6417]76        protected:
[7401]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.
[6417]78            virtual void preDestroy() {}
79
[5929]80        private:
[7401]81            /// Increments the reference counter (for smart pointers).
[5929]82            inline void incrementReferenceCount()
83                { ++this->referenceCount_; }
[7401]84            /// Decrements the reference counter (for smart pointers).
[5929]85            inline void decrementReferenceCount()
[6417]86            {
87                --this->referenceCount_;
88                if (this->referenceCount_ == 0 && this->requestedDestruction_)
89                    this->destroy();
90            }
91
[7849]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); }
[3325]98
[7849]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)
[1505]102    };
[7163]103
[7849]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:
[8079]112            virtual ~DestructionListener() {}
113
[7849]114            inline void registerAsDestructionListener(OrxonoxClass* object)
[7850]115                { if (object) { object->registerDestructionListener(this); } }
[7849]116            inline void unregisterAsDestructionListener(OrxonoxClass* object)
[7850]117                { if (object) { object->unregisterDestructionListener(this); } }
[7849]118
119            virtual void objectDeleted() = 0;
120    };
121
[1505]122}
123
124#endif /* _OrxonoxClass_H__ */
Note: See TracBrowser for help on using the repository browser.