Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Oct 4, 2015, 9:12:21 PM (9 years ago)
Author:
landauf
Message:

merged branch core7 back to trunk

Location:
code/trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • code/trunk

  • code/trunk/src/libraries/core/BaseObject.h

    r10298 r10624  
    5151#include "class/OrxonoxClass.h"
    5252#include "class/Super.h"
    53 #include "object/SmartPtr.h"
     53#include "object/StrongPtr.h"
    5454
    5555namespace orxonox
     
    6363    {
    6464        template <class T> friend class XMLPortClassParamContainer;
     65
     66        public:
     67            template <class T>
     68            class StrongOrWeakPtr
     69            {
     70                public:
     71                    inline StrongOrWeakPtr();
     72                    inline StrongOrWeakPtr(const StrongPtr<T>& ptr);
     73                    inline StrongOrWeakPtr(const WeakPtr<T>& ptr);
     74
     75                    inline T* get() const;
     76                    inline StrongPtr<T> createStrongPtr() const;
     77
     78                private:
     79                    StrongPtr<T> strongPtr_;
     80                    WeakPtr<T> weakPtr_;
     81            };
    6582
    6683        public:
     
    138155                { return this->templates_; }
    139156
    140             inline void setNamespace(const SmartPtr<Namespace>& ns) { this->namespace_ = ns; }
    141             inline const SmartPtr<Namespace>& getNamespace() const { return this->namespace_; }
     157            inline void setNamespace(const StrongOrWeakPtr<Namespace>& ns) { this->namespace_ = ns; }
     158            inline Namespace* getNamespace() const { return this->namespace_.get(); }
    142159
    143160            inline void setCreator(BaseObject* creator) { this->creator_ = creator; }
    144161            inline BaseObject* getCreator() const { return this->creator_; }
    145162
    146             inline void setScene(const SmartPtr<Scene>& scene, uint32_t sceneID) { this->scene_ = scene; this->sceneID_=sceneID; }
    147             inline const SmartPtr<Scene>& getScene() const { return this->scene_; }
     163            inline void setScene(const StrongOrWeakPtr<Scene>& scene, uint32_t sceneID) { this->scene_ = scene; this->sceneID_=sceneID; }
     164            inline Scene* getScene() const { return this->scene_.get(); }
    148165            inline virtual uint32_t getSceneID() const { return this->sceneID_; }
    149166
    150             inline void setGametype(const SmartPtr<Gametype>& gametype)
    151             {
    152                 if (gametype != this->gametype_)
    153                 {
    154                     this->oldGametype_ = this->gametype_;
    155                     this->gametype_ = gametype;
    156                     this->changedGametype();
    157                 }
    158             }
    159             inline const SmartPtr<Gametype>& getGametype() const { return this->gametype_; }
    160             inline Gametype* getOldGametype() const { return this->oldGametype_; }
    161             virtual void changedGametype() {}
    162 
    163             inline void setLevel(const SmartPtr<Level>& level)
    164             {
    165                 if (level != this->level_)
    166                 {
    167                     this->level_ = level;
    168                     this->changedLevel();
    169                 }
    170             }
    171             inline const SmartPtr<Level>& getLevel() const { return this->level_; }
    172             virtual void changedLevel() {}
     167            inline void setGametype(const StrongOrWeakPtr<Gametype>& gametype) { this->gametype_ = gametype; }
     168            inline Gametype* getGametype() const { return this->gametype_.get(); }
     169
     170            inline void setLevel(const StrongOrWeakPtr<Level>& level) { this->level_ = level; }
     171            inline Level* getLevel() const { return this->level_.get(); }
    173172
    174173            void addEventSource(BaseObject* source, const std::string& state);
     
    217216            void registerEventStates();
    218217
    219             bool                   bInitialized_;              //!< True if the object was initialized (passed the object registration)
    220             const XMLFile*         file_;                      //!< The XMLFile that loaded this object
    221             Element*               lastLoadedXMLElement_;      //!< Non 0 if the TinyXML attributes have already been copied to our own lowercase map
     218            bool                       bInitialized_;          //!< True if the object was initialized (passed the object registration)
     219            const XMLFile*             file_;                  //!< The XMLFile that loaded this object
     220            Element*                   lastLoadedXMLElement_;  //!< Non 0 if the TinyXML attributes have already been copied to our own lowercase map
    222221            std::map<std::string, std::string> xmlAttributes_; //!< Lowercase XML attributes
    223             std::string            loaderIndentation_;         //!< Indentation of the debug output in the Loader
    224             SmartPtr<Namespace>    namespace_;
    225             BaseObject*            creator_;
    226             SmartPtr<Scene>        scene_;
    227             uint32_t               sceneID_;
    228             SmartPtr<Gametype>     gametype_;
    229             Gametype*              oldGametype_;
    230             SmartPtr<Level>        level_;
    231             std::set<Template*>    templates_;
     222            std::string                loaderIndentation_;     //!< Indentation of the debug output in the Loader
     223            StrongOrWeakPtr<Namespace> namespace_;
     224            BaseObject*                creator_;
     225            StrongOrWeakPtr<Scene>     scene_;
     226            uint32_t                   sceneID_;
     227            StrongOrWeakPtr<Gametype>  gametype_;
     228            StrongOrWeakPtr<Level>     level_;
     229            std::set<Template*>        templates_;
    232230
    233231            std::map<BaseObject*, std::string>  eventSources_;           //!< List of objects which send events to this object, mapped to the state which they affect
     
    243241    SUPER_FUNCTION(4, BaseObject, XMLEventPort, false);
    244242    SUPER_FUNCTION(8, BaseObject, changedName, false);
    245     SUPER_FUNCTION(9, BaseObject, changedGametype, false);
     243
     244    template <class T>
     245    BaseObject::StrongOrWeakPtr<T>::StrongOrWeakPtr()
     246    {
     247    }
     248
     249    template <class T>
     250    BaseObject::StrongOrWeakPtr<T>::StrongOrWeakPtr(const StrongPtr<T>& ptr) : strongPtr_(ptr)
     251    {
     252    }
     253
     254    template <class T>
     255    BaseObject::StrongOrWeakPtr<T>::StrongOrWeakPtr(const WeakPtr<T>& ptr) : weakPtr_(ptr)
     256    {
     257    }
     258
     259    template <class T>
     260    T* BaseObject::StrongOrWeakPtr<T>::get() const
     261    {
     262        if (this->strongPtr_)
     263            return this->strongPtr_;
     264        else if (this->weakPtr_)
     265            return this->weakPtr_;
     266        else
     267            return NULL;
     268    }
     269
     270    template <class T>
     271    StrongPtr<T> BaseObject::StrongOrWeakPtr<T>::createStrongPtr() const
     272    {
     273        if (this->strongPtr_)
     274            return this->strongPtr_; // creates a copy
     275        else
     276            return this->weakPtr_; // converts automatically to StrongPtr
     277    }
    246278}
    247279
Note: See TracChangeset for help on using the changeset viewer.