bes  Updated for version 3.20.6
agg_util::RCPtr< T > Class Template Reference

A reference to an RCObject which automatically ref() and deref() on creation and destruction. More...

#include <RCObject.h>

Collaboration diagram for agg_util::RCPtr< T >:
Collaboration graph

Public Member Functions

T * get () const
 
T & operator* () const
 
T * operator-> () const
 
RCPtroperator= (const RCPtr &rhs)
 
 RCPtr (const RCPtr &from)
 
 RCPtr (T *pRef=0)
 
T * refAndGet () const
 

Detailed Description

template<class T>
class agg_util::RCPtr< T >

A reference to an RCObject which automatically ref() and deref() on creation and destruction.

Use this for temporary references to an RCObject* instead of std::auto_ptr to avoid leaks or double deletion. It is templated to allow RCObject subclass specific pointers.

For example,

RCPtr<RCObject> obj = RCPtr<RCObject>(new RCObject()); // count is now 1. // make a call to add to container that might throw exception. // we assume the container will up the ref() itself on a successful addition. addToContainer(obj.get()); // if previous line exceptions, ~RCPtr will unref() it back to 0, causing it to delete. // if we get here, the object is safely in the container and has been ref() to 2, // so ~RCPtr correctly drops it back to 1.

Note
We don't have a class for weak references, so make sure to not generate reference loops with back pointers (circular ref graphs) Back pointers should be raw pointers (until/unless we add weak references) and ref() should only be called when it's a strong reference! (ie one that shares ownership).

Definition at line 284 of file RCObject.h.

Member Function Documentation

◆ refAndGet()

template<class T >
T* agg_util::RCPtr< T >::refAndGet ( ) const
inline

If not null, ref() the object and then return it.

Useful for adding a reference to a container, e.g.:

RCPtr<T> myObj; vector<T> myVecOfObj; myVecOfObj.push_back(myObj.refAndGet());

Returns

Definition at line 353 of file RCObject.h.


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