TAO_AnyTypeCode 4.0.0
Loading...
Searching...
No Matches
Public Member Functions | Protected Member Functions | Private Attributes | List of all members
TAO::True_RefCount_Policy Class Reference

True reference counting policy. More...

#include <True_RefCount_Policy.h>

Collaboration diagram for TAO::True_RefCount_Policy:
Collaboration graph
[legend]

Public Member Functions

void add_ref ()
 Increase the reference count on this object.
 
void remove_ref ()
 Decrease the reference count on this object.
 

Protected Member Functions

 True_RefCount_Policy ()
 Constructor.
 
virtual ~True_RefCount_Policy ()
 Destructor.
 

Private Attributes

std::atomic< uint32_t > refcount_
 Reference counter.
 

Detailed Description

True reference counting policy.

This class is intended to be used as a "policy" argument to a host class template that requires true/functional reference counting. That class would then inherit privately from it like so:

template <class RefCountPolicy>
class MyHostClass : private RefCountPolicy
{
public:
void my_add_ref () { this->RefCountPolicy::add_ref (); }
void my_remove_ref () { this->RefCountPolicy::remove_ref (); }
};

and use it like so:

typedef MyHostClass<TAO::True_RefCount_Policy> MyRefCountedClass;
MyRefCountedClass * p = new MyRefCountedClass;
...
p->my_remove_ref ();
Note
Ideally, the host class should declare a protected destructor to enforce proper memory management through the reference counting mechanism, i.e. to prevent clients from calling operator delete() directly on the host class object.

Constructor & Destructor Documentation

◆ True_RefCount_Policy()

TAO::True_RefCount_Policy::True_RefCount_Policy ( )
protected

Constructor.

Note
This constructor is protected since it not meant to be instantiated/used as a standalone object.

◆ ~True_RefCount_Policy()

TAO::True_RefCount_Policy::~True_RefCount_Policy ( )
protectedvirtual

Destructor.

Note
The destructor must be virtual to ensure that subclass destructors are called when the reference count drops to zero, i.e. when remove_ref() calls operator delete this.

Member Function Documentation

◆ add_ref()

void TAO::True_RefCount_Policy::add_ref ( )

Increase the reference count on this object.

◆ remove_ref()

void TAO::True_RefCount_Policy::remove_ref ( )

Decrease the reference count on this object.

Decrease the reference count on this object. Once the reference count drops to zero, call operator delete() on this object.

Member Data Documentation

◆ refcount_

std::atomic<uint32_t> TAO::True_RefCount_Policy::refcount_
private

Reference counter.


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