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 | |
---|
34 | namespace 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 | { |
---|
62 | BaseObject::XMLPort(xmlelement, loading); |
---|
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, '\\', '"', '\0', '\0', '\0'); |
---|
75 | for (unsigned int i = 0; i < tokens.size(); i++) |
---|
76 | { |
---|
77 | for (std::set<NamespaceNode*>::iterator it = this->getNamespace()->representingNamespaces_.begin(); it != this->getNamespace()->representingNamespaces_.end(); ++it) |
---|
78 | { |
---|
79 | std::set<NamespaceNode*> temp = (*it)->getNodeRelative(tokens[i]); |
---|
80 | this->representingNamespaces_.insert(temp.begin(), temp.end()); |
---|
81 | } |
---|
82 | } |
---|
83 | |
---|
84 | XMLPortParam(Namespace, "operator", setOperator, getOperator, xmlelement, loading); |
---|
85 | XMLPortParam(Namespace, "bAutogenerated", setAutogenerated, isAutogenerated, xmlelement, loading); |
---|
86 | |
---|
87 | if (this->bAutogeneratedFileRootNamespace_) |
---|
88 | { |
---|
89 | for (std::set<NamespaceNode*>::iterator it = this->representingNamespaces_.begin(); it != this->representingNamespaces_.end(); ++it) |
---|
90 | { |
---|
91 | (*it)->setRoot(true); |
---|
92 | (*it)->setHidden(true); |
---|
93 | } |
---|
94 | } |
---|
95 | |
---|
96 | XMLPortObject(Namespace, BaseObject, "", loadObjects, saveObjects, xmlelement, loading, true, false); |
---|
97 | } |
---|
98 | |
---|
99 | void Namespace::loadObjects(BaseObject* object) |
---|
100 | { |
---|
101 | object->setNamespace(this); |
---|
102 | } |
---|
103 | |
---|
104 | const BaseObject* Namespace::saveObjects(unsigned int index) const |
---|
105 | { |
---|
106 | return 0; // todo |
---|
107 | } |
---|
108 | |
---|
109 | bool Namespace::includes(const Namespace* ns) const |
---|
110 | { |
---|
111 | for (std::set<NamespaceNode*>::const_iterator it1 = this->representingNamespaces_.begin(); it1 != this->representingNamespaces_.end(); ++it1) |
---|
112 | { |
---|
113 | for (std::set<NamespaceNode*>::const_iterator it2 = ns->representingNamespaces_.begin(); it2 != ns->representingNamespaces_.end(); ++it2) |
---|
114 | { |
---|
115 | if ((*it1)->includes(*it2)) |
---|
116 | { |
---|
117 | if (this->operator_ == "or") |
---|
118 | return true; |
---|
119 | |
---|
120 | if (this->operator_ == "not") |
---|
121 | return false; |
---|
122 | } |
---|
123 | else |
---|
124 | { |
---|
125 | if (this->operator_ == "and") |
---|
126 | return false; |
---|
127 | } |
---|
128 | } |
---|
129 | } |
---|
130 | |
---|
131 | if (this->operator_ == "or") |
---|
132 | return false; |
---|
133 | else if (this->operator_ == "and") |
---|
134 | return true; |
---|
135 | else if (this->operator_ == "not") |
---|
136 | return true; |
---|
137 | |
---|
138 | return false; |
---|
139 | } |
---|
140 | } |
---|