OPeNDAP Hyrax Back End Server (BES)  Updated for version 3.8.3
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>

Inheritance diagram for agg_util::RCPtr< T >:
Inheritance graph
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 (T *pRef=0)
 
 RCPtr (const RCPtr &from)
 
T * refAndGet () const
 If not null, ref() the object and then return it. More...
 
 ~RCPtr ()
 

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 279 of file RCObject.h.

Constructor & Destructor Documentation

template<class T>
agg_util::RCPtr< T >::RCPtr ( T *  pRef = 0)
inline

Definition at line 282 of file RCObject.h.

template<class T>
agg_util::RCPtr< T >::RCPtr ( const RCPtr< T > &  from)
inline

Definition at line 288 of file RCObject.h.

template<class T>
agg_util::RCPtr< T >::~RCPtr ( )
inline

Definition at line 294 of file RCObject.h.

Member Function Documentation

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

Definition at line 320 of file RCObject.h.

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

Definition at line 328 of file RCObject.h.

template<class T>
RCPtr& agg_util::RCPtr< T >::operator= ( const RCPtr< T > &  rhs)
inline

Definition at line 304 of file RCObject.h.

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 352 of file RCObject.h.

Referenced by ncml_module::ScanElement::getDatasetList().


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