[877] | 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" |
---|
[895] | 31 | #include "util/SubString.h" |
---|
| 32 | #include "NamespaceNode.h" |
---|
[877] | 33 | |
---|
| 34 | namespace orxonox |
---|
| 35 | { |
---|
| 36 | CreateFactory(Namespace); |
---|
| 37 | |
---|
| 38 | Namespace::Namespace() |
---|
| 39 | { |
---|
| 40 | RegisterObject(Namespace); |
---|
[878] | 41 | |
---|
[895] | 42 | this->bAutogeneratedFileRootNamespace_ = false; |
---|
| 43 | this->operator_ = "or"; |
---|
[877] | 44 | } |
---|
| 45 | |
---|
| 46 | Namespace::~Namespace() |
---|
| 47 | { |
---|
| 48 | } |
---|
| 49 | |
---|
| 50 | /** |
---|
| 51 | @brief XML loading and saving. |
---|
| 52 | @param xmlelement The XML-element |
---|
| 53 | @param loading Loading (true) or saving (false) |
---|
| 54 | @return The XML-element |
---|
| 55 | */ |
---|
| 56 | void Namespace::XMLPort(Element& xmlelement, bool loading) |
---|
| 57 | { |
---|
| 58 | BaseObject::XMLPort(xmlelement, loading); |
---|
| 59 | |
---|
[895] | 60 | std::string name = this->getName(); |
---|
| 61 | unsigned int pos = 0; |
---|
| 62 | while ((pos = name.find(',')) != std::string::npos) |
---|
| 63 | name.replace(pos, 1, " "); |
---|
| 64 | while ((pos = name.find(';')) != std::string::npos) |
---|
| 65 | name.replace(pos, 1, " "); |
---|
| 66 | while ((pos = name.find('\n')) != std::string::npos) |
---|
| 67 | name.replace(pos, 1, " "); |
---|
| 68 | while ((pos = name.find('\t')) != std::string::npos) |
---|
| 69 | name.replace(pos, 1, " "); |
---|
| 70 | SubString tokens(name, " ", '\0', false, '\\', '"', '\0', '\0', '\0'); |
---|
| 71 | for (unsigned int i = 0; i < tokens.size(); i++) |
---|
| 72 | { |
---|
| 73 | for (std::set<NamespaceNode*>::iterator it = this->getNamespace()->representingNamespaces_.begin(); it != this->getNamespace()->representingNamespaces_.end(); ++it) |
---|
| 74 | { |
---|
| 75 | std::set<NamespaceNode*> temp = (*it)->getNodeRelative(tokens[i]); |
---|
| 76 | this->representingNamespaces_.insert(temp.begin(), temp.end()); |
---|
| 77 | } |
---|
| 78 | } |
---|
| 79 | |
---|
| 80 | XMLPortParam(Namespace, "operator", setOperator, getOperator, xmlelement, loading); |
---|
| 81 | XMLPortParam(Namespace, "bAutogenerated", setAutogenerated, isAutogenerated, xmlelement, loading); |
---|
| 82 | |
---|
| 83 | if (this->bAutogeneratedFileRootNamespace_) |
---|
| 84 | { |
---|
| 85 | for (std::set<NamespaceNode*>::iterator it = this->representingNamespaces_.begin(); it != this->representingNamespaces_.end(); ++it) |
---|
| 86 | { |
---|
| 87 | (*it)->setRoot(true); |
---|
| 88 | (*it)->setHidden(true); |
---|
| 89 | } |
---|
| 90 | } |
---|
| 91 | |
---|
[879] | 92 | XMLPortObject(Namespace, BaseObject, "", loadObjects, saveObjects, xmlelement, loading, true, false); |
---|
[877] | 93 | } |
---|
| 94 | |
---|
| 95 | void Namespace::loadObjects(BaseObject* object) |
---|
| 96 | { |
---|
[895] | 97 | object->setNamespace(this); |
---|
[877] | 98 | } |
---|
| 99 | |
---|
[895] | 100 | const BaseObject* Namespace::saveObjects(unsigned int index) const |
---|
[879] | 101 | { |
---|
[895] | 102 | return 0; // todo |
---|
[879] | 103 | } |
---|
| 104 | |
---|
[895] | 105 | bool Namespace::includes(const Namespace* ns) const |
---|
[879] | 106 | { |
---|
[895] | 107 | for (std::set<NamespaceNode*>::const_iterator it1 = this->representingNamespaces_.begin(); it1 != this->representingNamespaces_.end(); ++it1) |
---|
| 108 | { |
---|
| 109 | for (std::set<NamespaceNode*>::const_iterator it2 = ns->representingNamespaces_.begin(); it2 != ns->representingNamespaces_.end(); ++it2) |
---|
| 110 | { |
---|
| 111 | if ((*it1)->includes(*it2)) |
---|
| 112 | { |
---|
| 113 | if (this->operator_ == "or") |
---|
| 114 | return true; |
---|
[879] | 115 | |
---|
[895] | 116 | if (this->operator_ == "not") |
---|
| 117 | return false; |
---|
| 118 | } |
---|
| 119 | else |
---|
| 120 | { |
---|
| 121 | if (this->operator_ == "and") |
---|
| 122 | return false; |
---|
| 123 | } |
---|
| 124 | } |
---|
| 125 | } |
---|
| 126 | |
---|
| 127 | if (this->operator_ == "or") |
---|
| 128 | return false; |
---|
| 129 | else if (this->operator_ == "and") |
---|
| 130 | return true; |
---|
| 131 | else if (this->operator_ == "not") |
---|
| 132 | return true; |
---|
| 133 | |
---|
| 134 | return false; |
---|
[877] | 135 | } |
---|
| 136 | } |
---|