Changeset 901 for code/branches/core2/src/orxonox/core
- Timestamp:
- Mar 19, 2008, 12:38:32 AM (17 years ago)
- Location:
- code/branches/core2/src/orxonox/core
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/core2/src/orxonox/core/Loader.cc
r899 r901 115 115 ticpp::Document xmlfile(level->getFile()); 116 116 xmlfile.LoadFile(); 117 117 118 ticpp::Element rootElement; 118 119 rootElement.SetAttribute("name", "root"); 120 rootElement.SetAttribute("bAutogenerated", true); 119 121 120 122 for (ticpp::Iterator<ticpp::Element> child = xmlfile.FirstChildElement(false); child != child.end(); child++) … … 126 128 rootNamespace->setLevel(level); 127 129 rootNamespace->setNamespace(rootNamespace); 128 rootNamespace-> deleteNamespaceNodesAfterDestruction(true);130 rootNamespace->setRoot(true); 129 131 rootNamespace->XMLPort(rootElement, true); 130 132 131 133 COUT(0) << "Finished loading " << level->getFile() << "." << std::endl; 134 135 COUT(4) << "Namespace-tree:" << std::endl << rootNamespace->toString(" ") << std::endl; 132 136 133 137 return true; -
code/branches/core2/src/orxonox/core/Namespace.cc
r898 r901 41 41 42 42 this->bAutogeneratedFileRootNamespace_ = false; 43 this->b DeleteNamespaceNodesAfterDestruction_ = false;43 this->bRoot_ = false; 44 44 this->operator_ = "or"; 45 45 } … … 47 47 Namespace::~Namespace() 48 48 { 49 if (this->b DeleteNamespaceNodesAfterDestruction_)49 if (this->bRoot_) 50 50 for (std::set<NamespaceNode*>::iterator it = this->representingNamespaces_.begin(); it != this->representingNamespaces_.end(); ++it) 51 51 delete (*it); … … 73 73 name.replace(pos, 1, " "); 74 74 SubString tokens(name, " ", "", false, '\\', '"', '\0', '\0', '\0'); 75 for (unsigned int i = 0; i < tokens.size(); i++)75 if (this->bRoot_) 76 76 { 77 for (std::set<NamespaceNode*>::iterator it = this->getNamespace()->representingNamespaces_.begin(); it != this->getNamespace()->representingNamespaces_.end(); ++it) 77 this->representingNamespaces_.insert(new NamespaceNode(this->getName())); 78 } 79 else 80 { 81 for (unsigned int i = 0; i < tokens.size(); i++) 78 82 { 79 std::set<NamespaceNode*> temp = (*it)->getNodeRelative(tokens[i]); 80 this->representingNamespaces_.insert(temp.begin(), temp.end()); 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 } 81 88 } 82 89 } … … 138 145 return false; 139 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 } 140 179 } -
code/branches/core2/src/orxonox/core/Namespace.h
r896 r901 59 59 { return this->operator_; } 60 60 61 void setRoot(bool bRoot) 62 { this->bRoot_ = bRoot; } 63 61 64 bool includes(const Namespace* ns) const; 62 65 bool isIncludedIn(const Namespace* ns) const { return ns->includes(this); } 63 66 64 void deleteNamespaceNodesAfterDestruction(bool bDelete)65 { this->bDeleteNamespaceNodesAfterDestruction_ = bDelete; }67 std::string toString() const; 68 std::string toString(const std::string& indentation) const; 66 69 67 70 private: 68 71 std::set<NamespaceNode*> representingNamespaces_; 69 72 bool bAutogeneratedFileRootNamespace_; 70 bool b DeleteNamespaceNodesAfterDestruction_;73 bool bRoot_; 71 74 std::string operator_; 72 75 }; -
code/branches/core2/src/orxonox/core/NamespaceNode.cc
r895 r901 49 49 std::set<NamespaceNode*> nodes; 50 50 51 if ( name == "")51 if ((name.size() == 0) || (name == "")) 52 52 { 53 53 nodes.insert(this); … … 56 56 { 57 57 unsigned int pos = name.find("::"); 58 std::string firstPart = name.substr(0, pos); 59 std::string secondPart = name.substr(pos + 2, std::string::npos); 58 std::string firstPart = name; 59 std::string secondPart; 60 61 if (pos != std::string::npos) 62 { 63 firstPart = name.substr(0, pos); 64 secondPart = name.substr(pos + 2, std::string::npos); 65 } 60 66 61 67 if (firstPart == "..") … … 64 70 { 65 71 COUT(2) << "Warning: Can't go to enclosing namespace with '..' operator in namespace " << this->name_ << ", namespace is root." << std::endl; 72 nodes = this->getNodeRelative(secondPart); 73 } 74 else if (!this->parent_) 75 { 76 COUT(2) << "Warning: Can't go to enclosing namespace with '..' operator in namespace " << this->name_ << ", no parent namespace set." << std::endl; 66 77 nodes = this->getNodeRelative(secondPart); 67 78 } … … 78 89 79 90 if ((*it).second->isHidden()) 91 { 80 92 COUT(2) << "Warning: Subnamespace '" << firstPart << "' in namespace '" << this->name_ << "' is hidden and can't be accessed." << std::endl; 93 nodes.insert(this); 94 } 81 95 else 96 { 82 97 nodes = (*it).second->getNodeRelative(secondPart); 98 } 83 99 } 84 100 else 85 101 { 102 bool bFoundMatchingNamespace = false; 103 86 104 for (std::map<std::string, NamespaceNode*>::iterator it = this->subnodes_.begin(); it != this->subnodes_.end(); ++it) 87 105 { … … 90 108 std::set<NamespaceNode*> temp2 = (*it).second->getNodeRelative(secondPart); 91 109 nodes.insert(temp2.begin(), temp2.end()); 110 bFoundMatchingNamespace = true; 92 111 } 112 } 113 114 if (!bFoundMatchingNamespace) 115 { 116 COUT(2) << "Warning: No file included with name '" << firstPart.substr(1, std::string::npos) << "' at this part of the level file, using parent namespace instead." << std::endl; 117 nodes = this->getNodeRelative(secondPart); 93 118 } 94 119 } … … 113 138 return false; 114 139 } 140 141 std::string NamespaceNode::toString() const 142 { 143 std::string output = this->name_; 144 145 if (this->subnodes_.size() > 0) 146 { 147 output += " ("; 148 149 int i = 0; 150 for (std::map<std::string, NamespaceNode*>::const_iterator it = this->subnodes_.begin(); it != this->subnodes_.end(); i++, ++it) 151 { 152 if (i > 0) 153 output += ", "; 154 155 output += (*it).second->toString(); 156 } 157 158 output += ")"; 159 } 160 161 return output; 162 } 163 164 std::string NamespaceNode::toString(const std::string& indentation) const 165 { 166 std::string output = (indentation + this->name_ + "\n"); 167 168 for (std::map<std::string, NamespaceNode*>::const_iterator it = this->subnodes_.begin(); it != this->subnodes_.end(); ++it) 169 output += (*it).second->toString(indentation + " "); 170 171 return output; 172 } 115 173 } -
code/branches/core2/src/orxonox/core/NamespaceNode.h
r895 r901 53 53 bool includes(const NamespaceNode*) const; 54 54 55 std::string toString() const; 56 std::string toString(const std::string& indentation) const; 57 55 58 private: 56 59 std::string name_; -
code/branches/core2/src/orxonox/core/XMLPort.h
r898 r901 256 256 newObject->setNamespace(object->getNamespace()); 257 257 if (this->bLoadBefore_) 258 { 258 259 newObject->XMLPort(*child, true); 259 COUT(4) << object->getLoaderIndentation() << "assigning " << child->Value() << " (objectname " << newObject->getName() << ") to " << this->classname_ << " (objectname " << object->getName() << ")" << std::endl; 260 COUT(4) << object->getLoaderIndentation() << "assigning " << child->Value() << " (objectname " << newObject->getName() << ") to " << this->classname_ << " (objectname " << object->getName() << ")" << std::endl; 261 } 262 else 263 { 264 COUT(4) << object->getLoaderIndentation() << "assigning " << child->Value() << " (object not yet loaded) to " << this->classname_ << " (objectname " << object->getName() << ")" << std::endl; 265 } 260 266 (*object.*this->loadfunction_)(newObject); 261 267 if (!this->bLoadBefore_)
Note: See TracChangeset
for help on using the changeset viewer.