gem5  v21.1.0.2
Public Types | Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
gem5::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_t<!B, ConstT >> ()
 
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_t< TisConst, RefCountingPtr< T >, RefCountingPtr< typename std::add_const< T >::type > >
 
using NonConstT = typename std::conditional_t< TisConst, RefCountingPtr< typename std::remove_const< T >::type >, RefCountingPtr< T > >
 
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 gem5::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 126 of file refcnt.hh.

Member Typedef Documentation

◆ ConstT

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

Definition at line 137 of file refcnt.hh.

◆ NonConstT

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

Definition at line 141 of file refcnt.hh.

◆ PtrType

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

Definition at line 129 of file refcnt.hh.

Constructor & Destructor Documentation

◆ RefCountingPtr() [1/5]

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

Create an empty reference counting pointer.

Definition at line 191 of file refcnt.hh.

◆ RefCountingPtr() [2/5]

template<class T >
gem5::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 195 of file refcnt.hh.

◆ RefCountingPtr() [3/5]

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

Create a new reference counting pointer by copying another one.

Adds a reference.

Definition at line 199 of file refcnt.hh.

◆ RefCountingPtr() [4/5]

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

Move-constructor.

Does not add a reference.

Definition at line 204 of file refcnt.hh.

◆ RefCountingPtr() [5/5]

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

Definition at line 211 of file refcnt.hh.

◆ ~RefCountingPtr()

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

Destroy the pointer and any reference it may hold.

Definition at line 214 of file refcnt.hh.

Member Function Documentation

◆ copy()

template<class T >
void gem5::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 155 of file refcnt.hh.

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

◆ del()

template<class T >
void gem5::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 168 of file refcnt.hh.

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

◆ get()

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

◆ operator bool()

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

Check if the pointer is non-empty.

Definition at line 262 of file refcnt.hh.

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

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

Definition at line 230 of file refcnt.hh.

◆ operator!()

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

Check if the pointer is empty.

Definition at line 259 of file refcnt.hh.

◆ operator*()

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

Dereference the pointer.

Definition at line 224 of file refcnt.hh.

◆ operator->()

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

Access a member variable.

Definition at line 221 of file refcnt.hh.

◆ operator=() [1/3]

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

Copy the pointer from another RefCountingPtr.

Definition at line 240 of file refcnt.hh.

◆ operator=() [2/3]

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

Move-assign the pointer from another RefCountingPtr.

Definition at line 247 of file refcnt.hh.

◆ operator=() [3/3]

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

Assign a new value to the pointer.

Definition at line 236 of file refcnt.hh.

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

◆ set()

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

Drop the old reference and change it to something new.

Definition at line 178 of file refcnt.hh.

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

Member Data Documentation

◆ ConstT

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

Definition at line 138 of file refcnt.hh.

◆ data

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

◆ NonConstT

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

Definition at line 142 of file refcnt.hh.

◆ TisConst

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

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

Definition at line 134 of file refcnt.hh.


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

Generated on Tue Sep 21 2021 12:28:00 for gem5 by doxygen 1.8.17