HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
UT_IntrusiveRefCounter< DerivedT, Deleter, CounterPolicyT > Class Template Reference

A reference counter base class for use with UT_IntrusivePtr. More...

#include <UT_IntrusivePtr.h>

Public Member Functions

SYS_FORCE_INLINE UT_IntrusiveRefCounter () noexcept
 Default constructor: Sets counter to 0. More...
 
SYS_FORCE_INLINE UT_IntrusiveRefCounter (const UT_IntrusiveRefCounter &) noexcept
 Copy constructor: Sets counter to 0. More...
 
UT_IntrusiveRefCounteroperator= (const UT_IntrusiveRefCounter &) noexcept
 Assignment operator: Does not modify counter. More...
 
SYS_FORCE_INLINE uint32 use_count () const noexcept
 Return current counter. More...
 
SYS_FORCE_INLINE bool conditionalAddRef () noexcept
 

Protected Member Functions

SYS_FORCE_INLINE ~UT_IntrusiveRefCounter ()
 Destructor: Only derived classes can destruct this. More...
 

Friends

void intrusive_ptr_add_ref (const UT_IntrusiveRefCounter< DerivedT, Deleter, CounterPolicyT > *p) noexcept
 
void intrusive_ptr_release (const UT_IntrusiveRefCounter< DerivedT, Deleter, CounterPolicyT > *p) noexcept
 
void intrusive_ptr_add_ref (const UT_IntrusiveRefCounter< DerivedT, Deleter, CounterPolicyT > *p, typename CounterPolicyT::pod_type refs_to_add) noexcept
 
void intrusive_ptr_release (const UT_IntrusiveRefCounter< DerivedT, Deleter, CounterPolicyT > *p, typename CounterPolicyT::pod_type refs_to_remove) noexcept
 

Detailed Description

template<typename DerivedT, typename Deleter = std::default_delete<DerivedT>, typename CounterPolicyT = UT_IntrusiveThreadSafeCounterPolicy>
class UT_IntrusiveRefCounter< DerivedT, Deleter, CounterPolicyT >

A reference counter base class for use with UT_IntrusivePtr.

This base class can be used with user-defined classes to add support for UT_IntrusivePtr. The class contains a reference counter defined by the CounterPolicyT. Upon releasing the last UT_IntrusivePtr referencing the object derived from the UT_IntrusiveRefCounter class, operator delete is automatically called on the pointer to the object.

The other template parameter, DerivedT, is the user's class that derives from UT_IntrusiveRefCounter.

Example:

class MyClass : public UT_IntrusiveRefCounter<MyClass>
{ ... };
using MyClassPtr = UT_IntrusivePtr<MyClass>;

Definition at line 242 of file UT_IntrusivePtr.h.

Constructor & Destructor Documentation

template<typename DerivedT, typename Deleter = std::default_delete<DerivedT>, typename CounterPolicyT = UT_IntrusiveThreadSafeCounterPolicy>
SYS_FORCE_INLINE UT_IntrusiveRefCounter< DerivedT, Deleter, CounterPolicyT >::UT_IntrusiveRefCounter ( )
inlinenoexcept

Default constructor: Sets counter to 0.

Definition at line 288 of file UT_IntrusivePtr.h.

template<typename DerivedT, typename Deleter = std::default_delete<DerivedT>, typename CounterPolicyT = UT_IntrusiveThreadSafeCounterPolicy>
SYS_FORCE_INLINE UT_IntrusiveRefCounter< DerivedT, Deleter, CounterPolicyT >::UT_IntrusiveRefCounter ( const UT_IntrusiveRefCounter< DerivedT, Deleter, CounterPolicyT > &  )
inlinenoexcept

Copy constructor: Sets counter to 0.

Definition at line 294 of file UT_IntrusivePtr.h.

template<typename DerivedT, typename Deleter = std::default_delete<DerivedT>, typename CounterPolicyT = UT_IntrusiveThreadSafeCounterPolicy>
SYS_FORCE_INLINE UT_IntrusiveRefCounter< DerivedT, Deleter, CounterPolicyT >::~UT_IntrusiveRefCounter ( )
inlineprotected

Destructor: Only derived classes can destruct this.

Definition at line 321 of file UT_IntrusivePtr.h.

Member Function Documentation

template<typename DerivedT, typename Deleter = std::default_delete<DerivedT>, typename CounterPolicyT = UT_IntrusiveThreadSafeCounterPolicy>
SYS_FORCE_INLINE bool UT_IntrusiveRefCounter< DerivedT, Deleter, CounterPolicyT >::conditionalAddRef ( )
inlinenoexcept

Adds a reference only if the reference count is not zero. This can be used to implement an operation similar to weak_ptr::lock().

Definition at line 313 of file UT_IntrusivePtr.h.

template<typename DerivedT, typename Deleter = std::default_delete<DerivedT>, typename CounterPolicyT = UT_IntrusiveThreadSafeCounterPolicy>
UT_IntrusiveRefCounter& UT_IntrusiveRefCounter< DerivedT, Deleter, CounterPolicyT >::operator= ( const UT_IntrusiveRefCounter< DerivedT, Deleter, CounterPolicyT > &  )
inlinenoexcept

Assignment operator: Does not modify counter.

Definition at line 299 of file UT_IntrusivePtr.h.

template<typename DerivedT, typename Deleter = std::default_delete<DerivedT>, typename CounterPolicyT = UT_IntrusiveThreadSafeCounterPolicy>
SYS_FORCE_INLINE uint32 UT_IntrusiveRefCounter< DerivedT, Deleter, CounterPolicyT >::use_count ( ) const
inlinenoexcept

Return current counter.

Definition at line 305 of file UT_IntrusivePtr.h.

Friends And Related Function Documentation

template<typename DerivedT, typename Deleter = std::default_delete<DerivedT>, typename CounterPolicyT = UT_IntrusiveThreadSafeCounterPolicy>
void intrusive_ptr_add_ref ( const UT_IntrusiveRefCounter< DerivedT, Deleter, CounterPolicyT > *  p)
friend

Definition at line 345 of file UT_IntrusivePtr.h.

template<typename DerivedT, typename Deleter = std::default_delete<DerivedT>, typename CounterPolicyT = UT_IntrusiveThreadSafeCounterPolicy>
void intrusive_ptr_add_ref ( const UT_IntrusiveRefCounter< DerivedT, Deleter, CounterPolicyT > *  p,
typename CounterPolicyT::pod_type  refs_to_add 
)
friend

Definition at line 364 of file UT_IntrusivePtr.h.

template<typename DerivedT, typename Deleter = std::default_delete<DerivedT>, typename CounterPolicyT = UT_IntrusiveThreadSafeCounterPolicy>
void intrusive_ptr_release ( const UT_IntrusiveRefCounter< DerivedT, Deleter, CounterPolicyT > *  p)
friend

Definition at line 352 of file UT_IntrusivePtr.h.

template<typename DerivedT, typename Deleter = std::default_delete<DerivedT>, typename CounterPolicyT = UT_IntrusiveThreadSafeCounterPolicy>
void intrusive_ptr_release ( const UT_IntrusiveRefCounter< DerivedT, Deleter, CounterPolicyT > *  p,
typename CounterPolicyT::pod_type  refs_to_remove 
)
friend

Definition at line 372 of file UT_IntrusivePtr.h.


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