ACE_Refcounted_Auto_Ptr_Rep< X, ACE_LOCK > Class Template Reference

An ACE_Refcounted_Auto_Ptr_Rep<X, ACE_LOCK> object encapsulates a pointer to an object of type X. It is pointed to by ACE_Refcounted_Auto_Ptr<X, ACE_LOCK> object[s] and only accessible through them. More...

#include <Refcounted_Auto_Ptr.h>

Collaboration diagram for ACE_Refcounted_Auto_Ptr_Rep< X, ACE_LOCK >:

Collaboration graph
[legend]
List of all members.

Private Member Functions

X * release (void)
 Sets the pointer value to 0 and returns its old value.

void reset (X *p=0)
X * get (void) const
 Get the pointer value.

int count (void) const
 Get the reference count value.

int null (void) const
 Allows us to check for NULL on all ACE_Refcounted_Auto_Ptr objects.

 ACE_Refcounted_Auto_Ptr_Rep (X *p=0)
 ~ACE_Refcounted_Auto_Ptr_Rep (void)

Static Private Member Functions

ACE_Refcounted_Auto_Ptr_Rep<
X, ACE_LOCK > * 
internal_create (X *p)
ACE_Refcounted_Auto_Ptr_Rep<
X, ACE_LOCK > * 
create (X *p)
ACE_Refcounted_Auto_Ptr_Rep<
X, ACE_LOCK > * 
attach (ACE_Refcounted_Auto_Ptr_Rep< X, ACE_LOCK > *&rep)
void detach (ACE_Refcounted_Auto_Ptr_Rep< X, ACE_LOCK > *&rep)
void assign (ACE_Refcounted_Auto_Ptr_Rep< X, ACE_LOCK > *&rep, ACE_Refcounted_Auto_Ptr_Rep< X, ACE_LOCK > *new_rep)

Private Attributes

 ACE_ALLOC_HOOK_DECLARE
 Declare the dynamic allocation hooks.

ACE_Auto_Basic_Ptr< X > ptr_
 Pointer to the result.

int ref_count_
 Reference count.

ACE_LOCK lock_
 Synchronization variable for the MT_SAFE .


Friends

class ACE_Refcounted_Auto_Ptr< X, ACE_LOCK >

Detailed Description

template<class X, class ACE_LOCK>
class ACE_Refcounted_Auto_Ptr_Rep< X, ACE_LOCK >

An ACE_Refcounted_Auto_Ptr_Rep<X, ACE_LOCK> object encapsulates a pointer to an object of type X. It is pointed to by ACE_Refcounted_Auto_Ptr<X, ACE_LOCK> object[s] and only accessible through them.

Definition at line 121 of file Refcounted_Auto_Ptr.h.


Constructor & Destructor Documentation

template<class X, class ACE_LOCK>
ACE_Refcounted_Auto_Ptr_Rep< X, ACE_LOCK >::ACE_Refcounted_Auto_Ptr_Rep X *  p = 0  )  [inline, private]
 

Definition at line 115 of file Refcounted_Auto_Ptr.inl.

00116   : ptr_ (p),
00117     ref_count_ (0)
00118 {
00119 }

template<class X, class ACE_LOCK>
ACE_Refcounted_Auto_Ptr_Rep< X, ACE_LOCK >::~ACE_Refcounted_Auto_Ptr_Rep void   )  [inline, private]
 

Definition at line 122 of file Refcounted_Auto_Ptr.inl.

00123 {
00124 }


Member Function Documentation

template<class X, class ACE_LOCK>
void ACE_Refcounted_Auto_Ptr_Rep< X, ACE_LOCK >::assign ACE_Refcounted_Auto_Ptr_Rep< X, ACE_LOCK > *&  rep,
ACE_Refcounted_Auto_Ptr_Rep< X, ACE_LOCK > *  new_rep
[inline, static, private]
 

Decreases the rep's reference count and and deletes rep if there are no more references to rep. Then assigns new_rep to rep.

Precondition (rep != 0 && new_rep != 0)

Definition at line 93 of file Refcounted_Auto_Ptr.inl.

References ACE_ASSERT, ACE_GUARD, ACE_Refcounted_Auto_Ptr_Rep< X, ACE_LOCK >::lock_, and ACE_Refcounted_Auto_Ptr_Rep< X, ACE_LOCK >::ref_count_.

00095 {
00096   ACE_ASSERT (rep != 0);
00097   ACE_ASSERT (new_rep != 0);
00098 
00099   ACE_Refcounted_Auto_Ptr_Rep<X, ACE_LOCK> *old = 0;
00100   {
00101     // detached old last for exception safety
00102     ACE_GUARD (ACE_LOCK, guard, rep->lock_);
00103     old = rep;
00104     rep = new_rep;
00105 
00106     if (old->ref_count_-- > 0)
00107       return;
00108 
00109   } // The lock is released before deleting old rep object below.
00110 
00111   delete old;
00112 }

template<class X, class ACE_LOCK>
ACE_Refcounted_Auto_Ptr_Rep< X, ACE_LOCK > * ACE_Refcounted_Auto_Ptr_Rep< X, ACE_LOCK >::attach ACE_Refcounted_Auto_Ptr_Rep< X, ACE_LOCK > *&  rep  )  [inline, static, private]
 

Increase the reference count and return argument. Uses the attribute "ace_lock_" to synchronize reference count updating.

Precondition (rep != 0).

Definition at line 62 of file Refcounted_Auto_Ptr.inl.

References ACE_ASSERT, ACE_GUARD_RETURN, ACE_Refcounted_Auto_Ptr_Rep< X, ACE_LOCK >::lock_, and ACE_Refcounted_Auto_Ptr_Rep< X, ACE_LOCK >::ref_count_.

00063 {
00064   ACE_ASSERT (rep != 0);
00065 
00066   ACE_GUARD_RETURN (ACE_LOCK, guard, rep->lock_, rep);
00067 
00068   ++rep->ref_count_;
00069 
00070   return rep;
00071 }

template<class X, class ACE_LOCK>
ACE_BEGIN_VERSIONED_NAMESPACE_DECL int ACE_Refcounted_Auto_Ptr_Rep< X, ACE_LOCK >::count void   )  const [inline, private]
 

Get the reference count value.

Definition at line 11 of file Refcounted_Auto_Ptr.inl.

References ACE_GUARD_RETURN.

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

00012 {
00013   ACE_GUARD_RETURN (ACE_LOCK, guard, this->lock_, 0);
00014   return this->ref_count_;
00015 }

template<class X, class ACE_LOCK>
ACE_Refcounted_Auto_Ptr_Rep< X, ACE_LOCK > * ACE_Refcounted_Auto_Ptr_Rep< X, ACE_LOCK >::create X *  p  )  [inline, static, private]
 

Create a ACE_Refcounted_Auto_Ptr_Rep<X, ACE_LOCK> and initialize the reference count.

Definition at line 48 of file Refcounted_Auto_Ptr.inl.

References ACE_ASSERT, ACE_throw_bad_alloc, and ACE_Refcounted_Auto_Ptr_Rep< X, ACE_LOCK >::internal_create().

00049 {
00050   // Yes set ref count to zero.
00051   ACE_Refcounted_Auto_Ptr_Rep<X, ACE_LOCK> *temp = internal_create (p);
00052 #if defined (ACE_NEW_THROWS_EXCEPTIONS)
00053   if (temp == 0)
00054     ACE_throw_bad_alloc;
00055 #else
00056   ACE_ASSERT (temp != 0);
00057 #endif /* ACE_NEW_THROWS_EXCEPTIONS */
00058    return temp;
00059 }

template<class X, class ACE_LOCK>
void ACE_Refcounted_Auto_Ptr_Rep< X, ACE_LOCK >::detach ACE_Refcounted_Auto_Ptr_Rep< X, ACE_LOCK > *&  rep  )  [inline, static, private]
 

Decreases the reference count and and deletes rep if there are no more references to rep.

Precondition (rep != 0)

Definition at line 74 of file Refcounted_Auto_Ptr.inl.

References ACE_ASSERT, ACE_GUARD, ACE_Refcounted_Auto_Ptr_Rep< X, ACE_LOCK >::lock_, and ACE_Refcounted_Auto_Ptr_Rep< X, ACE_LOCK >::ref_count_.

00075 {
00076   ACE_ASSERT (rep != 0);
00077   ACE_Refcounted_Auto_Ptr_Rep<X, ACE_LOCK> *rep_del = 0;
00078 
00079   {
00080     ACE_GUARD (ACE_LOCK, guard, rep->lock_);
00081 
00082     if (rep->ref_count_-- == 0)
00083       // Since rep contains the lock held by the ACE_Guard, the guard
00084       // needs to be released before freeing the memory holding the
00085       // lock. So save the pointer to free, then release, then free.
00086       rep_del = rep;
00087   }  // Release the lock
00088   if (0 != rep_del)
00089     delete rep;
00090 }

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

Get the pointer value.

Definition at line 143 of file Refcounted_Auto_Ptr.inl.

References ACE_GUARD_RETURN.

Referenced by ACE_Refcounted_Auto_Ptr< X, ACE_LOCK >::get(), ACE_Refcounted_Auto_Ptr< X, ACE_LOCK >::operator *(), and ACE_Refcounted_Auto_Ptr< X, ACE_LOCK >::operator->().

00144 {
00145   ACE_GUARD_RETURN (ACE_LOCK, guard, this->lock_, 0);
00146 
00147   return this->ptr_.get ();
00148 }

template<class X, class ACE_LOCK>
ACE_Refcounted_Auto_Ptr_Rep< X, ACE_LOCK > * ACE_Refcounted_Auto_Ptr_Rep< X, ACE_LOCK >::internal_create X *  p  )  [inline, static, private]
 

Allocate a new ACE_Refcounted_Auto_Ptr_Rep<X, ACE_LOCK> instance, returning NULL if it cannot be created.

Definition at line 38 of file Refcounted_Auto_Ptr.inl.

References ACE_NEW_RETURN.

Referenced by ACE_Refcounted_Auto_Ptr_Rep< X, ACE_LOCK >::create().

00039 {
00040   ACE_Refcounted_Auto_Ptr_Rep<X, ACE_LOCK> *temp = 0;
00041   ACE_NEW_RETURN (temp,
00042                   (ACE_Refcounted_Auto_Ptr_Rep<X, ACE_LOCK>) (p),
00043                   0);
00044   return temp;
00045 }

template<class X, class ACE_LOCK>
int ACE_Refcounted_Auto_Ptr_Rep< X, ACE_LOCK >::null void   )  const [inline, private]
 

Allows us to check for NULL on all ACE_Refcounted_Auto_Ptr objects.

Definition at line 24 of file Refcounted_Auto_Ptr.inl.

References ACE_GUARD_RETURN.

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

00025 {
00026   ACE_GUARD_RETURN (ACE_LOCK, guard, this->lock_, 0);
00027 
00028   return this->ptr_.get () == 0;
00029 }

template<class X, class ACE_LOCK>
X * ACE_Refcounted_Auto_Ptr_Rep< X, ACE_LOCK >::release void   )  [inline, private]
 

Sets the pointer value to 0 and returns its old value.

Definition at line 127 of file Refcounted_Auto_Ptr.inl.

References ACE_GUARD_RETURN.

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

00128 {
00129   ACE_GUARD_RETURN (ACE_LOCK, guard, this->lock_, 0);
00130 
00131   return this->ptr_.release ();
00132 }

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

Invokes delete on the previous pointer value and then sets the pointer value to the specified value.

Definition at line 135 of file Refcounted_Auto_Ptr.inl.

References ACE_GUARD.

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

00136 {
00137   ACE_GUARD (ACE_LOCK, guard, this->lock_);
00138 
00139   this->ptr_.reset (p);
00140 }


Friends And Related Function Documentation

template<class X, class ACE_LOCK>
friend class ACE_Refcounted_Auto_Ptr< X, ACE_LOCK > [friend]
 

Definition at line 124 of file Refcounted_Auto_Ptr.h.


Member Data Documentation

template<class X, class ACE_LOCK>
ACE_Refcounted_Auto_Ptr_Rep< X, ACE_LOCK >::ACE_ALLOC_HOOK_DECLARE [private]
 

Declare the dynamic allocation hooks.

Definition at line 140 of file Refcounted_Auto_Ptr.h.

template<class X, class ACE_LOCK>
ACE_LOCK ACE_Refcounted_Auto_Ptr_Rep< X, ACE_LOCK >::lock_ [mutable, private]
 

Synchronization variable for the MT_SAFE .

Definition at line 182 of file Refcounted_Auto_Ptr.h.

Referenced by ACE_Refcounted_Auto_Ptr_Rep< X, ACE_LOCK >::assign(), ACE_Refcounted_Auto_Ptr_Rep< X, ACE_LOCK >::attach(), and ACE_Refcounted_Auto_Ptr_Rep< X, ACE_LOCK >::detach().

template<class X, class ACE_LOCK>
ACE_Auto_Basic_Ptr<X> ACE_Refcounted_Auto_Ptr_Rep< X, ACE_LOCK >::ptr_ [private]
 

Pointer to the result.

Definition at line 174 of file Refcounted_Auto_Ptr.h.

template<class X, class ACE_LOCK>
int ACE_Refcounted_Auto_Ptr_Rep< X, ACE_LOCK >::ref_count_ [private]
 

Reference count.

Definition at line 177 of file Refcounted_Auto_Ptr.h.

Referenced by ACE_Refcounted_Auto_Ptr_Rep< X, ACE_LOCK >::assign(), ACE_Refcounted_Auto_Ptr_Rep< X, ACE_LOCK >::attach(), and ACE_Refcounted_Auto_Ptr_Rep< X, ACE_LOCK >::detach().


The documentation for this class was generated from the following files:
Generated on Thu Nov 9 11:27:53 2006 for ACE by doxygen 1.3.6