gem5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
RefCountingPtr< T > Class Template Reference

If you want a reference counting pointer to a mutable object, create it like this: More...

#include <refcnt.hh>

Public Member Functions

 RefCountingPtr ()
 Create an empty reference counting pointer. More...
 
 RefCountingPtr (T *data)
 Create a new reference counting pointer to some object (probably something newly created). More...
 
 RefCountingPtr (const RefCountingPtr &r)
 Create a new reference counting pointer by copying another one. More...
 
 ~RefCountingPtr ()
 Destroy the pointer and any reference it may hold. More...
 
T * operator-> () const
 Access a member variable. More...
 
T & operator* () const
 Dereference the pointer. More...
 
T * get () const
 Directly access the pointer itself without taking a reference. More...
 
const RefCountingPtroperator= (T *p)
 Assign a new value to the pointer. More...
 
const RefCountingPtroperator= (const RefCountingPtr &r)
 Copy the pointer from another RefCountingPtr. More...
 
bool operator! () const
 Check if the pointer is empty. More...
 
 operator bool () const
 Check if the pointer is non-empty. More...
 

Protected Member Functions

void copy (T *d)
 Copy a new pointer value and increment the reference count if it is a valid pointer. More...
 
void del ()
 Delete the reference to any existing object if it is non NULL. More...
 
void set (T *d)
 Drop the old reference and change it to something new. More...
 

Protected Attributes

T * data
 The stored pointer. More...
 

Detailed Description

template<class T>
class RefCountingPtr< T >

If you want a reference counting pointer to a mutable object, create it like this:

typedef RefCountingPtr<Foo> FooPtr;
Attention
Do not use "const FooPtr" To create a reference counting pointer to a const object, use this:
typedef RefCountingPtr<const Foo> ConstFooPtr;

These two usages are analogous to iterator and const_iterator in the stl.

Definition at line 106 of file refcnt.hh.

Constructor & Destructor Documentation

template<class T>
RefCountingPtr< T >::RefCountingPtr ( )
inline

Create an empty reference counting pointer.

Definition at line 156 of file refcnt.hh.

template<class T>
RefCountingPtr< T >::RefCountingPtr ( T *  data)
inline

Create a new reference counting pointer to some object (probably something newly created).

Adds a reference.

Definition at line 160 of file refcnt.hh.

template<class T>
RefCountingPtr< T >::RefCountingPtr ( const RefCountingPtr< T > &  r)
inline

Create a new reference counting pointer by copying another one.

Adds a reference.

Definition at line 164 of file refcnt.hh.

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

Destroy the pointer and any reference it may hold.

Definition at line 167 of file refcnt.hh.

Member Function Documentation

template<class T>
void RefCountingPtr< T >::copy ( T *  d)
inlineprotected

Copy a new pointer value and increment the reference count if it is a valid pointer.

Note, this does not delete the reference any existing object.

Parameters
dPointer to store.

Definition at line 120 of file refcnt.hh.

Referenced by RefCountingPtr< MinorDynInst >::RefCountingPtr(), and RefCountingPtr< MinorDynInst >::set().

template<class T>
void RefCountingPtr< T >::del ( )
inlineprotected

Delete the reference to any existing object if it is non NULL.

Attention
this doesn't clear the pointer value, so a double decref could happen if not careful.

Definition at line 133 of file refcnt.hh.

Referenced by RefCountingPtr< MinorDynInst >::set(), and RefCountingPtr< MinorDynInst >::~RefCountingPtr().

template<class T>
T* RefCountingPtr< T >::get ( ) const
inline
template<class T>
RefCountingPtr< T >::operator bool ( ) const
inline

Check if the pointer is non-empty.

Definition at line 193 of file refcnt.hh.

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

Check if the pointer is empty.

Definition at line 190 of file refcnt.hh.

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

Dereference the pointer.

Definition at line 177 of file refcnt.hh.

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

Access a member variable.

Definition at line 174 of file refcnt.hh.

template<class T>
const RefCountingPtr& RefCountingPtr< T >::operator= ( T *  p)
inline

Assign a new value to the pointer.

Definition at line 183 of file refcnt.hh.

Referenced by RefCountingPtr< MinorDynInst >::operator=().

template<class T>
const RefCountingPtr& RefCountingPtr< T >::operator= ( const RefCountingPtr< T > &  r)
inline

Copy the pointer from another RefCountingPtr.

Definition at line 186 of file refcnt.hh.

template<class T>
void RefCountingPtr< T >::set ( T *  d)
inlineprotected

Drop the old reference and change it to something new.

Definition at line 143 of file refcnt.hh.

Referenced by RefCountingPtr< MinorDynInst >::operator=().

Member Data Documentation

template<class T>
T* RefCountingPtr< T >::data
protected

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

Generated on Fri Jun 9 2017 13:04:17 for gem5 by doxygen 1.8.6