Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members   Related Pages  

ACE_Refcounted_Auto_Ptr_Rep 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:

Collaboration graph
[legend]
List of all members.

Private Methods

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

void reset (X *p=0)
 Invokes delete on the previous pointer value and then sets the pointer value to the specified value. More...

X * get (void) const
 Get the pointer value. More...

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

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

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

Static Private Methods

ACE_Refcounted_Auto_Ptr_Rep<
X, ACE_LOCK > * 
internal_create (X *p)
 Allocate a new ACE_Refcounted_Auto_Ptr_Rep<X, ACE_LOCK> instance, returning NULL if it cannot be created. More...

ACE_Refcounted_Auto_Ptr_Rep<
X, ACE_LOCK > * 
create (X *p)
 Create a ACE_Refcounted_Auto_Ptr_Rep<X, ACE_LOCK> and initialize the reference count. More...

ACE_Refcounted_Auto_Ptr_Rep<
X, ACE_LOCK > * 
attach (ACE_Refcounted_Auto_Ptr_Rep< X, ACE_LOCK > *&rep)
 Increase the reference count and return argument. Uses the attribute "ace_lock_" to synchronize reference count updating. Precondition (rep != 0). More...

void detach (ACE_Refcounted_Auto_Ptr_Rep< X, ACE_LOCK > *&rep)
 Decreases the reference count and and deletes rep if there are no more references to rep. Precondition (rep != 0). More...

void assign (ACE_Refcounted_Auto_Ptr_Rep< X, ACE_LOCK > *&rep, ACE_Refcounted_Auto_Ptr_Rep< X, ACE_LOCK > *new_rep)
 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). More...


Private Attributes

 ACE_ALLOC_HOOK_DECLARE
 Declare the dynamic allocation hooks. More...

ACE_Auto_Basic_Ptr< X > ptr_
 Pointer to the result. More...

int ref_count_
 Reference count. More...

ACE_LOCK lock_
 Synchronization variable for the MT_SAFE <ACE_Hash_Map_Manager_Ex>. More...


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 117 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.i.

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.i.

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.i.

References ACE_ASSERT, ACE_GUARD, lock_, and 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.i.

References ACE_ASSERT, ACE_GUARD_RETURN, lock_, and 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>
int ACE_Refcounted_Auto_Ptr_Rep< X, ACE_LOCK >::count void    const [inline, private]
 

Get the reference count value.

Definition at line 10 of file Refcounted_Auto_Ptr.i.

References ACE_GUARD_RETURN, and ref_count_.

Referenced by ACE_Refcounted_Auto_Ptr::count.

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

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.i.

References ACE_ASSERT, ACE_throw_bad_alloc, and 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.i.

References ACE_ASSERT, ACE_GUARD, lock_, and 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.i.

References ACE_GUARD_RETURN, and ptr_.

Referenced by ACE_Refcounted_Auto_Ptr::get, ACE_Refcounted_Auto_Ptr::operator *, and ACE_Refcounted_Auto_Ptr::operator->.

00144 {
00145   ACE_GUARD_RETURN (ACE_LOCK, guard, ACE_const_cast (ACE_LOCK &, 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.i.

References ACE_NEW_RETURN.

Referenced by 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 23 of file Refcounted_Auto_Ptr.i.

References ACE_GUARD_RETURN, and ptr_.

Referenced by ACE_Refcounted_Auto_Ptr::null.

00024 {
00025   ACE_GUARD_RETURN (ACE_LOCK, guard,
00026                     ACE_const_cast (ACE_LOCK&, 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.i.

References ACE_GUARD_RETURN, and ptr_.

Referenced by ACE_Refcounted_Auto_Ptr::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.i.

References ACE_GUARD, and ptr_.

Referenced by ACE_Refcounted_Auto_Ptr::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 120 of file Refcounted_Auto_Ptr.h.


Member Data Documentation

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

Declare the dynamic allocation hooks.

Definition at line 136 of file Refcounted_Auto_Ptr.h.

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

Synchronization variable for the MT_SAFE <ACE_Hash_Map_Manager_Ex>.

Definition at line 178 of file Refcounted_Auto_Ptr.h.

Referenced by assign, attach, and detach.

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

Pointer to the result.

Definition at line 170 of file Refcounted_Auto_Ptr.h.

Referenced by get, null, release, and reset.

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

Reference count.

Definition at line 173 of file Refcounted_Auto_Ptr.h.

Referenced by assign, attach, count, and detach.


The documentation for this class was generated from the following files:
Generated on Mon Jun 16 12:55:02 2003 for ACE by doxygen1.2.14 written by Dimitri van Heesch, © 1997-2002