98 class WeakPtr :
public DestructionListener
154 inline T*
get()
const 166 inline operator T*()
const 186 inline explicit operator bool()
const 195 other.unregisterAsDestructionListener(other.base_);
200 other.pointer_ = temp;
204 this->
base_ = other.base_;
209 other.registerAsDestructionListener(other.base_);
234 this->
base_ =
nullptr;
253 template <
class T,
class U>
256 return static_cast<T*
>(p.get());
260 template <
class T,
class U>
263 return const_cast<T*
>(p.get());
267 template <
class T,
class U>
WeakPtr & operator=(WeakPtr other)
Assigns the wrapped pointer of another WeakPtr.
Definition: WeakPtr.h:139
std::shared_ptr< Functor > FunctorPtr
Definition: FunctorPtr.h:57
WeakPtr(const WeakPtr &other)
Copy-constructor.
Definition: WeakPtr.h:113
virtual void objectDeleted() override
Will be called by Destroyable::~Destroyable() if the stored object is deleted. Resets the wrapped poi...
Definition: WeakPtr.h:232
Definition of orxonox::Functor and its specialized subclasses, as well as the createFunctor() functio...
StrongPtr< T > static_pointer_cast(const StrongPtr< U > &p)
Uses a static_cast to cast a pointer of type U* to a pointer of type T* and returns it in a new Stron...
Definition: StrongPtr.h:291
WeakPtr(T *pointer)
Constructor: Initializes the weak pointer with a pointer to an object.
Definition: WeakPtr.h:107
Shared library macros, enums, constants and forward declarations for the core library ...
void unregisterAsDestructionListener(Destroyable *object)
Definition: Destroyable.h:106
void registerAsDestructionListener(Destroyable *object)
Definition: Destroyable.h:104
virtual ~WeakPtr()
Destructor.
Definition: WeakPtr.h:126
FunctorPtr callback_
This callback will be executed if the stored object is deleted.
Definition: WeakPtr.h:242
WeakPtr wraps a pointer to an object, which becomes nullptr if the object is deleted.
Definition: CorePrereqs.h:236
Destroyable * getBase() const
Returns the wrapped pointer as Destroyable*.
Definition: WeakPtr.h:160
T * get() const
Returns the wrapped pointer as T*.
Definition: WeakPtr.h:154
void reset()
Resets the weak pointer (equivalent to assigning a nullptr).
Definition: WeakPtr.h:213
void swap(WeakPtr &other)
Swaps the contents of two weak pointers.
Definition: WeakPtr.h:192
Die Wagnis Klasse hat die folgenden Aufgaben:
Definition: ApplicationPaths.cc:66
T * pointer_
The wrapped pointer to an object of type T.
Definition: WeakPtr.h:240
const FunctorPtr & getCallback() const
Returns the registered callback.
Definition: WeakPtr.h:225
Declaration of Destroyable, the base class of all objects which can be used with StrongPtr and WeakPt...
ORX_FORCEINLINE T orxonox_cast(U *source)
Casts on object of type Identifiable to any derived type that is registered in the class hierarchy...
Definition: Identifier.h:485
Definition: InputPrereqs.h:78
StrongPtr< T > dynamic_pointer_cast(const StrongPtr< U > &p)
Uses a dynamic_cast to cast a pointer of type U* to a pointer of type T* and returns it in a new Stro...
Definition: StrongPtr.h:305
void setCallback(const FunctorPtr &callback)
Registers a callback that will be executed if the stored object is destroyed.
Definition: WeakPtr.h:219
Classes must inherit from this class if they should be used with StrongPtr or WeakPtr.
Definition: Destroyable.h:47
WeakPtr & operator=(const WeakPtr< O > &other)
Assigns the wrapped pointer of a WeakPtr of another class.
Definition: WeakPtr.h:147
T & operator*() const
Overloaded operator, returns a reference to the stored object.
Definition: WeakPtr.h:179
Destroyable * base_
The wrapped pointer, casted up to Destroyable (this is needed because with just a T* pointer...
Definition: WeakPtr.h:241
WeakPtr(const WeakPtr< O > &other)
Copy-constructor for weak pointers to objects of another class.
Definition: WeakPtr.h:120
WeakPtr()
Constructor: Initializes the weak pointer with a null pointer.
Definition: WeakPtr.h:102
StrongPtr< T > const_pointer_cast(const StrongPtr< U > &p)
Uses a const_cast to cast a pointer of type U* to a pointer of type T* and returns it in a new Strong...
Definition: StrongPtr.h:298
T * operator->() const
Overloaded operator, returns a pointer to the stored object.
Definition: WeakPtr.h:172
WeakPtr & operator=(T *pointer)
Assigns a new pointer.
Definition: WeakPtr.h:132