Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 895


Ignore:
Timestamp:
Mar 17, 2008, 1:33:00 AM (16 years ago)
Author:
landauf
Message:
  • added new XMLPortParam template to specify the template arguments / to specify the functor
  • implemented the Namespace object and
  • added a NamespaceNode class that helps keeping track of the existing namespaces in a level

this is not yet tested nor fully included in the loader nor usefull (as we have no scripts at the moment), but i think it's a good start.

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  
    1818  XMLPort.cc
    1919  Namespace.cc
     20  NamespaceNode.cc
    2021)
    2122
  • code/branches/core2/src/orxonox/core/CorePrereqs.h

    r877 r895  
    9696  class MetaObjectListElement;
    9797  class Namespace;
     98  class NamespaceNode;
    9899  template <class T>
    99100  class ObjectList;
  • code/branches/core2/src/orxonox/core/Namespace.cc

    r879 r895  
    2929#include "CoreIncludes.h"
    3030#include "XMLPort.h"
     31#include "util/SubString.h"
     32#include "NamespaceNode.h"
    3133
    3234namespace orxonox
     
    3840        RegisterObject(Namespace);
    3941
    40         this->representingNamespace_ = this;
     42        this->bAutogeneratedFileRootNamespace_ = false;
     43        this->operator_ = "or";
    4144    }
    4245
     
    5558        BaseObject::XMLPort(xmlelement, loading);
    5659
     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
    5792        XMLPortObject(Namespace, BaseObject, "", loadObjects, saveObjects, xmlelement, loading, true, false);
    5893    }
     
    6095    void Namespace::loadObjects(BaseObject* object)
    6196    {
    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);
    8198    }
    8299
     
    85102        return 0; // todo
    86103    }
     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    }
    87136}
  • code/branches/core2/src/orxonox/core/Namespace.h

    r879 r895  
    4949            const BaseObject* saveObjects(unsigned int index) const;
    5050
    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); }
    5363
    5464        private:
    55             std::map<std::string, Namespace*> namespaces_;
    56             Namespace* representingNamespace_;
     65            std::set<NamespaceNode*> representingNamespaces_;
     66            bool bAutogeneratedFileRootNamespace_;
     67            std::string operator_;
    5768    };
    5869}
  • code/branches/core2/src/orxonox/core/XMLPort.h

    r879 r895  
    4242
    4343#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) \
    4658    { \
    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); \
    4961    } \
    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
    6064
    6165#define XMLPortObject(classname, objectclass, sectionname, loadfunction, savefunction, xmlelement, loading, bApplyLoaderMask, bLoadBefore) \
Note: See TracChangeset for help on using the changeset viewer.