Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/objecthierarchy/src/core/BaseObject.cc @ 2002

Last change on this file since 2002 was 1993, checked in by landauf, 16 years ago

added several new classes

  • Property svn:eol-style set to native
File size: 3.7 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 the BaseObject class.
32*/
33
34#include "BaseObject.h"
35#include "tinyxml/tinyxml.h"
36#include "CoreIncludes.h"
37#include "XMLPort.h"
38#include "Level.h"
39#include "Template.h"
40#include "util/String.h"
41
42namespace orxonox
43{
44    CreateFactory(BaseObject);
45
46    /**
47        @brief Constructor: Registers the object in the BaseObject-list.
48    */
49    BaseObject::BaseObject() : bInitialized_(false)
50    {
51        RegisterRootObject(BaseObject);
52
53        this->bInitialized_ = true;
54
55        this->bActive_ = true;
56        this->bVisible_ = true;
57
58        this->level_ = 0;
59        this->namespace_ = 0;
60    }
61
62    /**
63        @brief Destructor
64    */
65    BaseObject::~BaseObject()
66    {
67    }
68
69    /**
70        @brief XML loading and saving.
71        @param xmlelement The XML-element
72        @param loading Loading (true) or saving (false)
73        @return The XML-element
74    */
75    void BaseObject::XMLPort(Element& xmlelement, XMLPort::Mode mode)
76    {
77        XMLPortParam(BaseObject, "name", setName, getName, xmlelement, mode);
78        XMLPortParam(BaseObject, "visible", setVisible, isVisible, xmlelement, mode);
79        XMLPortParam(BaseObject, "active", setActive, isActive, xmlelement, mode);
80
81        XMLPortObjectTemplate(BaseObject, Template, "templates", addTemplate, getTemplate, xmlelement, mode, const std::string&);
82    }
83
84    /**
85        @brief Returns the levelfile that loaded this object.
86        @return The levelfile
87    */
88    const std::string& BaseObject::getLevelfile() const
89    {
90        if (this->level_)
91            return this->level_->getFile();
92        else
93            return blankString;
94    }
95
96    /**
97        @brief Adds a Template to the object.
98        @param name The name of the Template
99    */
100    void BaseObject::addTemplate(const std::string& name)
101    {
102        Template* temp = Template::getTemplate(name);
103        if (temp)
104            this->addTemplate(temp);
105        else
106            COUT(1) << "Error: \"" << name << "\" is not a valid Template name (in class: " << this->getIdentifier()->getName() << ", name: " << this->getName() << ")." << std::endl;
107    }
108
109    /**
110        @brief Adds a Template to the object.
111        @param temp The Template
112    */
113    void BaseObject::addTemplate(Template* temp)
114    {
115        this->templates_.insert(temp);
116        temp->applyOn(this);
117    }
118
119    /**
120        @brief Returns the Template with the given index.
121        @param index The index
122    */
123    Template* BaseObject::getTemplate(unsigned int index) const
124    {
125        unsigned int i = 0;
126        for (std::set<Template*>::const_iterator it = this->templates_.begin(); it != this->templates_.end(); ++it)
127        {
128            if (i == index)
129                return (*it);
130            i++;
131        }
132        return 0;
133    }
134}
Note: See TracBrowser for help on using the repository browser.