Changeset 895 for code/branches/core2/src/orxonox/core/Namespace.cc
- Timestamp:
- Mar 17, 2008, 1:33:00 AM (17 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/core2/src/orxonox/core/Namespace.cc
r879 r895 29 29 #include "CoreIncludes.h" 30 30 #include "XMLPort.h" 31 #include "util/SubString.h" 32 #include "NamespaceNode.h" 31 33 32 34 namespace orxonox … … 38 40 RegisterObject(Namespace); 39 41 40 this->representingNamespace_ = this; 42 this->bAutogeneratedFileRootNamespace_ = false; 43 this->operator_ = "or"; 41 44 } 42 45 … … 55 58 BaseObject::XMLPort(xmlelement, loading); 56 59 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 57 92 XMLPortObject(Namespace, BaseObject, "", loadObjects, saveObjects, xmlelement, loading, true, false); 58 93 } … … 60 95 void Namespace::loadObjects(BaseObject* object) 61 96 { 62 object->setNamespace(this->representingNamespace_); 63 64 if (object->isA(Class(Namespace))) 65 this->addSubnamespace((Namespace*)object); 66 } 67 68 void Namespace::addSubnamespace(Namespace* ns) 69 { 70 std::string name = ns->getName().substr(ns->getName().find("::" 71 72 if (!this->hasSubnamespace(ns->getName())) 73 this->namespaces_[ns->getName()] = ns; 74 else 75 ns->representingNamespace_ = object; 76 } 77 78 bool Namespace::hasSubnamespace(const std::string& name) const 79 { 80 return (this->namespaces_.find(name) != this->namespaces_.end()); 97 object->setNamespace(this); 81 98 } 82 99 … … 85 102 return 0; // todo 86 103 } 104 105 bool Namespace::includes(const Namespace* ns) const 106 { 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; 115 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; 135 } 87 136 }
Note: See TracChangeset
for help on using the changeset viewer.