Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/core6/src/libraries/core/OrxonoxClass.cc @ 9561

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

OrxonoxClass now takes a 'Context' object as constructor argument. Not yet enforced nor used

  • Property svn:eol-style set to native
File size: 5.8 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 Implementation of OrxonoxClass.
32*/
33
34#include "OrxonoxClass.h"
35
36#include <cassert>
37#include "object/MetaObjectList.h"
38#include "object/Context.h"
39#include "Identifier.h"
40
41namespace orxonox
42{
43    /**
44        @brief Constructor: Sets the default values.
45    */
46    OrxonoxClass::OrxonoxClass(Context* context) : context_(context)
47    {
48        //assert(context);
49        if (!this->context_)
50            this->context_ = Context::getRootContext();
51
52        this->identifier_ = 0;
53        this->parents_ = 0;
54        this->metaList_ = new MetaObjectList();
55        this->referenceCount_ = 0;
56        this->requestedDestruction_ = false;
57        // Optimisation
58        this->objectPointers_.reserve(6);
59    }
60
61    /**
62        @brief Destructor: Removes the object from the object-lists, notifies all DestructionListener (for example @ref WeakPtr "weak pointers") that this object is being deleted.
63    */
64    OrxonoxClass::~OrxonoxClass()
65    {
66//        if (!this->requestedDestruction_)
67//            orxout(internal_warning) << "Destroyed object without destroy() (" << this->getIdentifier()->getName() << ')' << endl;
68
69        assert(this->referenceCount_ <= 0);
70
71        this->unregisterObject();
72
73        // parents_ exists only if isCreatingHierarchy() of the associated Identifier returned true while creating the class
74        if (this->parents_)
75            delete this->parents_;
76
77        // notify all destruction listeners
78        for (std::set<DestructionListener*>::iterator it = this->destructionListeners_.begin(); it != this->destructionListeners_.end(); )
79            (*(it++))->objectDeleted();
80    }
81
82    /**
83        @brief Deletes the object if no @ref orxonox::SmartPtr "smart pointers" point to this object. Otherwise schedules the object to be deleted as soon as possible.
84    */
85    void OrxonoxClass::destroy()
86    {
87        assert(this); // Just in case someone tries to delete a NULL pointer
88        this->requestedDestruction_ = true;
89        if (this->referenceCount_ == 0)
90        {
91            this->preDestroy();
92            if (this->referenceCount_ == 0)
93                delete this;
94        }
95    }
96
97    /**
98        @brief Removes this object from the object-lists.
99    */
100    void OrxonoxClass::unregisterObject()
101    {
102        if (this->metaList_)
103            delete this->metaList_;
104        this->metaList_ = 0;
105    }
106
107    /// Returns true if the object's class is of the given type or a derivative.
108    bool OrxonoxClass::isA(const Identifier* identifier)
109        { return this->getIdentifier()->isA(identifier); }
110    /// Returns true if the object's class is exactly of the given type.
111    bool OrxonoxClass::isExactlyA(const Identifier* identifier)
112        { return this->getIdentifier()->isExactlyA(identifier); }
113    /// Returns true if the object's class is a child of the given type.
114    bool OrxonoxClass::isChildOf(const Identifier* identifier)
115        { return this->getIdentifier()->isChildOf(identifier); }
116    /// Returns true if the object's class is a direct child of the given type.
117    bool OrxonoxClass::isDirectChildOf(const Identifier* identifier)
118        { return this->getIdentifier()->isDirectChildOf(identifier); }
119    /// Returns true if the object's class is a parent of the given type.
120    bool OrxonoxClass::isParentOf(const Identifier* identifier)
121        { return this->getIdentifier()->isParentOf(identifier); }
122    /// Returns true if the object's class is a direct parent of the given type.
123    bool OrxonoxClass::isDirectParentOf(const Identifier* identifier)
124        { return this->getIdentifier()->isDirectParentOf(identifier); }
125
126
127    /// Returns true if the object's class is of the given type or a derivative.
128    bool OrxonoxClass::isA(const OrxonoxClass* object)
129        { return this->getIdentifier()->isA(object->getIdentifier()); }
130    /// Returns true if the object's class is exactly of the given type.
131    bool OrxonoxClass::isExactlyA(const OrxonoxClass* object)
132        { return this->getIdentifier()->isExactlyA(object->getIdentifier()); }
133    /// Returns true if the object's class is a child of the given type.
134    bool OrxonoxClass::isChildOf(const OrxonoxClass* object)
135        { return this->getIdentifier()->isChildOf(object->getIdentifier()); }
136    /// Returns true if the object's class is a direct child of the given type.
137    bool OrxonoxClass::isDirectChildOf(const OrxonoxClass* object)
138        { return this->getIdentifier()->isDirectChildOf(object->getIdentifier()); }
139    /// Returns true if the object's class is a parent of the given type.
140    bool OrxonoxClass::isParentOf(const OrxonoxClass* object)
141        { return this->getIdentifier()->isParentOf(object->getIdentifier()); }
142    /// Returns true if the object's class is a direct child of the given type.
143    bool OrxonoxClass::isDirectParentOf(const OrxonoxClass* object)
144        { return this->getIdentifier()->isDirectParentOf(object->getIdentifier()); }
145}
Note: See TracBrowser for help on using the repository browser.