Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/core2/src/orxonox/core/Namespace.cc @ 897

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

bugfix

File size: 5.0 KB
Line 
1/*
2 *   ORXONOX - the hottest 3D action shooter ever to exist
3 *
4 *
5 *   License notice:
6 *
7 *   This program is free software; you can redistribute it and/or
8 *   modify it under the terms of the GNU General Public License
9 *   as published by the Free Software Foundation; either version 2
10 *   of the License, or (at your option) any later version.
11 *
12 *   This program is distributed in the hope that it will be useful,
13 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
14 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 *   GNU General Public License for more details.
16 *
17 *   You should have received a copy of the GNU General Public License
18 *   along with this program; if not, write to the Free Software
19 *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
20 *
21 *   Author:
22 *      Fabian 'x3n' Landau
23 *   Co-authors:
24 *      ...
25 *
26 */
27
28#include "Namespace.h"
29#include "CoreIncludes.h"
30#include "XMLPort.h"
31#include "util/SubString.h"
32#include "NamespaceNode.h"
33
34namespace orxonox
35{
36    CreateFactory(Namespace);
37
38    Namespace::Namespace()
39    {
40        RegisterObject(Namespace);
41
42        this->bAutogeneratedFileRootNamespace_ = false;
43        this->bDeleteNamespaceNodesAfterDestruction_ = false;
44        this->operator_ = "or";
45    }
46
47    Namespace::~Namespace()
48    {
49        if (this->bDeleteNamespaceNodesAfterDestruction_)
50            for (std::set<NamespaceNode*>::iterator it = this->representingNamespaces_.begin(); it != this->representingNamespaces_.end(); ++it)
51                delete (*it);
52    }
53
54    /**
55        @brief XML loading and saving.
56        @param xmlelement The XML-element
57        @param loading Loading (true) or saving (false)
58        @return The XML-element
59    */
60    void Namespace::XMLPort(Element& xmlelement, bool loading)
61    {
62std::cout << "1_1\n";
63        BaseObject::XMLPort(xmlelement, loading);
64std::cout << "1_2\n";
65
66        std::string name = this->getName();
67std::cout << "1_3\n";
68        unsigned int pos = 0;
69        while ((pos = name.find(',')) != std::string::npos)
70            name.replace(pos, 1, " ");
71        while ((pos = name.find(';')) != std::string::npos)
72            name.replace(pos, 1, " ");
73        while ((pos = name.find('\n')) != std::string::npos)
74            name.replace(pos, 1, " ");
75        while ((pos = name.find('\t')) != std::string::npos)
76            name.replace(pos, 1, " ");
77std::cout << "1_4\n";
78        SubString tokens(name, " ", "", false, '\\', '"', '\0', '\0', '\0');
79std::cout << "1_5\n";
80        for (unsigned int i = 0; i < tokens.size(); i++)
81        {
82std::cout << "1_6\n";
83            for (std::set<NamespaceNode*>::iterator it = this->getNamespace()->representingNamespaces_.begin(); it != this->getNamespace()->representingNamespaces_.end(); ++it)
84            {
85std::cout << "1_7\n";
86                std::set<NamespaceNode*> temp = (*it)->getNodeRelative(tokens[i]);
87std::cout << "1_8\n";
88                this->representingNamespaces_.insert(temp.begin(), temp.end());
89std::cout << "1_9\n";
90            }
91        }
92std::cout << "1_10\n";
93
94        XMLPortParam(Namespace, "operator", setOperator, getOperator, xmlelement, loading);
95        XMLPortParam(Namespace, "bAutogenerated", setAutogenerated, isAutogenerated, xmlelement, loading);
96
97        if (this->bAutogeneratedFileRootNamespace_)
98        {
99            for (std::set<NamespaceNode*>::iterator it = this->representingNamespaces_.begin(); it != this->representingNamespaces_.end(); ++it)
100            {
101                (*it)->setRoot(true);
102                (*it)->setHidden(true);
103            }
104        }
105
106        XMLPortObject(Namespace, BaseObject, "", loadObjects, saveObjects, xmlelement, loading, true, false);
107    }
108
109    void Namespace::loadObjects(BaseObject* object)
110    {
111        object->setNamespace(this);
112    }
113
114    const BaseObject* Namespace::saveObjects(unsigned int index) const
115    {
116        return 0; // todo
117    }
118
119    bool Namespace::includes(const Namespace* ns) const
120    {
121        for (std::set<NamespaceNode*>::const_iterator it1 = this->representingNamespaces_.begin(); it1 != this->representingNamespaces_.end(); ++it1)
122        {
123            for (std::set<NamespaceNode*>::const_iterator it2 = ns->representingNamespaces_.begin(); it2 != ns->representingNamespaces_.end(); ++it2)
124            {
125                if ((*it1)->includes(*it2))
126                {
127                    if (this->operator_ == "or")
128                        return true;
129
130                    if (this->operator_ == "not")
131                        return false;
132                }
133                else
134                {
135                    if (this->operator_ == "and")
136                        return false;
137                }
138            }
139        }
140
141        if (this->operator_ == "or")
142            return false;
143        else if (this->operator_ == "and")
144            return true;
145        else if (this->operator_ == "not")
146            return true;
147
148        return false;
149    }
150}
Note: See TracBrowser for help on using the repository browser.