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]
List of all members.

Public Member Functions

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

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


Protected Member Functions

 True_RefCount_Policy (void)
 Constructor.

virtual ~True_RefCount_Policy (void)
 Destructor.


Private Attributes

ACE_Atomic_Op< TAO_SYNCH_MUTEX,
unsigned long > 
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 (void) { this->RefCountPolicy::add_ref (); } void my_remove_ref (void) { 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 @c delete() directly on the host class object.

Definition at line 71 of file True_RefCount_Policy.h.


Constructor & Destructor Documentation

TAO_BEGIN_VERSIONED_NAMESPACE_DECL ACE_INLINE TAO::True_RefCount_Policy::True_RefCount_Policy void   )  [protected]
 

Constructor.

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

Definition at line 8 of file True_RefCount_Policy.inl.

00009   : refcount_ (1)
00010 {
00011 }

TAO_BEGIN_VERSIONED_NAMESPACE_DECL TAO::True_RefCount_Policy::~True_RefCount_Policy void   )  [protected, virtual]
 

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.

Definition at line 16 of file True_RefCount_Policy.cpp.

00017 {
00018 }


Member Function Documentation

ACE_INLINE void TAO::True_RefCount_Policy::add_ref void   ) 
 

Increase the reference count on this object.

Definition at line 14 of file True_RefCount_Policy.inl.

00015 {
00016   ++this->refcount_;
00017 }

ACE_INLINE void TAO::True_RefCount_Policy::remove_ref void   ) 
 

Decrease the reference count on this object.

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

Definition at line 20 of file True_RefCount_Policy.inl.

00021 {
00022   const unsigned long new_count = --this->refcount_;
00023 
00024   if (new_count == 0)
00025     delete this;
00026 }


Member Data Documentation

ACE_Atomic_Op<TAO_SYNCH_MUTEX, unsigned long> TAO::True_RefCount_Policy::refcount_ [private]
 

Reference counter.

Definition at line 106 of file True_RefCount_Policy.h.


The documentation for this class was generated from the following files:
Generated on Sun Jan 27 13:22:08 2008 for TAO_AnyTypeCode by doxygen 1.3.6