INET Framework for OMNeT++/OMNEST
inet::IntrusivePtr< T > Class Template Reference

A smart pointer that uses intrusive reference counting. More...

#include <IntrusivePtr.h>

Public Member Functions

constexpr INET_ALWAYS_INLINE IntrusivePtr () noexcept
 
constexpr INET_ALWAYS_INLINE IntrusivePtr (std::nullptr_t)
 
INET_ALWAYS_INLINE IntrusivePtr (T *p)
 
template<class U >
INET_ALWAYS_INLINE IntrusivePtr (IntrusivePtr< U > const &ptr)
 
INET_ALWAYS_INLINE IntrusivePtr (IntrusivePtr const &ptr)
 
INET_ALWAYS_INLINE ~IntrusivePtr ()
 
template<class U >
INET_ALWAYS_INLINE IntrusivePtroperator= (IntrusivePtr< U > const &ptr)
 
INET_ALWAYS_INLINE IntrusivePtr (IntrusivePtr &&ptr) noexcept
 
INET_ALWAYS_INLINE IntrusivePtroperator= (IntrusivePtr &&ptr) noexcept
 
template<class U >
INET_ALWAYS_INLINE IntrusivePtr (IntrusivePtr< U > &&ptr)
 
template<class U >
INET_ALWAYS_INLINE IntrusivePtroperator= (IntrusivePtr< U > &&ptr) noexcept
 
INET_ALWAYS_INLINE IntrusivePtroperator= (IntrusivePtr const &ptr)
 
INET_ALWAYS_INLINE IntrusivePtroperator= (T *ptr)
 
INET_ALWAYS_INLINE void reset ()
 
INET_ALWAYS_INLINE void reset (T *ptr)
 
INET_ALWAYS_INLINE void reset (T *ptr, bool add_ref)
 
INET_ALWAYS_INLINE Tget () const noexcept
 
INET_ALWAYS_INLINE Tdetach () noexcept
 
INET_ALWAYS_INLINE Toperator* () const noexcept
 
INET_ALWAYS_INLINE Toperator-> () const noexcept
 
INET_ALWAYS_INLINE operator bool () const noexcept
 
INET_ALWAYS_INLINE void swap (IntrusivePtr &ptr) noexcept
 
INET_ALWAYS_INLINE unsigned int use_count () const noexcept
 

Private Attributes

Tp
 

Friends

template<class U >
class IntrusivePtr
 

Detailed Description

template<class T>
class inet::IntrusivePtr< T >

A smart pointer that uses intrusive reference counting.

Relies on unqualified calls to void intrusivePtrCounterIncrement(T *p); void intrusivePtrCounterDecrement(T *p); The object is responsible for destroying itself.

Constructor & Destructor Documentation

◆ IntrusivePtr() [1/7]

template<class T >
constexpr INET_ALWAYS_INLINE inet::IntrusivePtr< T >::IntrusivePtr ( )
inlineconstexprnoexcept
33 : p(nullptr) {}

◆ IntrusivePtr() [2/7]

template<class T >
constexpr INET_ALWAYS_INLINE inet::IntrusivePtr< T >::IntrusivePtr ( std::nullptr_t  )
inlineconstexpr
35 : p(nullptr) {}

◆ IntrusivePtr() [3/7]

template<class T >
INET_ALWAYS_INLINE inet::IntrusivePtr< T >::IntrusivePtr ( T p)
inlineexplicit
37  : p(p) {
38  if (p != 0) intrusivePtrCounterIncrement(p);
39  }

◆ IntrusivePtr() [4/7]

template<class T >
template<class U >
INET_ALWAYS_INLINE inet::IntrusivePtr< T >::IntrusivePtr ( IntrusivePtr< U > const &  ptr)
inline
42  : p(ptr.get()) {
43  if (p != 0) intrusivePtrCounterIncrement(p);
44  }

◆ IntrusivePtr() [5/7]

template<class T >
INET_ALWAYS_INLINE inet::IntrusivePtr< T >::IntrusivePtr ( IntrusivePtr< T > const &  ptr)
inline
46  : p(ptr.p) {
47  if (p != 0) intrusivePtrCounterIncrement(p);
48  }

◆ ~IntrusivePtr()

template<class T >
INET_ALWAYS_INLINE inet::IntrusivePtr< T >::~IntrusivePtr ( )
inline
50  {
51  if (p != 0) intrusivePtrCounterDecrement(p);
52  }

◆ IntrusivePtr() [6/7]

template<class T >
INET_ALWAYS_INLINE inet::IntrusivePtr< T >::IntrusivePtr ( IntrusivePtr< T > &&  ptr)
inlinenoexcept
60  : p(ptr.p) {
61  ptr.p = 0;
62  }

◆ IntrusivePtr() [7/7]

template<class T >
template<class U >
INET_ALWAYS_INLINE inet::IntrusivePtr< T >::IntrusivePtr ( IntrusivePtr< U > &&  ptr)
inline
72  : p(ptr.p) {
73  ptr.p = 0;
74  }

Member Function Documentation

◆ detach()

template<class T >
INET_ALWAYS_INLINE T* inet::IntrusivePtr< T >::detach ( )
inlinenoexcept
106  {
107  T *ret = p;
108  p = 0;
109  return ret;
110  }

◆ get()

template<class T >
INET_ALWAYS_INLINE T* inet::IntrusivePtr< T >::get ( ) const
inlinenoexcept

◆ operator bool()

template<class T >
INET_ALWAYS_INLINE inet::IntrusivePtr< T >::operator bool ( ) const
inlineexplicitnoexcept
116 { return p != 0; }

◆ operator*()

template<class T >
INET_ALWAYS_INLINE T& inet::IntrusivePtr< T >::operator* ( ) const
inlinenoexcept
112 { return *p; }

◆ operator->()

template<class T >
INET_ALWAYS_INLINE T* inet::IntrusivePtr< T >::operator-> ( ) const
inlinenoexcept
114 { return p; }

◆ operator=() [1/5]

template<class T >
INET_ALWAYS_INLINE IntrusivePtr& inet::IntrusivePtr< T >::operator= ( IntrusivePtr< T > &&  ptr)
inlinenoexcept
64  {
65  IntrusivePtr(static_cast<IntrusivePtr &&>(ptr)).swap(*this);
66  return *this;
67  }

◆ operator=() [2/5]

template<class T >
INET_ALWAYS_INLINE IntrusivePtr& inet::IntrusivePtr< T >::operator= ( IntrusivePtr< T > const &  ptr)
inline
82  {
83  IntrusivePtr(ptr).swap(*this);
84  return *this;
85  }

◆ operator=() [3/5]

template<class T >
template<class U >
INET_ALWAYS_INLINE IntrusivePtr& inet::IntrusivePtr< T >::operator= ( IntrusivePtr< U > &&  ptr)
inlinenoexcept
77  {
78  IntrusivePtr(static_cast<IntrusivePtr<U> &&>(ptr)).swap(*this);
79  return *this;
80  }

◆ operator=() [4/5]

template<class T >
template<class U >
INET_ALWAYS_INLINE IntrusivePtr& inet::IntrusivePtr< T >::operator= ( IntrusivePtr< U > const &  ptr)
inline
55  {
56  IntrusivePtr(ptr).swap(*this);
57  return *this;
58  }

◆ operator=() [5/5]

template<class T >
INET_ALWAYS_INLINE IntrusivePtr& inet::IntrusivePtr< T >::operator= ( T ptr)
inline
87  {
88  IntrusivePtr(ptr).swap(*this);
89  return *this;
90  }

◆ reset() [1/3]

template<class T >
INET_ALWAYS_INLINE void inet::IntrusivePtr< T >::reset ( )
inline
92  {
93  IntrusivePtr().swap(*this);
94  }

◆ reset() [2/3]

template<class T >
INET_ALWAYS_INLINE void inet::IntrusivePtr< T >::reset ( T ptr)
inline
96  {
97  IntrusivePtr(ptr).swap(*this);
98  }

◆ reset() [3/3]

template<class T >
INET_ALWAYS_INLINE void inet::IntrusivePtr< T >::reset ( T ptr,
bool  add_ref 
)
inline
100  {
101  IntrusivePtr(ptr, add_ref).swap(*this);
102  }

◆ swap()

template<class T >
INET_ALWAYS_INLINE void inet::IntrusivePtr< T >::swap ( IntrusivePtr< T > &  ptr)
inlinenoexcept
118  {
119  T *tmp = p;
120  p = ptr.p;
121  ptr.p = tmp;
122  }

◆ use_count()

template<class T >
INET_ALWAYS_INLINE unsigned int inet::IntrusivePtr< T >::use_count ( ) const
inlinenoexcept
124 { return p->use_count(); }

Friends And Related Function Documentation

◆ IntrusivePtr

template<class T >
template<class U >
friend class IntrusivePtr
friend

Member Data Documentation

◆ p


The documentation for this class was generated from the following file:
inet::units::units::T
compose< Wb, pow< m, -2 > > T
Definition: Units.h:951
inet::intrusivePtrCounterIncrement
INET_ALWAYS_INLINE void intrusivePtrCounterIncrement(const IntrusivePtrCounter< T > *p) noexcept
Definition: IntrusivePtr.h:262
inet::IntrusivePtr::IntrusivePtr
friend class IntrusivePtr
Definition: IntrusivePtr.h:69
inet::IntrusivePtr::p
T * p
Definition: IntrusivePtr.h:30
inet::intrusivePtrCounterDecrement
INET_ALWAYS_INLINE void intrusivePtrCounterDecrement(const IntrusivePtrCounter< T > *p) noexcept
Definition: IntrusivePtr.h:268