cartobase  4.5.0
carto::SharedObject Class Reference

SharedObject allows to work with combined reference counting pointers and weak (Observer) pointers. More...

#include <cartobase/smart/sharedptr.h>

Inheritance diagram for carto::SharedObject:
Collaboration diagram for carto::SharedObject:

Public Member Functions

 SharedObject ()
 
 SharedObject (const SharedObject &x)
 
virtual ~SharedObject ()
 notifies observers More...
 
SharedObjectoperator= (const SharedObject &)
 
bool testDeletable ()
 tests if the shared object can be deleted (no strong pointers to it). More...
 
bool tryDelete ()
 tests if the shared object can be deleted. More...
 
- Public Member Functions inherited from carto::WeakObject
template<typename T >
void attachWeakPtr (weak_ptr< T > &) const
 
template<typename T >
void detachWeakPtr (weak_ptr< T > &) const
 
template<typename T >
void attachWeakPtr (weak_shared_ptr< T > &) const
 
template<typename T >
void detachWeakPtr (weak_shared_ptr< T > &) const
 
virtual ~WeakObject ()
 
- Public Member Functions inherited from carto::RCObject
 RCObject ()
 
 RCObject (const RCObject &)
 
RCObjectoperator= (const RCObject &)
 

Protected Member Functions

void disableRefCount ()
 called by destructors to avoid double deletion. More...
 
- Protected Member Functions inherited from carto::WeakObject
 WeakObject ()
 
 WeakObject (const WeakObject &)
 
WeakObjectoperator= (const WeakObject &)
 

Friends

template<typename T >
class weak_shared_ptr
 
template<typename T >
class shared_ptr
 
class rc_ptr_trick
 

Additional Inherited Members

- Public Types inherited from carto::RCObject
typedef int RefCounterType
 

Detailed Description

SharedObject allows to work with combined reference counting pointers and weak (Observer) pointers.

See also
weak_shared_ptr, rc_ptr, weak_ptr

Definition at line 47 of file sharedptr.h.

Constructor & Destructor Documentation

carto::SharedObject::SharedObject ( )
carto::SharedObject::SharedObject ( const SharedObject x)
virtual carto::SharedObject::~SharedObject ( )
virtual

notifies observers

Member Function Documentation

void carto::SharedObject::disableRefCount ( )
protected

called by destructors to avoid double deletion.

Sets the reference counter to -1, so any additional existing smart pointer will not delete the SharedObject another time.

SharedObject& carto::SharedObject::operator= ( const SharedObject )
inline

Definition at line 55 of file sharedptr.h.

bool carto::SharedObject::testDeletable ( )

tests if the shared object can be deleted (no strong pointers to it).

The test also returns false if no smart pointer at all points to the object (counters are 0), because it may mean the SharedObject has been allocated on the heap and must not be deleted by the C++ delete operator.

bool carto::SharedObject::tryDelete ( )

tests if the shared object can be deleted.

If possible, it is actually deleted (suicide is commited and the object is not valid any more after this call)

Friends And Related Function Documentation

friend class rc_ptr_trick
friend

Definition at line 80 of file sharedptr.h.

template<typename T >
friend class shared_ptr
friend

Definition at line 79 of file sharedptr.h.

template<typename T >
friend class weak_shared_ptr
friend

Definition at line 78 of file sharedptr.h.


The documentation for this class was generated from the following file: