cartobase  5.0.5
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 &)
 
virtual ~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

◆ SharedObject() [1/2]

carto::SharedObject::SharedObject ( )

◆ SharedObject() [2/2]

carto::SharedObject::SharedObject ( const SharedObject x)

◆ ~SharedObject()

virtual carto::SharedObject::~SharedObject ( )
virtual

notifies observers

Member Function Documentation

◆ disableRefCount()

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.

Referenced by operator=().

◆ operator=()

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

◆ testDeletable()

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.

Referenced by operator=().

◆ tryDelete()

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)

Referenced by operator=().

Friends And Related Function Documentation

◆ rc_ptr_trick

friend class rc_ptr_trick
friend

Definition at line 80 of file sharedptr.h.

◆ shared_ptr

template<typename T >
friend class shared_ptr
friend

Definition at line 79 of file sharedptr.h.

◆ weak_shared_ptr

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: