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

ACE_Strong_Bound_Ptr Class Template Reference

This class implements support for a reference counted pointer. More...

#include <Bound_Ptr.h>

Collaboration diagram for ACE_Strong_Bound_Ptr:

Collaboration graph
[legend]
List of all members.

Public Methods

ACE_EXPLICIT ACE_Strong_Bound_Ptr (X *p=0)
 Constructor that initializes an ACE_Strong_Bound_Ptr to point to the object <p> immediately. More...

ACE_EXPLICIT ACE_Strong_Bound_Ptr (auto_ptr< X > p)
 Constructor that initializes an ACE_Strong_Bound_Ptr by stealing ownership of an object from an auto_ptr. More...

 ACE_Strong_Bound_Ptr (const ACE_Strong_Bound_Ptr< X, ACE_LOCK > &r)
 Copy constructor binds <this> and <r> to the same object. More...

 ACE_Strong_Bound_Ptr (const ACE_Weak_Bound_Ptr< X, ACE_LOCK > &r)
 Constructor binds <this> and <r> to the same object. More...

 ~ACE_Strong_Bound_Ptr (void)
 Destructor. More...

void operator= (const ACE_Strong_Bound_Ptr< X, ACE_LOCK > &r)
 Assignment operator that binds <this> and <r> to the same object. More...

void operator= (const ACE_Weak_Bound_Ptr< X, ACE_LOCK > &r)
 Assignment operator that binds <this> and <r> to the same object. More...

int operator== (const ACE_Strong_Bound_Ptr< X, ACE_LOCK > &r) const
 Equality operator that returns 1 if both ACE_Strong_Bound_Ptr instances point to the same underlying object. More...

int operator== (const ACE_Weak_Bound_Ptr< X, ACE_LOCK > &r) const
 Equality operator that returns 1 if the ACE_Strong_Bound_Ptr and ACE_Weak_Bound_Ptr objects point to the same underlying object. More...

int operator== (X *p) const
 Equality operator that returns 1 if the ACE_Strong_Bound_Ptr and the raw pointer point to the same underlying object. More...

int operator!= (const ACE_Strong_Bound_Ptr< X, ACE_LOCK > &r) const
 Inequality operator, which is the opposite of equality. More...

int operator!= (const ACE_Weak_Bound_Ptr< X, ACE_LOCK > &r) const
 Inequality operator, which is the opposite of equality. More...

int operator!= (X *p) const
 Inequality operator, which is the opposite of equality. More...

X * operator-> (void) const
 Redirection operator. More...

X & operator * (void) const
 Dereference operator. More...

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

void reset (X *p=0)
 Resets the ACE_Strong_Bound_Ptr to refer to a different underlying object. More...

void reset (auto_ptr< X > p)
 Resets the ACE_Strong_Bound_Ptr to refer to a different underlying object, ownership of which is stolen from the auto_ptr. More...

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


Public Attributes

 ACE_ALLOC_HOOK_DECLARE
 Declare the dynamic allocation hooks. More...


Private Types

typedef ACE_Bound_Ptr_Counter<
ACE_LOCK > 
COUNTER
 The ACE_Bound_Ptr_Counter type. More...


Private Attributes

COUNTERcounter_
 The reference counter. More...

X * ptr_
 The underlying object. More...


Friends

class ACE_Weak_Bound_Ptr< X, ACE_LOCK >

Detailed Description

template<class X, class ACE_LOCK>
class ACE_Strong_Bound_Ptr< X, ACE_LOCK >

This class implements support for a reference counted pointer.

Assigning or copying instances of an ACE_Strong_Bound_Ptr will automatically increment the reference count of the underlying object. When the last instance of an ACE_Strong_Bound_Ptr that references a particular object is destroyed or overwritten, it will invoke delete on its underlying pointer.

Definition at line 109 of file Bound_Ptr.h.


Member Typedef Documentation

template<class X, class ACE_LOCK>
typedef ACE_Bound_Ptr_Counter<ACE_LOCK> ACE_Strong_Bound_Ptr::COUNTER [private]
 

The ACE_Bound_Ptr_Counter type.

Definition at line 194 of file Bound_Ptr.h.


Constructor & Destructor Documentation

template<class X, class ACE_LOCK>
ACE_Strong_Bound_Ptr< X, ACE_LOCK >::ACE_Strong_Bound_Ptr X *    p = 0 [inline]
 

Constructor that initializes an ACE_Strong_Bound_Ptr to point to the object <p> immediately.

Definition at line 142 of file Bound_Ptr.i.

00143   : counter_ (COUNTER::create_strong ()),
00144     ptr_ (p)
00145 {
00146 }

template<class X, class ACE_LOCK>
ACE_Strong_Bound_Ptr< X, ACE_LOCK >::ACE_Strong_Bound_Ptr auto_ptr< X >    p [inline]
 

Constructor that initializes an ACE_Strong_Bound_Ptr by stealing ownership of an object from an auto_ptr.

Definition at line 149 of file Bound_Ptr.i.

00150   : counter_ (COUNTER::create_strong ()),
00151     ptr_ (p.release())
00152 {
00153 }

template<class X, class ACE_LOCK>
ACE_Strong_Bound_Ptr< X, ACE_LOCK >::ACE_Strong_Bound_Ptr const ACE_Strong_Bound_Ptr< X, ACE_LOCK > &    r [inline]
 

Copy constructor binds <this> and <r> to the same object.

Definition at line 156 of file Bound_Ptr.i.

00157   : counter_ (r.counter_),
00158     ptr_ (r.ptr_)
00159 {
00160   COUNTER::attach_strong (this->counter_);
00161 }

template<class X, class ACE_LOCK>
ACE_Strong_Bound_Ptr< X, ACE_LOCK >::ACE_Strong_Bound_Ptr const ACE_Weak_Bound_Ptr< X, ACE_LOCK > &    r [inline]
 

Constructor binds <this> and <r> to the same object.

Definition at line 164 of file Bound_Ptr.i.

References counter_, and ptr_.

00165   : counter_ (r.counter_),
00166     ptr_ (r.ptr_)
00167 {
00168   // When creating a strong pointer from a weak one we can't assume that the
00169   // underlying object still exists. Therefore we must check for a return value
00170   // of -1, which indicates that the object has been destroyed.
00171   if (COUNTER::attach_strong (this->counter_) == -1)
00172     {
00173       // Underlying object has already been deleted, so set this pointer to null.
00174       this->counter_ = COUNTER::create_strong ();
00175       this->ptr_ = 0;
00176     }
00177 }

template<class X, class ACE_LOCK>
ACE_Strong_Bound_Ptr< X, ACE_LOCK >::~ACE_Strong_Bound_Ptr void    [inline]
 

Destructor.

Definition at line 180 of file Bound_Ptr.i.

References ptr_.

00181 {
00182   if (COUNTER::detach_strong (this->counter_) == 0)
00183     delete this->ptr_;
00184 }


Member Function Documentation

template<class X, class ACE_LOCK>
X * ACE_Strong_Bound_Ptr< X, ACE_LOCK >::get void    [inline]
 

Get the pointer value.

Definition at line 275 of file Bound_Ptr.i.

References ptr_.

00276 {
00277   return this->ptr_;
00278 }

template<class X, class ACE_LOCK>
int ACE_Strong_Bound_Ptr< X, ACE_LOCK >::null void    const [inline]
 

Allows us to check for NULL on all ACE_Strong_Bound_Ptr objects.

Definition at line 281 of file Bound_Ptr.i.

References ptr_.

00282 {
00283   return this->ptr_ == 0;
00284 }

template<class X, class ACE_LOCK>
X & ACE_Strong_Bound_Ptr< X, ACE_LOCK >::operator * void    const [inline]
 

Dereference operator.

Definition at line 269 of file Bound_Ptr.i.

References ptr_.

00270 {
00271   return *this->ptr_;
00272 }

template<class X, class ACE_LOCK>
int ACE_Strong_Bound_Ptr< X, ACE_LOCK >::operator!= X *    p const [inline]
 

Inequality operator, which is the opposite of equality.

Definition at line 257 of file Bound_Ptr.i.

References ptr_.

00258 {
00259   return this->ptr_ != p;
00260 }

template<class X, class ACE_LOCK>
int ACE_Strong_Bound_Ptr< X, ACE_LOCK >::operator!= const ACE_Weak_Bound_Ptr< X, ACE_LOCK > &    r const [inline]
 

Inequality operator, which is the opposite of equality.

Definition at line 250 of file Bound_Ptr.i.

00251 {
00252   // Use the weak pointer's operator!= since it will check for null.
00253   return r != *this;
00254 }

template<class X, class ACE_LOCK>
int ACE_Strong_Bound_Ptr< X, ACE_LOCK >::operator!= const ACE_Strong_Bound_Ptr< X, ACE_LOCK > &    r const [inline]
 

Inequality operator, which is the opposite of equality.

Definition at line 244 of file Bound_Ptr.i.

References ptr_.

00245 {
00246   return this->ptr_ != r.ptr_;
00247 }

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

Redirection operator.

Definition at line 263 of file Bound_Ptr.i.

References ptr_.

00264 {
00265   return this->ptr_;
00266 }

template<class X, class ACE_LOCK>
void ACE_Strong_Bound_Ptr< X, ACE_LOCK >::operator= const ACE_Weak_Bound_Ptr< X, ACE_LOCK > &    r [inline]
 

Assignment operator that binds <this> and <r> to the same object.

Definition at line 201 of file Bound_Ptr.i.

References counter_, ACE_Weak_Bound_Ptr::counter_, ptr_, and ACE_Weak_Bound_Ptr::ptr_.

00202 {
00203   // This will work if &r == this, by first increasing the ref count
00204 
00205   COUNTER *new_counter = rhs.counter_;
00206   X* new_ptr = rhs.ptr_;
00207 
00208   // When creating a strong pointer from a weak one we can't assume that the
00209   // underlying object still exists. Therefore we must check for a return value
00210   // of -1, which indicates that the object has been destroyed.
00211   if (COUNTER::attach_strong (new_counter) == -1)
00212     {
00213       // Underlying object has already been deleted, so set this pointer to null.
00214       new_counter = COUNTER::create_strong ();
00215       new_ptr = 0;
00216     }
00217 
00218   if (COUNTER::detach_strong (this->counter_) == 0)
00219     delete this->ptr_;
00220   this->counter_ = new_counter;
00221   this->ptr_ = new_ptr;
00222 }

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

Assignment operator that binds <this> and <r> to the same object.

Definition at line 187 of file Bound_Ptr.i.

References counter_, and ptr_.

00188 {
00189   // This will work if &r == this, by first increasing the ref count
00190 
00191   COUNTER *new_counter = rhs.counter_;
00192   X* new_ptr = rhs.ptr_;
00193   COUNTER::attach_strong (new_counter);
00194   if (COUNTER::detach_strong (this->counter_) == 0)
00195     delete this->ptr_;
00196   this->counter_ = new_counter;
00197   this->ptr_ = new_ptr;
00198 }

template<class X, class ACE_LOCK>
int ACE_Strong_Bound_Ptr< X, ACE_LOCK >::operator== X *    p const [inline]
 

Equality operator that returns 1 if the ACE_Strong_Bound_Ptr and the raw pointer point to the same underlying object.

Definition at line 238 of file Bound_Ptr.i.

References ptr_.

00239 {
00240   return this->ptr_ == p;
00241 }

template<class X, class ACE_LOCK>
int ACE_Strong_Bound_Ptr< X, ACE_LOCK >::operator== const ACE_Weak_Bound_Ptr< X, ACE_LOCK > &    r const [inline]
 

Equality operator that returns 1 if the ACE_Strong_Bound_Ptr and ACE_Weak_Bound_Ptr objects point to the same underlying object.

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

Definition at line 231 of file Bound_Ptr.i.

00232 {
00233   // Use the weak pointer's operator== since it will check for null.
00234   return r == *this;
00235 }

template<class X, class ACE_LOCK>
int ACE_Strong_Bound_Ptr< X, ACE_LOCK >::operator== const ACE_Strong_Bound_Ptr< X, ACE_LOCK > &    r const [inline]
 

Equality operator that returns 1 if both ACE_Strong_Bound_Ptr instances point to the same underlying object.

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

Definition at line 225 of file Bound_Ptr.i.

References ptr_.

00226 {
00227   return this->ptr_ == r.ptr_;
00228 }

template<class X, class ACE_LOCK>
void ACE_Strong_Bound_Ptr< X, ACE_LOCK >::reset auto_ptr< X >    p [inline]
 

Resets the ACE_Strong_Bound_Ptr to refer to a different underlying object, ownership of which is stolen from the auto_ptr.

Definition at line 298 of file Bound_Ptr.i.

References counter_, ptr_, and ACE_Auto_Basic_Ptr::release.

00299 {
00300   COUNTER *old_counter = this->counter_;
00301   X* old_ptr = this->ptr_;
00302   this->counter_ = COUNTER::create_strong ();
00303   this->ptr_ = p.release ();
00304   if (COUNTER::detach_strong (old_counter) == 0)
00305     delete old_ptr;
00306 }

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

Resets the ACE_Strong_Bound_Ptr to refer to a different underlying object.

Definition at line 287 of file Bound_Ptr.i.

References counter_, and ptr_.

00288 {
00289   COUNTER *old_counter = this->counter_;
00290   X* old_ptr = this->ptr_;
00291   this->counter_ = COUNTER::create_strong ();
00292   this->ptr_ = p;
00293   if (COUNTER::detach_strong (old_counter) == 0)
00294     delete old_ptr;
00295 }


Friends And Related Function Documentation

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

Definition at line 191 of file Bound_Ptr.h.


Member Data Documentation

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

Declare the dynamic allocation hooks.

Definition at line 188 of file Bound_Ptr.h.

template<class X, class ACE_LOCK>
COUNTER* ACE_Strong_Bound_Ptr::counter_ [private]
 

The reference counter.

Definition at line 197 of file Bound_Ptr.h.

Referenced by ACE_Strong_Bound_Ptr, ACE_Weak_Bound_Ptr::operator=, operator=, and reset.

template<class X, class ACE_LOCK>
X* ACE_Strong_Bound_Ptr::ptr_ [private]
 

The underlying object.

Definition at line 200 of file Bound_Ptr.h.

Referenced by ACE_Strong_Bound_Ptr, get, null, operator *, ACE_Weak_Bound_Ptr::operator!=, operator!=, operator->, ACE_Weak_Bound_Ptr::operator=, operator=, ACE_Weak_Bound_Ptr::operator==, operator==, reset, and ~ACE_Strong_Bound_Ptr.


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