Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/trunk/src/libraries/core/OrxonoxClass.cc @ 7704

Last change on this file since 7704 was 7401, checked in by landauf, 14 years ago

merged doc branch back to trunk

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