Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 879


Ignore:
Timestamp:
Mar 10, 2008, 5:07:48 PM (17 years ago)
Author:
landauf
Message:

started implementing the Namespace hierarchy (still unfinished)

Location:
code/branches/core2/src/orxonox
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • code/branches/core2/src/orxonox/core/BaseObject.h

    r877 r879  
    7979            const std::string& getLevelfile() const;
    8080
    81             inline void setNamespace(Namespace* ns) { this->namespace_ = ns; }
     81            virtual inline void setNamespace(Namespace* ns) { this->namespace_ = ns; }
    8282            inline Namespace* getNamespace() const { return this->namespace_; }
    8383
  • code/branches/core2/src/orxonox/core/Namespace.cc

    r878 r879  
    3838        RegisterObject(Namespace);
    3939
    40         this->representingNamespace_ = 0;
     40        this->representingNamespace_ = this;
    4141    }
    4242
     
    5555        BaseObject::XMLPort(xmlelement, loading);
    5656
    57         XMLPortObject(Namespace, BaseObject, "", loadObjects, saveObjects, xmlelement, loading, true);
     57        XMLPortObject(Namespace, BaseObject, "", loadObjects, saveObjects, xmlelement, loading, true, false);
    5858    }
    5959
    6060    void Namespace::loadObjects(BaseObject* object)
    6161    {
    62         object->setNamespace(this);
     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());
    6381    }
    6482
  • code/branches/core2/src/orxonox/core/Namespace.h

    r878 r879  
    2929#define _Namespace_H__
    3030
    31 #include <list>
     31#include <map>
    3232
    3333#include "BaseObject.h"
     
    4949            const BaseObject* saveObjects(unsigned int index) const;
    5050
     51            void addSubnamespace(Namespace* ns);
     52            bool hasSubnamespace(const std::string& name) const;
     53
    5154        private:
    52             std::list<Namespace*> namespaces_;
     55            std::map<std::string, Namespace*> namespaces_;
    5356            Namespace* representingNamespace_;
    5457    };
  • code/branches/core2/src/orxonox/core/XMLPort.h

    r878 r879  
    5959    xmlcontainer##loadfunction##savefunction->port(this, xmlelement, loading)
    6060
    61 #define XMLPortObject(classname, objectclass, sectionname, loadfunction, savefunction, xmlelement, loading, bApplyLoaderMask) \
     61#define XMLPortObject(classname, objectclass, sectionname, loadfunction, savefunction, xmlelement, loading, bApplyLoaderMask, bLoadBefore) \
    6262    orxonox::XMLPortClassObjectContainer<classname, objectclass>* xmlcontainer##loadfunction##savefunction = (orxonox::XMLPortClassObjectContainer<classname, objectclass>*)(this->getIdentifier()->getXMLPortObjectContainer(sectionname)); \
    6363    if (!xmlcontainer##loadfunction##savefunction) \
    6464    { \
    65         xmlcontainer##loadfunction##savefunction = new orxonox::XMLPortClassObjectContainer<classname, objectclass>(this->getIdentifier()->getName(), std::string(sectionname), &classname::loadfunction, &classname::savefunction, bApplyLoaderMask); \
     65        xmlcontainer##loadfunction##savefunction = new orxonox::XMLPortClassObjectContainer<classname, objectclass>(this->getIdentifier()->getName(), std::string(sectionname), &classname::loadfunction, &classname::savefunction, bApplyLoaderMask, bLoadBefore); \
    6666        this->getIdentifier()->addXMLPortObjectContainer(sectionname, xmlcontainer##loadfunction##savefunction); \
    6767    } \
     
    202202            std::string sectionname_;
    203203            bool bApplyLoaderMask_;
     204            bool bLoadBefore_;
    204205
    205206        private:
     
    212213    {
    213214        public:
    214             XMLPortClassObjectContainer(const std::string classname, const std::string sectionname, void (T::*loadfunction)(O*), const O* (T::*savefunction)(unsigned int) const, bool bApplyLoaderMask)
     215            XMLPortClassObjectContainer(const std::string classname, const std::string sectionname, void (T::*loadfunction)(O*), const O* (T::*savefunction)(unsigned int) const, bool bApplyLoaderMask, bool bLoadBefore)
    215216            {
    216217                this->classname_ = classname;
     
    219220                this->savefunction_ = savefunction;
    220221                this->bApplyLoaderMask_ = bApplyLoaderMask;
     222                this->bLoadBefore_ = bLoadBefore;
    221223            }
    222224
     
    248250                                            newObject->setLoaderIndentation(object->getLoaderIndentation() + "  ");
    249251                                            newObject->setLevel(object->getLevel());
    250                                             newObject->XMLPort(*child, true);
     252                                            newObject->setNamespace(object->getNamespace());
     253                                            if (this->bLoadBefore_)
     254                                                newObject->XMLPort(*child, true);
    251255                                            COUT(4) << object->getLoaderIndentation() << "assigning " << child->Value() << " (objectname " << newObject->getName() << ") to " << this->classname_ << " (objectname " << object->getName() << ")" << std::endl;
    252256                                            (*object.*this->loadfunction_)(newObject);
     257                                            if (!this->bLoadBefore_)
     258                                                newObject->XMLPort(*child, true);
    253259                                            COUT(5) << "  ...fabricated " << child->Value() << " (objectname " << newObject->getName() << ")." << std::endl;
    254260                                        }
  • code/branches/core2/src/orxonox/objects/WorldEntity.cc

    r878 r879  
    182182        XMLPortParam(WorldEntity, "rotationRate", setRotationRate, getRotationRate, xmlelement, loading);
    183183
    184         XMLPortObject(WorldEntity, WorldEntity, "attached", attachWorldEntity, getAttachedWorldEntity, xmlelement, loading, false);
     184        XMLPortObject(WorldEntity, WorldEntity, "attached", attachWorldEntity, getAttachedWorldEntity, xmlelement, loading, false, true);
    185185    }
    186186
Note: See TracChangeset for help on using the changeset viewer.