ACE_Strong_Bound_Ptr< X, ACE_LOCK > Class Template Reference

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

#include <Bound_Ptr.h>

Collaboration diagram for ACE_Strong_Bound_Ptr< X, ACE_LOCK >:

Collaboration graph
[legend]
List of all members.

Public Member Functions

 ACE_Strong_Bound_Ptr (X *p=0)
 ACE_Strong_Bound_Ptr (auto_ptr< X > p)
 ACE_Strong_Bound_Ptr (const ACE_Strong_Bound_Ptr< X, ACE_LOCK > &r)
 Copy constructor binds this and r to the same object.
 ACE_Strong_Bound_Ptr (const ACE_Weak_Bound_Ptr< X, ACE_LOCK > &r)
 Constructor binds this and r to the same object.
template<class Y>
 ACE_Strong_Bound_Ptr (const ACE_Strong_Bound_Ptr< Y, ACE_LOCK > &r)
 ~ACE_Strong_Bound_Ptr (void)
 Destructor.
void operator= (const ACE_Strong_Bound_Ptr< X, ACE_LOCK > &r)
 Assignment operator that binds this and r to the same object.
void operator= (const ACE_Weak_Bound_Ptr< X, ACE_LOCK > &r)
 Assignment operator that binds this and r to the same object.
template<class Y>
ACE_Weak_Bound_Ptr< X, ACE_LOCK > & operator= (const ACE_Strong_Bound_Ptr< Y, ACE_LOCK > &r)
bool operator== (const ACE_Strong_Bound_Ptr< X, ACE_LOCK > &r) const
bool operator== (const ACE_Weak_Bound_Ptr< X, ACE_LOCK > &r) const
bool operator== (X *p) const
bool operator!= (const ACE_Strong_Bound_Ptr< X, ACE_LOCK > &r) const
 Inequality operator, which is the opposite of equality.
bool operator!= (const ACE_Weak_Bound_Ptr< X, ACE_LOCK > &r) const
 Inequality operator, which is the opposite of equality.
bool operator!= (X *p) const
 Inequality operator, which is the opposite of equality.
X * operator-> (void) const
 Redirection operator.
X & operator * (void) const
 Dereference operator.
X * get (void) const
 Get the pointer value.
void reset (X *p=0)
void reset (auto_ptr< X > p)
int null (void) const

Public Attributes

 ACE_ALLOC_HOOK_DECLARE
 Declare the dynamic allocation hooks.

Private Types

typedef X X_t
typedef ACE_Bound_Ptr_Counter<
ACE_LOCK > 
COUNTER
 The ACE_Bound_Ptr_Counter type.

Private Attributes

COUNTERcounter_
 The reference counter.
X * ptr_
 The underlying object.

Friends

class ACE_Weak_Bound_Ptr< X, ACE_LOCK >
class ACE_Strong_Bound_Ptr

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 112 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< X, ACE_LOCK >::COUNTER [private]

The ACE_Bound_Ptr_Counter type.

Definition at line 240 of file Bound_Ptr.h.

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

Definition at line 232 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, explicit]

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

Definition at line 147 of file Bound_Ptr.inl.

00148   : counter_ (COUNTER::create_strong ()),
00149     ptr_ (p)
00150 {
00151 }

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

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

Definition at line 154 of file Bound_Ptr.inl.

00155   : counter_ (COUNTER::create_strong ()),
00156     ptr_ (p.release())
00157 {
00158 }

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 161 of file Bound_Ptr.inl.

References ACE_Bound_Ptr_Counter< ACE_LOCK >::attach_strong().

00162   : counter_ (r.counter_),
00163     ptr_ (r.ptr_)
00164 {
00165   COUNTER::attach_strong (this->counter_);
00166 }

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 169 of file Bound_Ptr.inl.

References ACE_Bound_Ptr_Counter< ACE_LOCK >::attach_strong(), ACE_Strong_Bound_Ptr< X, ACE_LOCK >::counter_, ACE_Bound_Ptr_Counter< ACE_LOCK >::create_strong(), and ACE_Strong_Bound_Ptr< X, ACE_LOCK >::ptr_.

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

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

Copy constructor binds this and r to the same object if Y* can be implicitly converted to X*.

Definition at line 132 of file Bound_Ptr.h.

References ACE_Bound_Ptr_Counter< ACE_LOCK >::attach_strong().

00133       : counter_ (r.counter_),
00134         ptr_ (dynamic_cast<X_t*>(r.ptr_))
00135   {
00136     // This ctor is temporarily defined here to increase our chances
00137     // of being accepted by broken compilers.
00138     //
00139     COUNTER::attach_strong (this->counter_);
00140   }

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

Destructor.

Definition at line 185 of file Bound_Ptr.inl.

References ACE_Bound_Ptr_Counter< ACE_LOCK >::detach_strong(), and ACE_Strong_Bound_Ptr< X, ACE_LOCK >::ptr_.

00186 {
00187   if (COUNTER::detach_strong (this->counter_) == 0)
00188     delete this->ptr_;
00189 }


Member Function Documentation

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

Get the pointer value.

Definition at line 286 of file Bound_Ptr.inl.

References ACE_Strong_Bound_Ptr< X, ACE_LOCK >::ptr_.

00287 {
00288   return this->ptr_;
00289 }

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 292 of file Bound_Ptr.inl.

References ACE_Strong_Bound_Ptr< X, ACE_LOCK >::ptr_.

00293 {
00294   return this->ptr_ == 0;
00295 }

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

Dereference operator.

Definition at line 280 of file Bound_Ptr.inl.

References ACE_Strong_Bound_Ptr< X, ACE_LOCK >::ptr_.

00281 {
00282   return *this->ptr_;
00283 }

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

Inequality operator, which is the opposite of equality.

Definition at line 268 of file Bound_Ptr.inl.

References ACE_Strong_Bound_Ptr< X, ACE_LOCK >::ptr_.

00269 {
00270   return this->ptr_ != p;
00271 }

template<class X, class ACE_LOCK>
bool 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 261 of file Bound_Ptr.inl.

00262 {
00263   // Use the weak pointer's operator!= since it will check for null.
00264   return r != *this;
00265 }

template<class X, class ACE_LOCK>
bool 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 255 of file Bound_Ptr.inl.

References ACE_Strong_Bound_Ptr< X, ACE_LOCK >::ptr_.

00256 {
00257   return this->ptr_ != r.ptr_;
00258 }

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

Redirection operator.

Definition at line 274 of file Bound_Ptr.inl.

References ACE_Strong_Bound_Ptr< X, ACE_LOCK >::ptr_.

00275 {
00276   return this->ptr_;
00277 }

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

Assignment operator that binds this and r to the same object if Y* can be implicitly converted to X*.

Definition at line 155 of file Bound_Ptr.h.

References ACE_Bound_Ptr_Counter< ACE_LOCK >::attach_strong(), ACE_Strong_Bound_Ptr< X, ACE_LOCK >::counter_, ACE_Bound_Ptr_Counter< ACE_LOCK >::detach_strong(), and ACE_Strong_Bound_Ptr< X, ACE_LOCK >::ptr_.

00156   {
00157     // This operator is temporarily defined here to increase our chances
00158     // of being accepted by broken compilers.
00159     //
00160 
00161     // This will work if &r == this, by first increasing the ref count
00162 
00163     COUNTER *new_counter = r.counter_;
00164     X* new_ptr = dynamic_cast<X_t*> (r.ptr_);
00165     COUNTER::attach_strong (new_counter);
00166     if (COUNTER::detach_strong (this->counter_) == 0)
00167       delete this->ptr_;
00168     this->counter_ = new_counter;
00169     this->ptr_ = new_ptr;
00170 
00171     return *this;
00172   }

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 209 of file Bound_Ptr.inl.

References ACE_Bound_Ptr_Counter< ACE_LOCK >::attach_strong(), ACE_Strong_Bound_Ptr< X, ACE_LOCK >::counter_, ACE_Weak_Bound_Ptr< X, ACE_LOCK >::counter_, ACE_Bound_Ptr_Counter< ACE_LOCK >::create_strong(), ACE_Bound_Ptr_Counter< ACE_LOCK >::detach_strong(), ACE_Strong_Bound_Ptr< X, ACE_LOCK >::ptr_, and ACE_Weak_Bound_Ptr< X, ACE_LOCK >::ptr_.

00210 {
00211   // This will work if &r == this, by first increasing the ref count, but
00212   // why go through all that?
00213   if (&rhs == this)
00214     return;
00215 
00216   COUNTER *new_counter = rhs.counter_;
00217   X_t *new_ptr = rhs.ptr_;
00218 
00219   // When creating a strong pointer from a weak one we can't assume that the
00220   // underlying object still exists. Therefore we must check for a return value
00221   // of -1, which indicates that the object has been destroyed.
00222   if (COUNTER::attach_strong (new_counter) == -1)
00223     {
00224       // Underlying object has already been deleted, so set this pointer to null.
00225       new_counter = COUNTER::create_strong ();
00226       new_ptr = 0;
00227     }
00228 
00229   if (COUNTER::detach_strong (this->counter_) == 0)
00230     delete this->ptr_;
00231   this->counter_ = new_counter;
00232   this->ptr_ = new_ptr;
00233 }

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 192 of file Bound_Ptr.inl.

References ACE_Bound_Ptr_Counter< ACE_LOCK >::attach_strong(), ACE_Strong_Bound_Ptr< X, ACE_LOCK >::counter_, ACE_Bound_Ptr_Counter< ACE_LOCK >::detach_strong(), and ACE_Strong_Bound_Ptr< X, ACE_LOCK >::ptr_.

00193 {
00194   // This will work if &r == this, by first increasing the ref count, but
00195   // why go through all that?
00196   if (&rhs == this)
00197     return;
00198 
00199   COUNTER *new_counter = rhs.counter_;
00200   X_t *new_ptr = rhs.ptr_;
00201   COUNTER::attach_strong (new_counter);
00202   if (COUNTER::detach_strong (this->counter_) == 0)
00203     delete this->ptr_;
00204   this->counter_ = new_counter;
00205   this->ptr_ = new_ptr;
00206 }

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

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

Definition at line 249 of file Bound_Ptr.inl.

References ACE_Strong_Bound_Ptr< X, ACE_LOCK >::ptr_.

00250 {
00251   return this->ptr_ == p;
00252 }

template<class X, class ACE_LOCK>
bool ACE_Strong_Bound_Ptr< X, ACE_LOCK >::operator== ( const ACE_Weak_Bound_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 242 of file Bound_Ptr.inl.

00243 {
00244   // Use the weak pointer's operator== since it will check for null.
00245   return r == *this;
00246 }

template<class X, class ACE_LOCK>
bool ACE_Strong_Bound_Ptr< X, ACE_LOCK >::operator== ( const ACE_Strong_Bound_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 236 of file Bound_Ptr.inl.

References ACE_Strong_Bound_Ptr< X, ACE_LOCK >::ptr_.

00237 {
00238   return this->ptr_ == r.ptr_;
00239 }

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 309 of file Bound_Ptr.inl.

References ACE_Strong_Bound_Ptr< X, ACE_LOCK >::counter_, ACE_Bound_Ptr_Counter< ACE_LOCK >::create_strong(), ACE_Bound_Ptr_Counter< ACE_LOCK >::detach_strong(), ACE_Strong_Bound_Ptr< X, ACE_LOCK >::ptr_, and ACE_Auto_Basic_Ptr< X >::release().

00310 {
00311   COUNTER *old_counter = this->counter_;
00312   X_t *old_ptr = this->ptr_;
00313   this->counter_ = COUNTER::create_strong ();
00314   this->ptr_ = p.release ();
00315   if (COUNTER::detach_strong (old_counter) == 0)
00316     delete old_ptr;
00317 }

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 298 of file Bound_Ptr.inl.

References ACE_Strong_Bound_Ptr< X, ACE_LOCK >::counter_, ACE_Bound_Ptr_Counter< ACE_LOCK >::create_strong(), ACE_Bound_Ptr_Counter< ACE_LOCK >::detach_strong(), and ACE_Strong_Bound_Ptr< X, ACE_LOCK >::ptr_.

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


Friends And Related Function Documentation

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

Definition at line 237 of file Bound_Ptr.h.

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

Definition at line 234 of file Bound_Ptr.h.


Member Data Documentation

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

Declare the dynamic allocation hooks.

Definition at line 229 of file Bound_Ptr.h.

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

The reference counter.

Definition at line 243 of file Bound_Ptr.h.

Referenced by ACE_Strong_Bound_Ptr< X, ACE_LOCK >::ACE_Strong_Bound_Ptr(), ACE_Weak_Bound_Ptr< X, ACE_LOCK >::operator=(), ACE_Strong_Bound_Ptr< X, ACE_LOCK >::operator=(), and ACE_Strong_Bound_Ptr< X, ACE_LOCK >::reset().

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

The underlying object.

Definition at line 246 of file Bound_Ptr.h.

Referenced by ACE_Strong_Bound_Ptr< X, ACE_LOCK >::ACE_Strong_Bound_Ptr(), ACE_Strong_Bound_Ptr< X, ACE_LOCK >::get(), ACE_Strong_Bound_Ptr< X, ACE_LOCK >::null(), ACE_Strong_Bound_Ptr< X, ACE_LOCK >::operator *(), ACE_Weak_Bound_Ptr< X, ACE_LOCK >::operator!=(), ACE_Strong_Bound_Ptr< X, ACE_LOCK >::operator!=(), ACE_Strong_Bound_Ptr< X, ACE_LOCK >::operator->(), ACE_Weak_Bound_Ptr< X, ACE_LOCK >::operator=(), ACE_Strong_Bound_Ptr< X, ACE_LOCK >::operator=(), ACE_Weak_Bound_Ptr< X, ACE_LOCK >::operator==(), ACE_Strong_Bound_Ptr< X, ACE_LOCK >::operator==(), ACE_Strong_Bound_Ptr< X, ACE_LOCK >::reset(), and ACE_Strong_Bound_Ptr< X, ACE_LOCK >::~ACE_Strong_Bound_Ptr().


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