senf::intrusive_refcount_t< Self > Class Template Reference

Customizable reference count mixin for intrusive_ptr. More...

#include <senf/Utils/intrusive_refcount.hh>

Inheritance diagram for senf::intrusive_refcount_t< Self >:
Inheritance graph
[legend]

List of all members.


Detailed Description

template<class Self>
class senf::intrusive_refcount_t< Self >

Customizable reference count mixin for intrusive_ptr.

This class provides a simple internally managed refcount and supplies the boost::intrusive_ptr required interface. To make a class compatible with boost::intrusive_ptr, just derive publicly from intrusive_refcount_t.

class SomeClass
    : public intrusive_refcount_t<SomeClass>
{
    // ...

private:
    typedef intrusive_refcount_t<SomeClass> intrusive_base;

    void add_ref()
    {
        // somehow call intrusive_base::add_ref()
    }

    bool release()
    {
        // Call intrusive_base::release() to decrement the
        // refcount. This call will return 'true' when the refcount reaches 0.

        // Return 'true', if the instance shall be deleted
    }

    // Needed to give intrusive_base access to 'add_ref' and 'release'
    friend class intrusive_base;
};

Two additional benefits of using intrusive_refcount are

  • The object can access it's own refcount
  • It is valid and safe to convert a plain object pointer to an intrusive_ptr at any time (not only after new)
This class allows to customize the reference counting strategy (e.g. additional refcounting within another object or checking some additional condition before deleting the object when the refcount reaches 0).

The interface of this class is defined in intrusive_refcount_base (which you should not use directly).

Definition at line 120 of file intrusive_refcount.hh.


Protected Member Functions

  intrusive_refcount_t ()

Constructor & Destructor Documentation

template<class Self >
senf::intrusive_refcount_t< Self >::
intrusive_refcount_t ()

Definition at line 58 of file intrusive_refcount.cti.


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