xgboost
Classes | Public Types | Public Member Functions | Protected Attributes | List of all members
xgboost::IntrusivePtr< T > Class Template Reference

Implementation of Intrusive Pointer. A smart pointer that points to an object with an embedded reference counter. The underlying object must implement a friend function IntrusivePtrRefCount() that returns the ref counter (of type IntrusivePtrCell). The intrusive pointer is faster than std::shared_ptr<>: std::shared_ptr<> makes an extra memory allocation for the ref counter whereas the intrusive pointer does not. More...

#include <intrusive_ptr.h>

Collaboration diagram for xgboost::IntrusivePtr< T >:
Collaboration graph

Classes

struct  Hash
 

Public Types

using element_type = T
 

Public Member Functions

 IntrusivePtr (T *p)
 Contruct an IntrusivePtr from raw pointer. IntrusivePtr takes the ownership. More...
 
 IntrusivePtr () noexcept=default
 
 IntrusivePtr (IntrusivePtr const &that)
 
 IntrusivePtr (IntrusivePtr &&that) noexcept
 
 ~IntrusivePtr ()
 
IntrusivePtr< T > & operator= (IntrusivePtr< T > const &that)
 
IntrusivePtr< T > & operator= (IntrusivePtr< T > &&that) noexcept
 
void reset ()
 
void reset (element_type *that)
 
element_typeoperator* () const noexcept
 
element_typeoperator-> () const noexcept
 
element_typeget () const noexcept
 
 operator bool () const noexcept
 
int32_t use_count () noexcept
 
void swap (IntrusivePtr< T > &that) noexcept
 

Protected Attributes

T * ptr_ {nullptr}
 

Detailed Description

template<typename T>
class xgboost::IntrusivePtr< T >

Implementation of Intrusive Pointer. A smart pointer that points to an object with an embedded reference counter. The underlying object must implement a friend function IntrusivePtrRefCount() that returns the ref counter (of type IntrusivePtrCell). The intrusive pointer is faster than std::shared_ptr<>: std::shared_ptr<> makes an extra memory allocation for the ref counter whereas the intrusive pointer does not.

class ForIntrusivePtrTest {
public:
mutable class IntrusivePtrCell ref;
float data { 0 };
friend IntrusivePtrCell &
IntrusivePtrRefCount(ForIntrusivePtrTest const *t) noexcept { // NOLINT
return t->ref;
}
ForIntrusivePtrTest() = default;
ForIntrusivePtrTest(float a, int32_t b) : data{a + static_cast<float>(b)} {}
explicit ForIntrusivePtrTest(NotCopyConstructible a) : data{a.data} {}
};
IntrusivePtr<ForIntrusivePtrTest> ptr {new ForIntrusivePtrTest};
IntrusivePtrCell & IntrusivePtrRefCount(T const *ptr) noexcept
User defined function for returning embedded reference count.

Member Typedef Documentation

◆ element_type

template<typename T >
using xgboost::IntrusivePtr< T >::element_type = T

Constructor & Destructor Documentation

◆ IntrusivePtr() [1/4]

template<typename T >
xgboost::IntrusivePtr< T >::IntrusivePtr ( T *  p)
inlineexplicit

Contruct an IntrusivePtr from raw pointer. IntrusivePtr takes the ownership.

Parameters
pRaw pointer to object

◆ IntrusivePtr() [2/4]

template<typename T >
xgboost::IntrusivePtr< T >::IntrusivePtr ( )
defaultnoexcept

◆ IntrusivePtr() [3/4]

template<typename T >
xgboost::IntrusivePtr< T >::IntrusivePtr ( IntrusivePtr< T > const &  that)
inline

◆ IntrusivePtr() [4/4]

template<typename T >
xgboost::IntrusivePtr< T >::IntrusivePtr ( IntrusivePtr< T > &&  that)
inlinenoexcept

◆ ~IntrusivePtr()

template<typename T >
xgboost::IntrusivePtr< T >::~IntrusivePtr ( )
inline

Member Function Documentation

◆ get()

template<typename T >
element_type* xgboost::IntrusivePtr< T >::get ( ) const
inlinenoexcept

◆ operator bool()

template<typename T >
xgboost::IntrusivePtr< T >::operator bool ( ) const
inlineexplicitnoexcept

◆ operator*()

template<typename T >
element_type& xgboost::IntrusivePtr< T >::operator* ( ) const
inlinenoexcept

◆ operator->()

template<typename T >
element_type* xgboost::IntrusivePtr< T >::operator-> ( ) const
inlinenoexcept

◆ operator=() [1/2]

template<typename T >
IntrusivePtr<T>& xgboost::IntrusivePtr< T >::operator= ( IntrusivePtr< T > &&  that)
inlinenoexcept

◆ operator=() [2/2]

template<typename T >
IntrusivePtr<T>& xgboost::IntrusivePtr< T >::operator= ( IntrusivePtr< T > const &  that)
inline

◆ reset() [1/2]

template<typename T >
void xgboost::IntrusivePtr< T >::reset ( )
inline

◆ reset() [2/2]

template<typename T >
void xgboost::IntrusivePtr< T >::reset ( element_type that)
inline

◆ swap()

template<typename T >
void xgboost::IntrusivePtr< T >::swap ( IntrusivePtr< T > &  that)
inlinenoexcept

◆ use_count()

template<typename T >
int32_t xgboost::IntrusivePtr< T >::use_count ( )
inlinenoexcept

Member Data Documentation

◆ ptr_

template<typename T >
T* xgboost::IntrusivePtr< T >::ptr_ {nullptr}
protected

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