[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" |
---|
| 30 | #include "NamespaceNode.h" |
---|
| 31 | #include "CoreIncludes.h" |
---|
| 32 | #include "XMLPort.h" |
---|
| 33 | #include "util/SubString.h" |
---|
| 34 | |
---|
| 35 | namespace orxonox |
---|
| 36 | { |
---|
| 37 | CreateFactory(Namespace); |
---|
| 38 | |
---|
[2019] | 39 | Namespace::Namespace(BaseObject* creator) : BaseObject(creator), |
---|
[1505] | 40 | bAutogeneratedFileRootNamespace_(false), |
---|
| 41 | bRoot_(false), |
---|
| 42 | operator_("or") |
---|
| 43 | { |
---|
| 44 | RegisterObject(Namespace); |
---|
| 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 | { |
---|
[1747] | 62 | SUPER(Namespace, XMLPort, xmlelement, mode); |
---|
[1505] | 63 | |
---|
| 64 | std::string name = this->getName(); |
---|
[1889] | 65 | size_t pos = 0; |
---|
[1505] | 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 | |
---|
[1854] | 103 | XMLPortObjectExtended(Namespace, BaseObject, "", loadObjects, saveObjects, xmlelement, mode, true, false); |
---|
[1505] | 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 | } |
---|