[1505] | 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 | #include "Namespace.h" |
---|
[3196] | 30 | |
---|
| 31 | #include <set> |
---|
| 32 | |
---|
[1505] | 33 | #include "NamespaceNode.h" |
---|
| 34 | #include "CoreIncludes.h" |
---|
| 35 | #include "XMLPort.h" |
---|
| 36 | #include "util/SubString.h" |
---|
| 37 | |
---|
| 38 | namespace orxonox |
---|
| 39 | { |
---|
[9667] | 40 | RegisterClass(Namespace); |
---|
[1505] | 41 | |
---|
[9667] | 42 | Namespace::Namespace(Context* context) : BaseObject(context), Context(context), |
---|
[1505] | 43 | bAutogeneratedFileRootNamespace_(false), |
---|
| 44 | bRoot_(false), |
---|
| 45 | operator_("or") |
---|
| 46 | { |
---|
| 47 | RegisterObject(Namespace); |
---|
[10298] | 48 | |
---|
[10624] | 49 | this->setNamespace(WeakPtr<Namespace>(this)); // store a weak-pointer to itself (a strong-pointer would create a recursive dependency) |
---|
[1505] | 50 | } |
---|
| 51 | |
---|
| 52 | Namespace::~Namespace() |
---|
| 53 | { |
---|
| 54 | if (this->bRoot_) |
---|
| 55 | for (std::set<NamespaceNode*>::iterator it = this->representingNamespaces_.begin(); it != this->representingNamespaces_.end(); ++it) |
---|
| 56 | delete (*it); |
---|
| 57 | } |
---|
| 58 | |
---|
| 59 | void Namespace::XMLPort(Element& xmlelement, XMLPort::Mode mode) |
---|
| 60 | { |
---|
[1747] | 61 | SUPER(Namespace, XMLPort, xmlelement, mode); |
---|
[1505] | 62 | |
---|
| 63 | std::string name = this->getName(); |
---|
[1889] | 64 | size_t pos = 0; |
---|
[1505] | 65 | while ((pos = name.find(',')) != std::string::npos) |
---|
| 66 | name.replace(pos, 1, " "); |
---|
| 67 | while ((pos = name.find(';')) != std::string::npos) |
---|
| 68 | name.replace(pos, 1, " "); |
---|
| 69 | while ((pos = name.find('\n')) != std::string::npos) |
---|
| 70 | name.replace(pos, 1, " "); |
---|
| 71 | while ((pos = name.find('\t')) != std::string::npos) |
---|
| 72 | name.replace(pos, 1, " "); |
---|
| 73 | SubString tokens(name, " ", "", false, '\\', true, '"', true, '\0', '\0', true, '\0'); |
---|
| 74 | if (this->bRoot_) |
---|
| 75 | { |
---|
| 76 | this->representingNamespaces_.insert(new NamespaceNode(this->getName())); |
---|
| 77 | } |
---|
| 78 | else |
---|
| 79 | { |
---|
| 80 | for (unsigned int i = 0; i < tokens.size(); i++) |
---|
| 81 | { |
---|
| 82 | for (std::set<NamespaceNode*>::iterator it = this->getNamespace()->representingNamespaces_.begin(); it != this->getNamespace()->representingNamespaces_.end(); ++it) |
---|
| 83 | { |
---|
| 84 | std::set<NamespaceNode*> temp = (*it)->getNodeRelative(tokens[i]); |
---|
| 85 | this->representingNamespaces_.insert(temp.begin(), temp.end()); |
---|
| 86 | } |
---|
| 87 | } |
---|
| 88 | } |
---|
| 89 | |
---|
| 90 | XMLPortParam(Namespace, "operator", setOperator, getOperator, xmlelement, mode); |
---|
| 91 | XMLPortParam(Namespace, "bAutogenerated", setAutogenerated, isAutogenerated, xmlelement, mode); |
---|
| 92 | |
---|
| 93 | if (this->bAutogeneratedFileRootNamespace_) |
---|
| 94 | { |
---|
| 95 | for (std::set<NamespaceNode*>::iterator it = this->representingNamespaces_.begin(); it != this->representingNamespaces_.end(); ++it) |
---|
| 96 | { |
---|
| 97 | (*it)->setRoot(true); |
---|
| 98 | (*it)->setHidden(true); |
---|
| 99 | } |
---|
| 100 | } |
---|
| 101 | |
---|
[1854] | 102 | XMLPortObjectExtended(Namespace, BaseObject, "", loadObjects, saveObjects, xmlelement, mode, true, false); |
---|
[1505] | 103 | } |
---|
| 104 | |
---|
| 105 | void Namespace::loadObjects(BaseObject* object) |
---|
| 106 | { |
---|
| 107 | } |
---|
| 108 | |
---|
| 109 | const BaseObject* Namespace::saveObjects(unsigned int index) const |
---|
| 110 | { |
---|
| 111 | return 0; // todo |
---|
| 112 | } |
---|
| 113 | |
---|
| 114 | bool Namespace::includes(const Namespace* ns) const |
---|
| 115 | { |
---|
| 116 | for (std::set<NamespaceNode*>::const_iterator it1 = this->representingNamespaces_.begin(); it1 != this->representingNamespaces_.end(); ++it1) |
---|
| 117 | { |
---|
| 118 | for (std::set<NamespaceNode*>::const_iterator it2 = ns->representingNamespaces_.begin(); it2 != ns->representingNamespaces_.end(); ++it2) |
---|
| 119 | { |
---|
| 120 | if ((*it1)->includes(*it2)) |
---|
| 121 | { |
---|
| 122 | if (this->operator_ == "or") |
---|
| 123 | return true; |
---|
| 124 | |
---|
| 125 | if (this->operator_ == "not") |
---|
| 126 | return false; |
---|
| 127 | } |
---|
| 128 | else |
---|
| 129 | { |
---|
| 130 | if (this->operator_ == "and") |
---|
| 131 | return false; |
---|
| 132 | } |
---|
| 133 | } |
---|
| 134 | } |
---|
| 135 | |
---|
| 136 | if (this->operator_ == "or") |
---|
| 137 | return false; |
---|
| 138 | else if (this->operator_ == "and") |
---|
| 139 | return true; |
---|
| 140 | else if (this->operator_ == "not") |
---|
| 141 | return true; |
---|
| 142 | |
---|
| 143 | return false; |
---|
| 144 | } |
---|
| 145 | |
---|
| 146 | std::string Namespace::toString() const |
---|
| 147 | { |
---|
| 148 | std::string output; |
---|
| 149 | |
---|
| 150 | int i = 0; |
---|
| 151 | for (std::set<NamespaceNode*>::const_iterator it = this->representingNamespaces_.begin(); it != this->representingNamespaces_.end(); i++, ++it) |
---|
| 152 | { |
---|
| 153 | if (i > 0) |
---|
| 154 | output += " / "; |
---|
| 155 | |
---|
| 156 | output += (*it)->toString(); |
---|
| 157 | } |
---|
| 158 | |
---|
| 159 | return output; |
---|
| 160 | } |
---|
| 161 | |
---|
| 162 | std::string Namespace::toString(const std::string& indentation) const |
---|
| 163 | { |
---|
| 164 | std::string output; |
---|
| 165 | |
---|
| 166 | int i = 0; |
---|
| 167 | for (std::set<NamespaceNode*>::const_iterator it = this->representingNamespaces_.begin(); it != this->representingNamespaces_.end(); i++, ++it) |
---|
| 168 | { |
---|
| 169 | if (i > 0) |
---|
[6417] | 170 | output += '\n'; |
---|
[1505] | 171 | |
---|
| 172 | output += (*it)->toString(indentation); |
---|
| 173 | } |
---|
| 174 | |
---|
| 175 | return output; |
---|
| 176 | } |
---|
| 177 | } |
---|