|
OpenTop 1.3 | |||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | Cross-Platform C++ | ||||
SUMMARY: CONSTRUCTOR | METHOD | DETAIL: CONSTRUCTOR | METHOD |
#include "ot/base/RefPtrMember.h"
Template class designed to be used as a member variable within a class that needs to store object references, possibly even a reference to itself.
The RefPtrMember class is very similar in design and operation to RefPtr<T>, with the exception that it will not increment or decrement the reference count of an object that is referring to itself.
Use RefPtrMember in preference to RefPtr when a class contains an object reference as a member variable, and the possibility exists for that member to be set equal to the containing object.
In the following example, the CoffeeFilter class uses a FilterEventHandler class, presumably to report interesting events that happen to the coffee filter. The derived class MyFilter wishes to implement a customized filter and deal with its events. To achieve this, it needs to call setEventHandler(this), which would create a cyclic reference if the reference count of the FilterEventHandler was incremented naively.
class FilterEventHandler; class CoffeeFilter : public ManagedObject { public: void setEventHandler(FilterEventHandler* pHandler); private: RefPtrMember<FilterEventHandler> m_rpEventHandler; }; class MyFilter : public CoffeeFilter, public FilterEventHandler { public: MyFilter() { setEventHandler(this); } };
Constructor/Destructor Summary | |
RefPtrMember(ManagedObject* pParent) Standard constructor, requires a pointer to a ManagedObject which is the parent object containing this RefPtrMember as a member. | |
RefPtrMember(ManagedObject* pParent, T* ptr) Constructs a RefPtrMember with a pointer to T. | |
RefPtrMember(ManagedObject* pParent, const RefPtrMember< T >& rhs) Constructs a RefPtrMember with another RefPtrMember. | |
RefPtrMember(ManagedObject* pParent, const RefPtr< T >& rhs) Constructs a RefPtrMember from a RefPtr for the same type. | |
~RefPtrMember() Destructor. |
Method Summary | |
T* |
get() const Returns the contained object pointer. |
bool |
isNull() const Tests if the contained object pointer is null. |
T& |
operator *() const A dereferencing operator. |
|
operator T *() const Conversion operator. |
bool |
operator!=(const RefPtrMember< T >& rhs) const Inequality operator. |
bool |
operator!=(const T* rhs) const Inequality operator. |
bool |
operator<(const RefPtrMember< T >& rhs) const Less than operator. |
RefPtrMember< T >& |
operator=(const RefPtrMember< T >& rhs) Assigns one RefPtrMember to another. |
RefPtrMember< T >& |
operator=(const RefPtr< T >& rhs) Assigns a RefPtr to a RefPtrMember. |
RefPtrMember< T >& |
operator=(T* ptr) Assigns a pointer. |
bool |
operator==(const RefPtrMember< T >& rhs) const Equality operator. |
bool |
operator==(const T* rhs) const Equality operator. |
T* |
operator->() const A dereferencing operator. |
void |
release() Decrements the reference count of the contained object pointer if it is not null and is not the same as the parent object. |
Constructor/Destructor Detail |
RefPtrMember(ManagedObject* pParent)
pParent
- RefPtrMember(ManagedObject* pParent, T* ptr)
pParent
- ptr
- RefPtrMember(ManagedObject* pParent, const RefPtrMember< T >& rhs)
pParent
- rhs
- RefPtrMember(ManagedObject* pParent, const RefPtr< T >& rhs)
pParent
- rhs
- ~RefPtrMember()
Method Detail |
T* get() const
bool isNull() const
T& operator *() const
operator T *() const
bool operator!=(const RefPtrMember< T >& rhs) const
rhs
- bool operator!=(const T* rhs) const
rhs
- bool operator<(const RefPtrMember< T >& rhs) const
rhs
- RefPtrMember< T >& operator=(const RefPtrMember< T >& rhs)
rhs
- RefPtrMember< T >& operator=(const RefPtr< T >& rhs)
rhs
- RefPtrMember< T >& operator=(T* ptr)
ptr
- bool operator==(const RefPtrMember< T >& rhs) const
rhs
- bool operator==(const T* rhs) const
rhs
- T* operator->() const
void release()
|
OpenTop 1.3 | |||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | Cross-Platform C++ | ||||
SUMMARY: CONSTRUCTOR | METHOD | DETAIL: CONSTRUCTOR | METHOD |