gem5 v24.0.0.0
Loading...
Searching...
No Matches
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.
 
 RefCountingPtr (T *data)
 Create a new reference counting pointer to some object (probably something newly created).
 
 RefCountingPtr (const RefCountingPtr &r)
 Create a new reference counting pointer by copying another one.
 
 RefCountingPtr (RefCountingPtr &&r)
 Move-constructor.
 
template<bool B = TisConst>
 RefCountingPtr (const NonConstT &r)
 
 ~RefCountingPtr ()
 Destroy the pointer and any reference it may hold.
 
T * operator-> () const
 Access a member variable.
 
T & operator* () const
 Dereference the pointer.
 
T * get () const
 Directly access the pointer itself without taking a reference.
 
template<bool B = TisConst>
 operator RefCountingPtr< typename std::enable_if_t<!B, ConstT > > ()
 
const RefCountingPtroperator= (T *p)
 Assign a new value to the pointer.
 
const RefCountingPtroperator= (const RefCountingPtr &r)
 Copy the pointer from another RefCountingPtr.
 
const RefCountingPtroperator= (RefCountingPtr &&r)
 Move-assign the pointer from another RefCountingPtr.
 
bool operator! () const
 Check if the pointer is empty.
 
 operator bool () const
 Check if the pointer is non-empty.
 

Protected Member Functions

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

Protected Attributes

T * data
 The stored pointer.
 
using ConstT
 
using NonConstT
 
static constexpr auto TisConst = std::is_const_v<T>
 Convenience aliases for const/non-const versions of T w/ friendship.
 
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;
If you want a reference counting pointer to a mutable object, create it like this:
Definition refcnt.hh:127
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
protected
Initial value:
typename std::conditional_t<TisConst,
RefCountingPtr<typename std::add_const<T>::type>>
RefCountingPtr()
Create an empty reference counting pointer.
Definition refcnt.hh:191
static constexpr auto TisConst
Convenience aliases for const/non-const versions of T w/ friendship.
Definition refcnt.hh:134

Definition at line 135 of file refcnt.hh.

◆ NonConstT

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

Definition at line 139 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.

Referenced by gem5::RefCountingPtr< T >::operator RefCountingPtr< typename std::enable_if_t<!B, ConstT > >().

◆ 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.

References gem5::RefCountingPtr< T >::copy(), and gem5::RefCountingPtr< T >::data.

◆ 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.

References gem5::RefCountingPtr< T >::copy(), and gem5::MipsISA::r.

◆ 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.

References gem5::RefCountingPtr< T >::data, and gem5::MipsISA::r.

◆ 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.

References gem5::RefCountingPtr< T >::copy(), and gem5::MipsISA::r.

◆ ~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.

References gem5::RefCountingPtr< T >::del().

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.

References gem5::ArmISA::d, and gem5::RefCountingPtr< T >::data.

Referenced by gem5::RefCountingPtr< T >::RefCountingPtr(), gem5::RefCountingPtr< T >::RefCountingPtr(), gem5::RefCountingPtr< T >::RefCountingPtr(), and gem5::RefCountingPtr< T >::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.

References gem5::RefCountingPtr< T >::data.

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

◆ get()

◆ 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.

References gem5::RefCountingPtr< T >::data.

◆ 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.

References gem5::RefCountingPtr< T >::RefCountingPtr().

◆ 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.

References gem5::RefCountingPtr< T >::data.

◆ operator*()

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

Dereference the pointer.

Definition at line 224 of file refcnt.hh.

References gem5::RefCountingPtr< T >::data.

◆ operator->()

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

Access a member variable.

Definition at line 221 of file refcnt.hh.

References gem5::RefCountingPtr< T >::data.

◆ 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.

References gem5::RefCountingPtr< T >::operator=(), and gem5::MipsISA::r.

◆ 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.

References gem5::RefCountingPtr< T >::data, gem5::RefCountingPtr< T >::del(), and gem5::MipsISA::r.

◆ 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.

References gem5::MipsISA::p, and gem5::ArmISA::set.

Referenced by gem5::RefCountingPtr< T >::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.

References gem5::RefCountingPtr< T >::copy(), gem5::ArmISA::d, gem5::RefCountingPtr< T >::data, and gem5::RefCountingPtr< T >::del().

Member Data Documentation

◆ ConstT

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

Definition at line 138 of file refcnt.hh.

◆ data

◆ NonConstT

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

Definition at line 142 of file refcnt.hh.

◆ TisConst

template<class T >
auto gem5::RefCountingPtr< T >::TisConst = std::is_const_v<T>
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 Jun 18 2024 16:24:13 for gem5 by doxygen 1.11.0