Changeset 895
- Timestamp:
- Mar 17, 2008, 1:33:00 AM (17 years ago)
- Location:
- code/branches/core2/src/orxonox/core
- Files:
-
- 2 added
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/core2/src/orxonox/core/CMakeLists.txt
r877 r895 18 18 XMLPort.cc 19 19 Namespace.cc 20 NamespaceNode.cc 20 21 ) 21 22 -
code/branches/core2/src/orxonox/core/CorePrereqs.h
r877 r895 96 96 class MetaObjectListElement; 97 97 class Namespace; 98 class NamespaceNode; 98 99 template <class T> 99 100 class ObjectList; -
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 } -
code/branches/core2/src/orxonox/core/Namespace.h
r879 r895 49 49 const BaseObject* saveObjects(unsigned int index) const; 50 50 51 void addSubnamespace(Namespace* ns); 52 bool hasSubnamespace(const std::string& name) const; 51 void setAutogenerated(bool bAutogenerated) 52 { this->bAutogeneratedFileRootNamespace_ = bAutogenerated; } 53 bool isAutogenerated() const 54 { return this->bAutogeneratedFileRootNamespace_; } 55 56 void setOperator(const std::string& op) 57 { this->operator_ = op; } 58 const std::string& getOperator() const 59 { return this->operator_; } 60 61 bool includes(const Namespace* ns) const; 62 bool isIncludedIn(const Namespace* ns) const { return ns->includes(this); } 53 63 54 64 private: 55 std::map<std::string, Namespace*> namespaces_; 56 Namespace* representingNamespace_; 65 std::set<NamespaceNode*> representingNamespaces_; 66 bool bAutogeneratedFileRootNamespace_; 67 std::string operator_; 57 68 }; 58 69 } -
code/branches/core2/src/orxonox/core/XMLPort.h
r879 r895 42 42 43 43 #define XMLPortParam(classname, paramname, loadfunction, savefunction, xmlelement, loading) \ 44 orxonox::XMLPortClassParamContainer<classname>* xmlcontainer##loadfunction##savefunction = (orxonox::XMLPortClassParamContainer<classname>*)(this->getIdentifier()->getXMLPortParamContainer(paramname)); \ 45 if (!xmlcontainer##loadfunction##savefunction) \ 44 XMLPortParamGeneric(classname, paramname, xmlcontainer##loadfunction##savefunction, createFunctor(&classname::loadfunction), createFunctor(&classname::savefunction), xmlelement, loading) 45 #define XMLPortParam_Template(classname, paramname, loadtemplate, loadfunction, savetemplate, savefunction, xmlelement, loading) \ 46 XMLPortParamGeneric(classname, paramname, xmlcontainer##loadfunction##savefunction, createFunctor loadtemplate (&classname::loadfunction), createFunctor savetemplate (&classname::savefunction), xmlelement, loading) 47 48 49 #define XMLPortParamLoadOnly(classname, paramname, loadfunction, xmlelement, loading) \ 50 XMLPortParamGeneric(classname, paramname, xmlcontainer##loadfunction##0, createFunctor(&classname::loadfunction), 0, xmlelement, loading) 51 #define XMLPortParamLoadOnly_Template(classname, paramname, loadtemplate, loadfunction, xmlelement, loading) \ 52 XMLPortParamGeneric(classname, paramname, xmlcontainer##loadfunction##0, createFunctor loadtemplate (&classname::loadfunction), 0, xmlelement, loading) 53 54 55 #define XMLPortParamGeneric(classname, paramname, containername, loadfunctor, savefunctor, xmlelement, loading) \ 56 orxonox::XMLPortClassParamContainer<classname>* containername = (orxonox::XMLPortClassParamContainer<classname>*)(this->getIdentifier()->getXMLPortParamContainer(paramname)); \ 57 if (!containername) \ 46 58 { \ 47 xmlcontainer##loadfunction##savefunction = new orxonox::XMLPortClassParamContainer<classname>(this->getIdentifier()->getName(), std::string(paramname), createFunctor(&classname::loadfunction), createFunctor(&classname::savefunction)); \48 this->getIdentifier()->addXMLPortParamContainer(paramname, xmlcontainer##loadfunction##savefunction); \59 containername = new orxonox::XMLPortClassParamContainer<classname>(this->getIdentifier()->getName(), std::string(paramname), loadfunctor, savefunctor); \ 60 this->getIdentifier()->addXMLPortParamContainer(paramname, containername); \ 49 61 } \ 50 xmlcontainer##loadfunction##savefunction->port(this, xmlelement, loading) 51 52 #define XMLPortParamLoadOnly(classname, paramname, loadfunction, xmlelement, loading) \ 53 orxonox::XMLPortClassParamContainer<classname>* xmlcontainer##loadfunction##savefunction = (orxonox::XMLPortClassParamContainer<classname>*)(this->getIdentifier()->getXMLPortParamContainer(paramname)); \ 54 if (!xmlcontainer##loadfunction##savefunction) \ 55 { \ 56 xmlcontainer##loadfunction##savefunction = new orxonox::XMLPortClassParamContainer<classname>(this->getIdentifier()->getName(), std::string(paramname), createFunctor(&classname::loadfunction), 0); \ 57 this->getIdentifier()->addXMLPortParamContainer(paramname, xmlcontainer##loadfunction##savefunction); \ 58 } \ 59 xmlcontainer##loadfunction##savefunction->port(this, xmlelement, loading) 62 containername->port(this, xmlelement, loading) 63 60 64 61 65 #define XMLPortObject(classname, objectclass, sectionname, loadfunction, savefunction, xmlelement, loading, bApplyLoaderMask, bLoadBefore) \
Note: See TracChangeset
for help on using the changeset viewer.