Logo ROOT  
Reference Guide
TGeoRCPtr< T > Class Template Reference

template<class T>
class TGeoRCPtr< T >

A reference counting-managed pointer for classes derived from TGeoExtension which can be used as C pointer.

Based on CodeProject implementation example

Example:

class MyExtension : public TGeoExtension {
public:
MyExtension() : TGeoExtension(), fRC(0) {printf("Created MyExtension\n");}
virtual ~MyExtension() {printf("Deleted MyExtension\n");}
virtual TGeoExtension *Grab() const {fRC++; return (TGeoExtension*)this;}
virtual void Release() const {assert(fRC > 0); fRC--; if (fRC ==0) delete this;}
void print() const {printf("MyExtension object %p\n", this);}
private:
mutable Int_t fRC; // Reference counter
ClassDef(MyExtension,1)
};
int Int_t
Definition: RtypesCore.h:41
#define ClassDef(name, id)
Definition: Rtypes.h:326
ABC for user objects attached to TGeoVolume or TGeoNode.
Definition: TGeoExtension.h:20

Usage:

// Module 1 creates an object
TGeoRCPtr<MyExtension> a2 = new MyExtension(); //fRC=1
// Module 2 grabs object
// Module 2 invokes a method
ptr2->Print();
(*ptr2).Print();
// Module 1 no longer needs object
a2 = 0; //RC=1
// Module 2 no longer needs object
ptr2 = 0; //object will be destroyed here
A reference counting-managed pointer for classes derived from TGeoExtension which can be used as C po...
Definition: TGeoRCPtr.h:63
static byte * ptr2
Definition: gifdecode.c:17

Note:

Event if one forgets to call ptr2 = 0, the object gets delete when the method using ptr2 gets out of scope.

Definition at line 62 of file TGeoRCPtr.h.

Public Member Functions

 TGeoRCPtr (const TGeoRCPtr &ptr)
 
 TGeoRCPtr (T *ptr=0)
 
 ~TGeoRCPtr ()
 
T * Get () const
 
 operator bool () const
 
 operator T* () const
 
T & operator* () const
 
T * operator-> () const
 
TGeoRCPtroperator= (const TGeoRCPtr &ptr)
 
TGeoRCPtroperator= (T *ptr)
 
bool operator== (const T *ptr)
 
bool operator== (const TGeoRCPtr &ptr)
 

Private Attributes

T * fPtr
 

#include <TGeoRCPtr.h>

Constructor & Destructor Documentation

◆ TGeoRCPtr() [1/2]

template<class T >
TGeoRCPtr< T >::TGeoRCPtr ( T *  ptr = 0)
inline

Definition at line 66 of file TGeoRCPtr.h.

◆ TGeoRCPtr() [2/2]

template<class T >
TGeoRCPtr< T >::TGeoRCPtr ( const TGeoRCPtr< T > &  ptr)
inline

Definition at line 73 of file TGeoRCPtr.h.

◆ ~TGeoRCPtr()

template<class T >
TGeoRCPtr< T >::~TGeoRCPtr ( )
inline

Definition at line 79 of file TGeoRCPtr.h.

Member Function Documentation

◆ Get()

template<class T >
T * TGeoRCPtr< T >::Get ( ) const
inline

Definition at line 100 of file TGeoRCPtr.h.

◆ operator bool()

template<class T >
TGeoRCPtr< T >::operator bool ( ) const
inline

Definition at line 110 of file TGeoRCPtr.h.

◆ operator T*()

template<class T >
TGeoRCPtr< T >::operator T* ( ) const
inline

Definition at line 109 of file TGeoRCPtr.h.

◆ operator*()

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

Definition at line 108 of file TGeoRCPtr.h.

◆ operator->()

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

Definition at line 107 of file TGeoRCPtr.h.

◆ operator=() [1/2]

template<class T >
TGeoRCPtr & TGeoRCPtr< T >::operator= ( const TGeoRCPtr< T > &  ptr)
inline

Definition at line 94 of file TGeoRCPtr.h.

◆ operator=() [2/2]

template<class T >
TGeoRCPtr & TGeoRCPtr< T >::operator= ( T *  ptr)
inline

Definition at line 85 of file TGeoRCPtr.h.

◆ operator==() [1/2]

template<class T >
bool TGeoRCPtr< T >::operator== ( const T *  ptr)
inline

Definition at line 112 of file TGeoRCPtr.h.

◆ operator==() [2/2]

template<class T >
bool TGeoRCPtr< T >::operator== ( const TGeoRCPtr< T > &  ptr)
inline

Definition at line 111 of file TGeoRCPtr.h.

Member Data Documentation

◆ fPtr

template<class T >
T* TGeoRCPtr< T >::fPtr
private

Definition at line 115 of file TGeoRCPtr.h.


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