gem5  v20.1.0.0
Public Types | 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 Types

using PtrType = T *
 

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 (RefCountingPtr &&r)
 Move-constructor. More...
 
template<bool B = TisConst>
 RefCountingPtr (const NonConstT &r)
 
 ~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...
 
template<bool B = TisConst>
 operator RefCountingPtr< typename std::enable_if<!B, ConstT >::type > ()
 
const RefCountingPtroperator= (T *p)
 Assign a new value to the pointer. More...
 
const RefCountingPtroperator= (const RefCountingPtr &r)
 Copy the pointer from another RefCountingPtr. More...
 
const RefCountingPtroperator= (RefCountingPtr &&r)
 Move-assign 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...
 
using ConstT = typename std::conditional< TisConst, RefCountingPtr< T >, RefCountingPtr< typename std::add_const< T >::type > >::type
 
using NonConstT = typename std::conditional< TisConst, RefCountingPtr< typename std::remove_const< T >::type >, RefCountingPtr< T > >::type
 
static constexpr auto TisConst = std::is_const<T>::value
 Convenience aliases for const/non-const versions of T w/ friendship. More...
 
friend ConstT
 
friend NonConstT
 

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 118 of file refcnt.hh.

Member Typedef Documentation

◆ ConstT

template<class T >
using RefCountingPtr< T >::ConstT = typename std::conditional<TisConst, RefCountingPtr<T>, RefCountingPtr<typename std::add_const<T>::type> >::type
protected

Definition at line 129 of file refcnt.hh.

◆ NonConstT

template<class T >
using RefCountingPtr< T >::NonConstT = typename std::conditional<TisConst, RefCountingPtr<typename std::remove_const<T>::type>, RefCountingPtr<T> >::type
protected

Definition at line 133 of file refcnt.hh.

◆ PtrType

template<class T >
using RefCountingPtr< T >::PtrType = T*

Definition at line 121 of file refcnt.hh.

Constructor & Destructor Documentation

◆ RefCountingPtr() [1/5]

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

Create an empty reference counting pointer.

Definition at line 183 of file refcnt.hh.

◆ RefCountingPtr() [2/5]

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 187 of file refcnt.hh.

◆ RefCountingPtr() [3/5]

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 191 of file refcnt.hh.

◆ RefCountingPtr() [4/5]

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

Move-constructor.

Does not add a reference.

Definition at line 196 of file refcnt.hh.

◆ RefCountingPtr() [5/5]

template<class T >
template<bool B = TisConst>
RefCountingPtr< T >::RefCountingPtr ( const NonConstT r)
inline

Definition at line 203 of file refcnt.hh.

◆ ~RefCountingPtr()

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

Destroy the pointer and any reference it may hold.

Definition at line 206 of file refcnt.hh.

Member Function Documentation

◆ copy()

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 147 of file refcnt.hh.

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

◆ del()

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 160 of file refcnt.hh.

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

◆ get()

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

◆ operator bool()

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

Check if the pointer is non-empty.

Definition at line 250 of file refcnt.hh.

◆ operator RefCountingPtr< typename std::enable_if<!B, ConstT >::type >()

template<class T >
template<bool B = TisConst>
RefCountingPtr< T >::operator RefCountingPtr< typename std::enable_if<!B, ConstT >::type > ( )
inline

Definition at line 222 of file refcnt.hh.

◆ operator!()

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

Check if the pointer is empty.

Definition at line 247 of file refcnt.hh.

◆ operator*()

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

Dereference the pointer.

Definition at line 216 of file refcnt.hh.

◆ operator->()

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

Access a member variable.

Definition at line 213 of file refcnt.hh.

◆ operator=() [1/3]

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

Copy the pointer from another RefCountingPtr.

Definition at line 231 of file refcnt.hh.

◆ operator=() [2/3]

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

Move-assign the pointer from another RefCountingPtr.

Definition at line 235 of file refcnt.hh.

◆ operator=() [3/3]

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

Assign a new value to the pointer.

Definition at line 228 of file refcnt.hh.

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

◆ set()

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

Drop the old reference and change it to something new.

Definition at line 170 of file refcnt.hh.

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

Member Data Documentation

◆ ConstT

template<class T >
friend RefCountingPtr< T >::ConstT
protected

Definition at line 130 of file refcnt.hh.

◆ data

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

◆ NonConstT

template<class T >
friend RefCountingPtr< T >::NonConstT
protected

Definition at line 134 of file refcnt.hh.

◆ TisConst

template<class T >
constexpr auto RefCountingPtr< T >::TisConst = std::is_const<T>::value
staticconstexprprotected

Convenience aliases for const/non-const versions of T w/ friendship.

Definition at line 126 of file refcnt.hh.


The documentation for this class was generated from the following file:
RefCountingPtr
If you want a reference counting pointer to a mutable object, create it like this:
Definition: refcnt.hh:118

Generated on Wed Sep 30 2020 14:02:30 for gem5 by doxygen 1.8.17