ACE_Refcounted_Auto_Ptr< X, ACE_LOCK > Class Template Reference

This class implements support for a reference counted auto_ptr. Assigning or copying instances of an ACE_Refcounted_Auto_Ptr will automatically increment the reference count. When the last instance that references a ACE_Refcounted_Auto_Ptr instance is destroyed or overwritten, it will invoke delete on its underlying pointer. More...

#include <Refcounted_Auto_Ptr.h>

Collaboration diagram for ACE_Refcounted_Auto_Ptr< X, ACE_LOCK >:

Collaboration graph
[legend]
List of all members.

Public Member Functions

 ACE_Refcounted_Auto_Ptr (X *p=0)
 ACE_Refcounted_Auto_Ptr (const ACE_Refcounted_Auto_Ptr< X, ACE_LOCK > &r)
virtual ~ACE_Refcounted_Auto_Ptr (void)
void operator= (const ACE_Refcounted_Auto_Ptr< X, ACE_LOCK > &r)
bool operator== (const ACE_Refcounted_Auto_Ptr< X, ACE_LOCK > &r) const
bool operator!= (const ACE_Refcounted_Auto_Ptr< X, ACE_LOCK > &r) const
 Inequality operator, which is the opposite of equality.
X * operator-> (void) const
 Redirection operator.
X & operator * () const
 Accessor method.
bool operator! () const
 Check rep easily.
 operator bool () const
 Check rep easily.
X * release (void)
void reset (X *p=0)
X * get (void) const
 Get the pointer value.
long count (void) const
 Get the reference count value.
bool null (void) const
 Returns true if this object does not contain a valid pointer.

Public Attributes

 ACE_ALLOC_HOOK_DECLARE
 Declare the dynamic allocation hooks.

Protected Types

typedef ACE_Refcounted_Auto_Ptr_Rep<
X, ACE_LOCK > 
AUTO_REFCOUNTED_PTR_REP
 the ACE_Refcounted_Auto_Ptr_Rep

Protected Attributes

AUTO_REFCOUNTED_PTR_REPrep_
 Protect operations on the ACE_Refcounted_Auto_Ptr.

Detailed Description

template<class X, class ACE_LOCK>
class ACE_Refcounted_Auto_Ptr< X, ACE_LOCK >

This class implements support for a reference counted auto_ptr. Assigning or copying instances of an ACE_Refcounted_Auto_Ptr will automatically increment the reference count. When the last instance that references a ACE_Refcounted_Auto_Ptr instance is destroyed or overwritten, it will invoke delete on its underlying pointer.

The ACE_Refcounted_Auto_Ptr works by maintaining a reference to a separate representation object, ACE_Refcounted_Auto_Ptr_Rep. That separate representation object contains the reference count and the actual pointer value.

Definition at line 47 of file Refcounted_Auto_Ptr.h.


Member Typedef Documentation

template<class X, class ACE_LOCK>
typedef ACE_Refcounted_Auto_Ptr_Rep<X, ACE_LOCK> ACE_Refcounted_Auto_Ptr< X, ACE_LOCK >::AUTO_REFCOUNTED_PTR_REP [protected]

the ACE_Refcounted_Auto_Ptr_Rep

Definition at line 118 of file Refcounted_Auto_Ptr.h.


Constructor & Destructor Documentation

template<class X, class ACE_LOCK>
ACE_Refcounted_Auto_Ptr< X, ACE_LOCK >::ACE_Refcounted_Auto_Ptr ( X *  p = 0  )  [inline, explicit]

Constructor that initializes an ACE_Refcounted_Auto_Ptr to the specified pointer value.

Definition at line 92 of file Refcounted_Auto_Ptr.inl.

00093   : rep_ (AUTO_REFCOUNTED_PTR_REP::create (p))
00094 {
00095 }

template<class X, class ACE_LOCK>
ACE_Refcounted_Auto_Ptr< X, ACE_LOCK >::ACE_Refcounted_Auto_Ptr ( const ACE_Refcounted_Auto_Ptr< X, ACE_LOCK > &  r  )  [inline]

Copy constructor binds the new ACE_Refcounted_Auto_Ptr to the representation object referenced by r. An ACE_Refcounted_Auto_Ptr_Rep is created if necessary.

Definition at line 98 of file Refcounted_Auto_Ptr.inl.

template<class X, class ACE_LOCK>
ACE_BEGIN_VERSIONED_NAMESPACE_DECL ACE_Refcounted_Auto_Ptr< X, ACE_LOCK >::~ACE_Refcounted_Auto_Ptr ( void   )  [virtual]

Destructor. Releases the reference to the underlying representation. If the release of that reference causes its reference count to reach 0, the representation object will also be destroyed.

Definition at line 11 of file Refcounted_Auto_Ptr.cpp.

References ACE_Refcounted_Auto_Ptr_Rep< X, ACE_LOCK >::detach(), and ACE_Refcounted_Auto_Ptr< X, ACE_LOCK >::rep_.

00012 {
00013   AUTO_REFCOUNTED_PTR_REP::detach (rep_);
00014 }


Member Function Documentation

template<class X, class ACE_LOCK>
long ACE_Refcounted_Auto_Ptr< X, ACE_LOCK >::count ( void   )  const [inline]

Get the reference count value.

Definition at line 17 of file Refcounted_Auto_Ptr.inl.

References ACE_Refcounted_Auto_Ptr_Rep< X, ACE_LOCK >::count(), and ACE_Refcounted_Auto_Ptr< X, ACE_LOCK >::rep_.

00018 {
00019   return this->rep_->count ();
00020 }

template<class X, class ACE_LOCK>
X * ACE_Refcounted_Auto_Ptr< X, ACE_LOCK >::get ( void   )  const [inline]

Get the pointer value.

Definition at line 140 of file Refcounted_Auto_Ptr.inl.

References ACE_Refcounted_Auto_Ptr_Rep< X, ACE_LOCK >::get(), and ACE_Refcounted_Auto_Ptr< X, ACE_LOCK >::rep_.

Referenced by ACE_Refcounted_Auto_Ptr< X, ACE_LOCK >::release().

00141 {
00142   // We return the ACE_Future_rep.
00143   return this->rep_->get ();
00144 }

template<class X, class ACE_LOCK>
bool ACE_Refcounted_Auto_Ptr< X, ACE_LOCK >::null ( void   )  const [inline]

Returns true if this object does not contain a valid pointer.

Definition at line 23 of file Refcounted_Auto_Ptr.inl.

00024 {
00025   return (this->rep_ == 0 || this->rep_->get () == 0);
00026 }

template<class X, class ACE_LOCK>
X & ACE_Refcounted_Auto_Ptr< X, ACE_LOCK >::operator * (  )  const [inline]

Accessor method.

Definition at line 122 of file Refcounted_Auto_Ptr.inl.

References ACE_Refcounted_Auto_Ptr_Rep< X, ACE_LOCK >::get(), and ACE_Refcounted_Auto_Ptr< X, ACE_LOCK >::rep_.

00123 {
00124   return *this->rep_->get ();
00125 }

template<class X, class ACE_LOCK>
ACE_Refcounted_Auto_Ptr< X, ACE_LOCK >::operator bool (  )  const [inline]

Check rep easily.

Definition at line 134 of file Refcounted_Auto_Ptr.inl.

References ACE_Refcounted_Auto_Ptr_Rep< X, ACE_LOCK >::get(), and ACE_Refcounted_Auto_Ptr< X, ACE_LOCK >::rep_.

00135 {
00136   return this->rep_->get () != 0;
00137 }

template<class X, class ACE_LOCK>
bool ACE_Refcounted_Auto_Ptr< X, ACE_LOCK >::operator! (  )  const [inline]

Check rep easily.

Definition at line 128 of file Refcounted_Auto_Ptr.inl.

References ACE_Refcounted_Auto_Ptr_Rep< X, ACE_LOCK >::get(), and ACE_Refcounted_Auto_Ptr< X, ACE_LOCK >::rep_.

00129 {
00130   return this->rep_->get () == 0;
00131 }

template<class X, class ACE_LOCK>
bool ACE_Refcounted_Auto_Ptr< X, ACE_LOCK >::operator!= ( const ACE_Refcounted_Auto_Ptr< X, ACE_LOCK > &  r  )  const [inline]

Inequality operator, which is the opposite of equality.

Definition at line 110 of file Refcounted_Auto_Ptr.inl.

References ACE_Refcounted_Auto_Ptr< X, ACE_LOCK >::rep_.

00111 {
00112   return r.rep_ != this->rep_;
00113 }

template<class X, class ACE_LOCK>
X * ACE_Refcounted_Auto_Ptr< X, ACE_LOCK >::operator-> ( void   )  const [inline]

Redirection operator.

Definition at line 116 of file Refcounted_Auto_Ptr.inl.

References ACE_Refcounted_Auto_Ptr_Rep< X, ACE_LOCK >::get(), and ACE_Refcounted_Auto_Ptr< X, ACE_LOCK >::rep_.

00117 {
00118     return this->rep_->get();
00119 }

template<class X, class ACE_LOCK>
void ACE_Refcounted_Auto_Ptr< X, ACE_LOCK >::operator= ( const ACE_Refcounted_Auto_Ptr< X, ACE_LOCK > &  r  )  [inline]

Assignment operator that binds the current object and r to the same ACE_Refcounted_Auto_Ptr_Rep. An ACE_Refcounted_Auto_Ptr_Rep is created if necessary.

Definition at line 172 of file Refcounted_Auto_Ptr.inl.

References ACE_Refcounted_Auto_Ptr_Rep< X, ACE_LOCK >::attach(), ACE_Refcounted_Auto_Ptr_Rep< X, ACE_LOCK >::detach(), and ACE_Refcounted_Auto_Ptr< X, ACE_LOCK >::rep_.

00173 {
00174   //  bind <this> to the same <ACE_Refcounted_Auto_Ptr_Rep> as <r>.
00175   AUTO_REFCOUNTED_PTR_REP *old_rep = this->rep_;
00176   if (rhs.rep_ != 0)
00177     {
00178       this->rep_ = AUTO_REFCOUNTED_PTR_REP::attach
00179         (const_cast<ACE_Refcounted_Auto_Ptr<X, ACE_LOCK>& > (rhs).rep_);
00180       if (this->rep_ != 0)
00181         AUTO_REFCOUNTED_PTR_REP::detach (old_rep);
00182     }
00183   else    // Assign a 0 rep to this
00184     {
00185       AUTO_REFCOUNTED_PTR_REP::detach (old_rep);
00186       this->rep_ = 0;
00187     }
00188 }

template<class X, class ACE_LOCK>
bool ACE_Refcounted_Auto_Ptr< X, ACE_LOCK >::operator== ( const ACE_Refcounted_Auto_Ptr< X, ACE_LOCK > &  r  )  const [inline]

Note:
It also returns true if both objects have just been instantiated and not used yet.

Definition at line 104 of file Refcounted_Auto_Ptr.inl.

References ACE_Refcounted_Auto_Ptr< X, ACE_LOCK >::rep_.

00105 {
00106   return r.rep_ == this->rep_;
00107 }

template<class X, class ACE_LOCK>
X * ACE_Refcounted_Auto_Ptr< X, ACE_LOCK >::release ( void   )  [inline]

Releases the reference to the underlying representation object.

Return values:
The pointer value prior to releasing it.

Definition at line 147 of file Refcounted_Auto_Ptr.inl.

References ACE_Refcounted_Auto_Ptr_Rep< X, ACE_LOCK >::detach(), ACE_Refcounted_Auto_Ptr< X, ACE_LOCK >::get(), and ACE_Refcounted_Auto_Ptr< X, ACE_LOCK >::rep_.

00148 {
00149   X *p = this->get ();
00150   AUTO_REFCOUNTED_PTR_REP::detach (this->rep_);
00151   this->rep_ = 0;
00152   return p;
00153 }

template<class X, class ACE_LOCK>
void ACE_Refcounted_Auto_Ptr< X, ACE_LOCK >::reset ( X *  p = 0  )  [inline]

Releases the current pointer value and then sets a new pointer value specified by p.

Definition at line 156 of file Refcounted_Auto_Ptr.inl.

References ACE_Refcounted_Auto_Ptr_Rep< X, ACE_LOCK >::create(), ACE_Refcounted_Auto_Ptr_Rep< X, ACE_LOCK >::detach(), and ACE_Refcounted_Auto_Ptr< X, ACE_LOCK >::rep_.

00157 {
00158   // Avoid deleting the underlying auto_ptr if assigning the same actual
00159   // pointer value.
00160   if (this->get () == p)
00161     return;
00162 
00163   AUTO_REFCOUNTED_PTR_REP *old_rep = this->rep_;
00164   if ((this->rep_ = AUTO_REFCOUNTED_PTR_REP::create (p)) != 0)
00165     AUTO_REFCOUNTED_PTR_REP::detach (old_rep);
00166   else
00167     this->rep_ = old_rep;
00168   return;
00169 }


Member Data Documentation

template<class X, class ACE_LOCK>
ACE_Refcounted_Auto_Ptr< X, ACE_LOCK >::ACE_ALLOC_HOOK_DECLARE

Declare the dynamic allocation hooks.

Definition at line 114 of file Refcounted_Auto_Ptr.h.

template<class X, class ACE_LOCK>
AUTO_REFCOUNTED_PTR_REP* ACE_Refcounted_Auto_Ptr< X, ACE_LOCK >::rep_ [protected]

Protect operations on the ACE_Refcounted_Auto_Ptr.

Definition at line 121 of file Refcounted_Auto_Ptr.h.

Referenced by ACE_Refcounted_Auto_Ptr< X, ACE_LOCK >::count(), ACE_Refcounted_Auto_Ptr< X, ACE_LOCK >::get(), ACE_Refcounted_Auto_Ptr< X, ACE_LOCK >::operator *(), ACE_Refcounted_Auto_Ptr< X, ACE_LOCK >::operator bool(), ACE_Refcounted_Auto_Ptr< X, ACE_LOCK >::operator!(), ACE_Refcounted_Auto_Ptr< X, ACE_LOCK >::operator!=(), ACE_Refcounted_Auto_Ptr< X, ACE_LOCK >::operator->(), ACE_Refcounted_Auto_Ptr< X, ACE_LOCK >::operator=(), ACE_Refcounted_Auto_Ptr< X, ACE_LOCK >::operator==(), ACE_Refcounted_Auto_Ptr< X, ACE_LOCK >::release(), ACE_Refcounted_Auto_Ptr< X, ACE_LOCK >::reset(), and ACE_Refcounted_Auto_Ptr< X, ACE_LOCK >::~ACE_Refcounted_Auto_Ptr().


The documentation for this class was generated from the following files:
Generated on Tue Feb 2 17:35:30 2010 for ACE by  doxygen 1.4.7