- Timestamp:
- Sep 9, 2015, 4:10:21 PM (9 years ago)
- Location:
- code/branches/core7/src
- Files:
-
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/core7/src/libraries/core/BaseObject.cc
r10576 r10578 77 77 { 78 78 this->setFile(this->creator_->getFile()); 79 this->setNamespace(this->creator_->namespace_); 80 this->setScene(this->creator_->scene_, this->creator_->sceneID_); 81 this->setGametype(this->creator_->gametype_); 82 this->setLevel(this->creator_->level_); 79 80 // store strong-pointers on all four base objects by default (can be overwritten with weak-ptr after the constructor if necessary) 81 this->setNamespace(this->creator_->namespace_.createStrongPtr()); 82 this->setScene (this->creator_->scene_ .createStrongPtr(), this->creator_->sceneID_); 83 this->setGametype (this->creator_->gametype_ .createStrongPtr()); 84 this->setLevel (this->creator_->level_ .createStrongPtr()); 83 85 } 84 86 else -
code/branches/core7/src/libraries/core/BaseObject.h
r10576 r10578 63 63 { 64 64 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 }; 65 82 66 83 public: … … 138 155 { return this->templates_; } 139 156 140 inline void setNamespace(const Strong Ptr<Namespace>& ns) { this->namespace_ = ns; }141 inline 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(); } 142 159 143 160 inline void setCreator(BaseObject* creator) { this->creator_ = creator; } 144 161 inline BaseObject* getCreator() const { return this->creator_; } 145 162 146 inline void setScene(const Strong Ptr<Scene>& scene, uint32_t sceneID) { this->scene_ = scene; this->sceneID_=sceneID; }147 inline 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(); } 148 165 inline virtual uint32_t getSceneID() const { return this->sceneID_; } 149 166 150 inline void setGametype(const Strong Ptr<Gametype>& gametype) { this->gametype_ = gametype; }151 inline Gametype* getGametype() const { return this->gametype_ ; }152 153 inline void setLevel(const Strong Ptr<Level>& level) { this->level_ = level; }154 inline Level* getLevel() const { return this->level_ ; }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(); } 155 172 156 173 void addEventSource(BaseObject* source, const std::string& state); … … 199 216 void registerEventStates(); 200 217 201 bool bInitialized_;//!< True if the object was initialized (passed the object registration)202 const XMLFile* file_;//!< The XMLFile that loaded this object203 Element* lastLoadedXMLElement_;//!< Non 0 if the TinyXML attributes have already been copied to our own lowercase map218 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 204 221 std::map<std::string, std::string> xmlAttributes_; //!< Lowercase XML attributes 205 std::string loaderIndentation_;//!< Indentation of the debug output in the Loader206 Strong Ptr<Namespace>namespace_;207 BaseObject* creator_;208 Strong Ptr<Scene>scene_;209 uint32_t sceneID_;210 Strong Ptr<Gametype>gametype_;211 Strong Ptr<Level>level_;212 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_; 213 230 214 231 std::map<BaseObject*, std::string> eventSources_; //!< List of objects which send events to this object, mapped to the state which they affect … … 224 241 SUPER_FUNCTION(4, BaseObject, XMLEventPort, false); 225 242 SUPER_FUNCTION(8, BaseObject, changedName, 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 } 226 278 } 227 279 -
code/branches/core7/src/libraries/core/Namespace.cc
r10562 r10578 47 47 RegisterObject(Namespace); 48 48 49 this->setNamespace( StrongPtr<Namespace>(this, false));49 this->setNamespace(WeakPtr<Namespace>(this)); // store a weak-pointer to itself (a strong-pointer would create a recursive dependency) 50 50 } 51 51 -
code/branches/core7/src/libraries/core/object/StrongPtr.h
r10555 r10578 142 142 } 143 143 144 /// Constructor: Initializes the strong pointer with a pointer to an object. @param pointer The pointer @param bAddRef If true, the reference counter is increased. Don't set this to false unless you know exactly what you're doing! (for example to avoid circular references if the @c this pointer of the possessing object is stored)145 inline StrongPtr(T* pointer , bool bAddRef = true) : pointer_(pointer), base_(pointer)146 { 147 if (this->base_ && bAddRef)144 /// Constructor: Initializes the strong pointer with a pointer to an object. @param pointer The pointer 145 inline StrongPtr(T* pointer) : pointer_(pointer), base_(pointer) 146 { 147 if (this->base_) 148 148 this->base_->incrementReferenceCount(); 149 149 } -
code/branches/core7/src/orxonox/Level.cc
r10576 r10578 49 49 RegisterObject(Level); 50 50 51 this->setLevel( StrongPtr<Level>(this, false));51 this->setLevel(WeakPtr<Level>(this)); // store a weak-pointer to itself (a strong-pointer would create a recursive dependency) 52 52 53 53 this->registerVariables(); … … 123 123 Gametype* rootgametype = orxonox_cast<Gametype*>(identifier->fabricate(this)); 124 124 125 rootgametype->setLevel( NULL); // avoid circular references126 this->setGametype( rootgametype);125 rootgametype->setLevel(StrongPtr<Level>(NULL)); // avoid circular references 126 this->setGametype(StrongPtr<Gametype>(rootgametype)); 127 127 rootgametype->init(); // call init() AFTER the gametype was set 128 128 -
code/branches/core7/src/orxonox/Scene.cc
r10571 r10578 62 62 RegisterObject(Scene); 63 63 64 this->setScene( StrongPtr<Scene>(this, false), this->getObjectID());64 this->setScene(WeakPtr<Scene>(this), this->getObjectID()); // store a weak-pointer to itself (a strong-pointer would create a recursive dependency) 65 65 66 66 this->bShadows_ = true; -
code/branches/core7/src/orxonox/gametypes/Gametype.cc
r10575 r10578 61 61 RegisterObject(Gametype); 62 62 63 this->setGametype( StrongPtr<Gametype>(this, false));63 this->setGametype(WeakPtr<Gametype>(this)); // store a weak-pointer to itself (a strong-pointer would create a recursive dependency) 64 64 65 65 this->gtinfo_ = new GametypeInfo(context); -
code/branches/core7/src/orxonox/infos/PlayerInfo.cc
r10576 r10578 98 98 { 99 99 Gametype* oldGametype = this->getGametype(); 100 this->setGametype( gametype);100 this->setGametype(StrongPtr<Gametype>(gametype)); 101 101 Gametype* newGametype = this->getGametype(); 102 102
Note: See TracChangeset
for help on using the changeset viewer.