Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 994 was 994, checked in by landauf, 16 years ago
  • added some symbols to the CommandExecutor: a) expression | expression: the pipe leads the output from the right expression into the left one b) expression > file: writes the output of the expression into a file c) expression < file: reads a file and uses it's content as input for the expression
  • added new console commands: a) echo text: returns the input b) read file: reads a file and returns the content c) write file text: writes text into a file d) append file text: appends text to a file
  • added stripEnclosingQuotes function to String.h, that removes enclosing quotes (if there are some). whitespaces outside the quotes are stripped, whitespaces inside the quotes stay. removes the quotes only if there is nothing else than whitespaces outside of them. what it changes: "expression" → expression what it let unchanged:
    • ex"press"ion
    • a"expression"b
    • a"expression"
    • "expression"b
    • express"ion
  • extended SubString: added some bools to determine the behaviour when dividing a string like the following up into pieces: mytext "this is a quoted area" blub (0, 1, 2)

this usually results in:
mytext / this is a quoted area / blub / 0, 1, 2

but now you can change it to:
mytext / "this is a quoted area" / blub / (0, 1, 2)

this is important if the string wents through several substring splitups and the quotes and brackets should stay.

File size: 5.8 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->bRoot_ = false;
44        this->operator_ = "or";
45    }
46
47    Namespace::~Namespace()
48    {
49        if (this->bRoot_)
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, XMLPort::Mode mode)
61    {
62        BaseObject::XMLPort(xmlelement, mode);
63
64        std::string name = this->getName();
65        unsigned int pos = 0;
66        while ((pos = name.find(',')) != std::string::npos)
67            name.replace(pos, 1, " ");
68        while ((pos = name.find(';')) != std::string::npos)
69            name.replace(pos, 1, " ");
70        while ((pos = name.find('\n')) != std::string::npos)
71            name.replace(pos, 1, " ");
72        while ((pos = name.find('\t')) != std::string::npos)
73            name.replace(pos, 1, " ");
74        SubString tokens(name, " ", "", false, '\\', true, '"', true, '\0', '\0', true, '\0');
75        if (this->bRoot_)
76        {
77            this->representingNamespaces_.insert(new NamespaceNode(this->getName()));
78        }
79        else
80        {
81            for (unsigned int i = 0; i < tokens.size(); i++)
82            {
83                for (std::set<NamespaceNode*>::iterator it = this->getNamespace()->representingNamespaces_.begin(); it != this->getNamespace()->representingNamespaces_.end(); ++it)
84                {
85                    std::set<NamespaceNode*> temp = (*it)->getNodeRelative(tokens[i]);
86                    this->representingNamespaces_.insert(temp.begin(), temp.end());
87                }
88            }
89        }
90
91        XMLPortParam(Namespace, "operator", setOperator, getOperator, xmlelement, mode);
92        XMLPortParam(Namespace, "bAutogenerated", setAutogenerated, isAutogenerated, xmlelement, mode);
93
94        if (this->bAutogeneratedFileRootNamespace_)
95        {
96            for (std::set<NamespaceNode*>::iterator it = this->representingNamespaces_.begin(); it != this->representingNamespaces_.end(); ++it)
97            {
98                (*it)->setRoot(true);
99                (*it)->setHidden(true);
100            }
101        }
102
103        XMLPortObject(Namespace, BaseObject, "", loadObjects, saveObjects, xmlelement, mode, true, false);
104    }
105
106    void Namespace::loadObjects(BaseObject* object)
107    {
108        object->setNamespace(this);
109    }
110
111    const BaseObject* Namespace::saveObjects(unsigned int index) const
112    {
113        return 0; // todo
114    }
115
116    bool Namespace::includes(const Namespace* ns) const
117    {
118        for (std::set<NamespaceNode*>::const_iterator it1 = this->representingNamespaces_.begin(); it1 != this->representingNamespaces_.end(); ++it1)
119        {
120            for (std::set<NamespaceNode*>::const_iterator it2 = ns->representingNamespaces_.begin(); it2 != ns->representingNamespaces_.end(); ++it2)
121            {
122                if ((*it1)->includes(*it2))
123                {
124                    if (this->operator_ == "or")
125                        return true;
126
127                    if (this->operator_ == "not")
128                        return false;
129                }
130                else
131                {
132                    if (this->operator_ == "and")
133                        return false;
134                }
135            }
136        }
137
138        if (this->operator_ == "or")
139            return false;
140        else if (this->operator_ == "and")
141            return true;
142        else if (this->operator_ == "not")
143            return true;
144
145        return false;
146    }
147
148    std::string Namespace::toString() const
149    {
150        std::string output;
151
152        int i = 0;
153        for (std::set<NamespaceNode*>::const_iterator it = this->representingNamespaces_.begin(); it != this->representingNamespaces_.end(); i++, ++it)
154        {
155            if (i > 0)
156                output += " / ";
157
158            output += (*it)->toString();
159        }
160
161        return output;
162    }
163
164    std::string Namespace::toString(const std::string& indentation) const
165    {
166        std::string output;
167
168        int i = 0;
169        for (std::set<NamespaceNode*>::const_iterator it = this->representingNamespaces_.begin(); it != this->representingNamespaces_.end(); i++, ++it)
170        {
171            if (i > 0)
172                output += "\n";
173
174            output += (*it)->toString(indentation);
175        }
176
177        return output;
178    }
179}
Note: See TracBrowser for help on using the repository browser.