Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/trunk/src/libraries/core/OrxonoxClass.h @ 8859

Last change on this file since 8859 was 8858, checked in by landauf, 14 years ago

merged output branch back to trunk.

Changes:

  • you have to include util/Output.h instead of util/Debug.h
  • COUT(x) is now called orxout(level)
  • output levels are now defined by an enum instead of numbers. see util/Output.h for the definition
  • it's possible to use output contexts with orxout(level, context). see util/Output.h for some common contexts. you can define more contexts
  • you must use 'endl' at the end of an output message, '\n' does not flush the message

Output levels:

  • instead of COUT(0) use orxout()
  • instead of COUT(1) use orxout(user_error) or orxout(internal_error)
  • instead of COUT(2) use orxout(user_warning) or orxout(internal_warning)
  • instead of COUT(3) use orxout(user_status/user_info) or orxout(internal_status/internal_info)
  • instead of COUT(4) use orxout(verbose)
  • instead of COUT(5) use orxout(verbose_more)
  • instead of COUT(6) use orxout(verbose_ultra)

Guidelines:

  • user_* levels are for the user, visible in the console and the log-file
  • internal_* levels are for developers, visible in the log-file
  • verbose_* levels are for debugging, only visible if the context of the output is activated

Usage in C++:

  • orxout() << "message" << endl;
  • orxout(level) << "message" << endl;
  • orxout(level, context) << "message" << endl;

Usage in Lua:

  • orxout("message")
  • orxout(orxonox.level.levelname, "message")
  • orxout(orxonox.level.levelname, "context", "message")

Usage in Tcl (and in the in-game-console):

  • orxout levelname message
  • orxout_context levelname context message
  • shortcuts: log message, error message, warning message, status message, info message, debug message
  • Property svn:eol-style set to native
File size: 8.8 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    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.
41*/
42
43#ifndef _OrxonoxClass_H__
44#define _OrxonoxClass_H__
45
46#include "CorePrereqs.h"
[3327]47
[1505]48#include <set>
[3327]49#include <vector>
[8729]50#include "Super.h"
[1505]51
52namespace orxonox
53{
54    /**
[7401]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.
[1505]60    */
61    class _CoreExport OrxonoxClass
62    {
[3325]63        template <class T>
64        friend class ClassIdentifier;
65
[5929]66        template <class T>
67        friend class SmartPtr;
68
[7849]69        friend class DestructionListener;
[5929]70
[1505]71        public:
72            OrxonoxClass();
73            virtual ~OrxonoxClass();
74
[5929]75            void destroy();
[6417]76            void unregisterObject();
[5929]77
[7401]78            /// Function to collect the SetConfigValue-macro calls.
[1505]79            void setConfigValues() {};
80
[7401]81            /// Returns the Identifier of the object.
[1505]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
[7401]91            /// Returns true if the object's class is of the given type or a derivative.
[5929]92            template <class B> inline bool isA(const SubclassIdentifier<B>* identifier)
93                { return this->isA(*identifier); }
[7401]94            /// Returns true if the object's class is exactly of the given type.
[5929]95            template <class B> inline bool isExactlyA(const SubclassIdentifier<B>* identifier)
96                { return this->isExactlyA(*identifier); }
[7401]97            /// Returns true if the object's class is a child of the given type.
[5929]98            template <class B> inline bool isChildOf(const SubclassIdentifier<B>* identifier)
99                { return this->isChildOf(*identifier); }
[7401]100            /// Returns true if the object's class is a direct child of the given type.
[5929]101            template <class B> inline bool isDirectChildOf(const SubclassIdentifier<B>* identifier)
102                { return this->isDirectChildOf(*identifier); }
[7401]103            /// Returns true if the object's class is a parent of the given type.
[5929]104            template <class B> inline bool isParentOf(const SubclassIdentifier<B>* identifier)
105                { return this->isParentOf(*identifier); }
[7401]106            /// Returns true if the object's class is a direct parent of the given type.
[5929]107            template <class B> inline bool isDirectParentOf(const SubclassIdentifier<B>* identifier)
108                { return this->isDirectParentOf(*identifier); }
[1505]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);
[7163]116
[6524]117            virtual void clone(OrxonoxClass*& item) {}
[1505]118
[7401]119            /// Returns the number of @ref orxonox::SmartPtr "smart pointers" that point to this object.
[5929]120            inline unsigned int getReferenceCount() const
121                { return this->referenceCount_; }
122
[3325]123            /**
124            @brief
125                Returns a valid pointer of any derived type that is
126                registered in the class hierarchy.
127            @return
128                Returns NULL if the no pointer was found.
129            */
[8351]130            ORX_FORCEINLINE void* getDerivedPointer(unsigned int classID)
[3325]131            {
132                for (int i = this->objectPointers_.size() - 1; i >= 0; --i)
133                {
134                    if (this->objectPointers_[i].first == classID)
[5929]135                        return this->objectPointers_[i].second;
[3325]136                }
137                return NULL;
138            }
[5929]139
[7401]140            /// Version of getDerivedPointer with template
[8351]141            template <class T> ORX_FORCEINLINE T* getDerivedPointer(unsigned int classID)
[5929]142            {   return static_cast<T*>(this->getDerivedPointer(classID));   }
[7401]143            /// Const version of getDerivedPointer with template
[8351]144            template <class T> ORX_FORCEINLINE const T* getDerivedPointer(unsigned int classID) const
[5929]145            {   return const_cast<OrxonoxClass*>(this)->getDerivedPointer<T>(classID);   }
146
[6417]147        protected:
[7401]148            /// 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]149            virtual void preDestroy() {}
150
[5929]151        private:
[7401]152            /// Increments the reference counter (for smart pointers).
[5929]153            inline void incrementReferenceCount()
154                { ++this->referenceCount_; }
[7401]155            /// Decrements the reference counter (for smart pointers).
[5929]156            inline void decrementReferenceCount()
[6417]157            {
158                --this->referenceCount_;
159                if (this->referenceCount_ == 0 && this->requestedDestruction_)
160                    this->destroy();
161            }
162
[7849]163            /// Register a destruction listener (for example a weak pointer which points to this object).
164            inline void registerDestructionListener(DestructionListener* pointer)
165                { this->destructionListeners_.insert(pointer); }
166            /// Unegister a destruction listener (for example a weak pointer which pointed to this object before).
167            inline void unregisterDestructionListener(DestructionListener* pointer)
168                { this->destructionListeners_.erase(pointer); }
[3325]169
[7849]170            Identifier* identifier_;                                //!< The Identifier of the object
171            std::set<const Identifier*>* parents_;                  //!< List of all parents of the object
172            MetaObjectList* metaList_;                              //!< MetaObjectList, containing all ObjectLists and ObjectListElements the object is registered in
173            int referenceCount_;                                    //!< Counts the references from smart pointers to this object
174            bool requestedDestruction_;                             //!< Becomes true after someone called delete on this object
175            std::set<DestructionListener*> destructionListeners_;   //!< All destruction listeners (for example weak pointers which point to this object and like to get notified if it dies)
[5929]176
[7401]177            /// 'Fast map' that holds this-pointers of all derived types
[3325]178            std::vector<std::pair<unsigned int, void*> > objectPointers_;
[1505]179    };
[7163]180
[7849]181    /**
182        @brief This listener is used to inform weak pointers if an object of type OrxonoxClass gets destroyed.
183    */
184    class _CoreExport DestructionListener
185    {
186        friend class OrxonoxClass;
187
188        protected:
[8079]189            virtual ~DestructionListener() {}
190
[7849]191            inline void registerAsDestructionListener(OrxonoxClass* object)
[7850]192                { if (object) { object->registerDestructionListener(this); } }
[7849]193            inline void unregisterAsDestructionListener(OrxonoxClass* object)
[7850]194                { if (object) { object->unregisterDestructionListener(this); } }
[7849]195
196            virtual void objectDeleted() = 0;
197    };
198
[7163]199    SUPER_FUNCTION(11, OrxonoxClass, clone, false);
[1505]200}
201
202#endif /* _OrxonoxClass_H__ */
Note: See TracBrowser for help on using the repository browser.