Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/trunk/src/core/Namespace.cc @ 1062

Last change on this file since 1062 was 1062, checked in by rgrieder, 16 years ago
  • changed header file inclusion order
File size: 5.8 KB
RevLine 
[877]1/*
2 *   ORXONOX - the hottest 3D action shooter ever to exist
[1056]3 *                    > www.orxonox.net <
[877]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#include "Namespace.h"
[1062]30#include "NamespaceNode.h"
[877]31#include "CoreIncludes.h"
32#include "XMLPort.h"
[895]33#include "util/SubString.h"
[877]34
35namespace orxonox
36{
37    CreateFactory(Namespace);
38
39    Namespace::Namespace()
40    {
41        RegisterObject(Namespace);
[878]42
[895]43        this->bAutogeneratedFileRootNamespace_ = false;
[901]44        this->bRoot_ = false;
[895]45        this->operator_ = "or";
[877]46    }
47
48    Namespace::~Namespace()
49    {
[901]50        if (this->bRoot_)
[896]51            for (std::set<NamespaceNode*>::iterator it = this->representingNamespaces_.begin(); it != this->representingNamespaces_.end(); ++it)
52                delete (*it);
[877]53    }
54
55    /**
56        @brief XML loading and saving.
57        @param xmlelement The XML-element
58        @param loading Loading (true) or saving (false)
59        @return The XML-element
60    */
[902]61    void Namespace::XMLPort(Element& xmlelement, XMLPort::Mode mode)
[877]62    {
[902]63        BaseObject::XMLPort(xmlelement, mode);
[877]64
[895]65        std::string name = this->getName();
66        unsigned int pos = 0;
67        while ((pos = name.find(',')) != std::string::npos)
68            name.replace(pos, 1, " ");
69        while ((pos = name.find(';')) != std::string::npos)
70            name.replace(pos, 1, " ");
71        while ((pos = name.find('\n')) != std::string::npos)
72            name.replace(pos, 1, " ");
73        while ((pos = name.find('\t')) != std::string::npos)
74            name.replace(pos, 1, " ");
[994]75        SubString tokens(name, " ", "", false, '\\', true, '"', true, '\0', '\0', true, '\0');
[901]76        if (this->bRoot_)
[895]77        {
[901]78            this->representingNamespaces_.insert(new NamespaceNode(this->getName()));
79        }
80        else
81        {
82            for (unsigned int i = 0; i < tokens.size(); i++)
[895]83            {
[901]84                for (std::set<NamespaceNode*>::iterator it = this->getNamespace()->representingNamespaces_.begin(); it != this->getNamespace()->representingNamespaces_.end(); ++it)
85                {
86                    std::set<NamespaceNode*> temp = (*it)->getNodeRelative(tokens[i]);
87                    this->representingNamespaces_.insert(temp.begin(), temp.end());
88                }
[895]89            }
90        }
91
[902]92        XMLPortParam(Namespace, "operator", setOperator, getOperator, xmlelement, mode);
93        XMLPortParam(Namespace, "bAutogenerated", setAutogenerated, isAutogenerated, xmlelement, mode);
[895]94
95        if (this->bAutogeneratedFileRootNamespace_)
96        {
97            for (std::set<NamespaceNode*>::iterator it = this->representingNamespaces_.begin(); it != this->representingNamespaces_.end(); ++it)
98            {
99                (*it)->setRoot(true);
100                (*it)->setHidden(true);
101            }
102        }
103
[902]104        XMLPortObject(Namespace, BaseObject, "", loadObjects, saveObjects, xmlelement, mode, true, false);
[877]105    }
106
107    void Namespace::loadObjects(BaseObject* object)
108    {
[895]109        object->setNamespace(this);
[877]110    }
111
[895]112    const BaseObject* Namespace::saveObjects(unsigned int index) const
[879]113    {
[895]114        return 0; // todo
[879]115    }
116
[895]117    bool Namespace::includes(const Namespace* ns) const
[879]118    {
[895]119        for (std::set<NamespaceNode*>::const_iterator it1 = this->representingNamespaces_.begin(); it1 != this->representingNamespaces_.end(); ++it1)
120        {
121            for (std::set<NamespaceNode*>::const_iterator it2 = ns->representingNamespaces_.begin(); it2 != ns->representingNamespaces_.end(); ++it2)
122            {
123                if ((*it1)->includes(*it2))
124                {
125                    if (this->operator_ == "or")
126                        return true;
[879]127
[895]128                    if (this->operator_ == "not")
129                        return false;
130                }
131                else
132                {
133                    if (this->operator_ == "and")
134                        return false;
135                }
136            }
137        }
138
139        if (this->operator_ == "or")
140            return false;
141        else if (this->operator_ == "and")
142            return true;
143        else if (this->operator_ == "not")
144            return true;
145
146        return false;
[877]147    }
[901]148
149    std::string Namespace::toString() const
150    {
151        std::string output;
152
153        int i = 0;
154        for (std::set<NamespaceNode*>::const_iterator it = this->representingNamespaces_.begin(); it != this->representingNamespaces_.end(); i++, ++it)
155        {
156            if (i > 0)
157                output += " / ";
158
159            output += (*it)->toString();
160        }
161
162        return output;
163    }
164
165    std::string Namespace::toString(const std::string& indentation) const
166    {
167        std::string output;
168
169        int i = 0;
170        for (std::set<NamespaceNode*>::const_iterator it = this->representingNamespaces_.begin(); it != this->representingNamespaces_.end(); i++, ++it)
171        {
172            if (i > 0)
173                output += "\n";
174
175            output += (*it)->toString(indentation);
176        }
177
178        return output;
179    }
[877]180}
Note: See TracBrowser for help on using the repository browser.