This class implements support for a reference counted pointer. More...
#include <Bound_Ptr.h>

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) |
| bool | 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 | |
| COUNTER * | counter_ |
| The reference counter. | |
| X * | ptr_ |
| The underlying object. | |
Friends | |
| class | ACE_Weak_Bound_Ptr< X, ACE_LOCK > |
| class | ACE_Strong_Bound_Ptr |
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.
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.
typedef X ACE_Strong_Bound_Ptr< X, ACE_LOCK >::X_t [private] |
Definition at line 232 of file Bound_Ptr.h.
| 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.
: counter_ (COUNTER::create_strong ()), ptr_ (p) { }
| 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.
: counter_ (COUNTER::create_strong ()), ptr_ (p.release()) { }
| 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.
| 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.
: counter_ (r.counter_), ptr_ (r.ptr_) { // When creating a strong pointer from a weak one we can't assume that the // underlying object still exists. Therefore we must check for a return value // of -1, which indicates that the object has been destroyed. if (COUNTER::attach_strong (this->counter_) == -1) { // Underlying object has already been deleted, so set this pointer to null. this->counter_ = COUNTER::create_strong (); this->ptr_ = 0; } }
| 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.
| ACE_Strong_Bound_Ptr< X, ACE_LOCK >::~ACE_Strong_Bound_Ptr | ( | void | ) | [inline] |
Destructor.
Definition at line 185 of file Bound_Ptr.inl.
{
if (COUNTER::detach_strong (this->counter_) == 0)
delete this->ptr_;
}
| X * ACE_Strong_Bound_Ptr< X, ACE_LOCK >::get | ( | void | ) | const [inline] |
| bool 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.
{
return this->ptr_ == 0;
}
| 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.
{
// Use the weak pointer's operator!= since it will check for null.
return r != *this;
}
| 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.
{
return this->ptr_ != p;
}
| 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.
| X & ACE_Strong_Bound_Ptr< X, ACE_LOCK >::operator* | ( | void | ) | const [inline] |
| X * ACE_Strong_Bound_Ptr< X, ACE_LOCK >::operator-> | ( | void | ) | const [inline] |
| 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.
{
// This will work if &r == this, by first increasing the ref count, but
// why go through all that?
if (&rhs == this)
return;
COUNTER *new_counter = rhs.counter_;
X_t *new_ptr = rhs.ptr_;
// When creating a strong pointer from a weak one we can't assume that the
// underlying object still exists. Therefore we must check for a return value
// of -1, which indicates that the object has been destroyed.
if (COUNTER::attach_strong (new_counter) == -1)
{
// Underlying object has already been deleted, so set this pointer to null.
new_counter = COUNTER::create_strong ();
new_ptr = 0;
}
if (COUNTER::detach_strong (this->counter_) == 0)
delete this->ptr_;
this->counter_ = new_counter;
this->ptr_ = new_ptr;
}
| 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.
{
// This will work if &r == this, by first increasing the ref count, but
// why go through all that?
if (&rhs == this)
return;
COUNTER *new_counter = rhs.counter_;
X_t *new_ptr = rhs.ptr_;
COUNTER::attach_strong (new_counter);
if (COUNTER::detach_strong (this->counter_) == 0)
delete this->ptr_;
this->counter_ = new_counter;
this->ptr_ = new_ptr;
}
| 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.
{
// This operator is temporarily defined here to increase our chances
// of being accepted by broken compilers.
//
// This will work if &r == this, by first increasing the ref count
COUNTER *new_counter = r.counter_;
X* new_ptr = dynamic_cast<X_t*> (r.ptr_);
COUNTER::attach_strong (new_counter);
if (COUNTER::detach_strong (this->counter_) == 0)
delete this->ptr_;
this->counter_ = new_counter;
this->ptr_ = new_ptr;
return *this;
}
| bool ACE_Strong_Bound_Ptr< X, ACE_LOCK >::operator== | ( | const ACE_Strong_Bound_Ptr< X, ACE_LOCK > & | r | ) | const [inline] |
Equality operator that returns true if both ACE_Strong_Bound_Ptr instances point to the same underlying object.
true if both objects have just been instantiated and not used yet. Definition at line 236 of file Bound_Ptr.inl.
| bool ACE_Strong_Bound_Ptr< X, ACE_LOCK >::operator== | ( | const ACE_Weak_Bound_Ptr< X, ACE_LOCK > & | r | ) | const [inline] |
Equality operator that returns true if the ACE_Strong_Bound_Ptr and ACE_Weak_Bound_Ptr objects point to the same underlying object.
true if both objects have just been instantiated and not used yet. Definition at line 242 of file Bound_Ptr.inl.
{
// Use the weak pointer's operator== since it will check for null.
return r == *this;
}
| 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.
{
return this->ptr_ == p;
}
| 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.
{
COUNTER *old_counter = this->counter_;
X_t *old_ptr = this->ptr_;
this->counter_ = COUNTER::create_strong ();
this->ptr_ = p.release ();
if (COUNTER::detach_strong (old_counter) == 0)
delete old_ptr;
}
| 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.
{
COUNTER *old_counter = this->counter_;
X_t *old_ptr = this->ptr_;
this->counter_ = COUNTER::create_strong ();
this->ptr_ = p;
if (COUNTER::detach_strong (old_counter) == 0)
delete old_ptr;
}
friend class ACE_Strong_Bound_Ptr [friend] |
Definition at line 237 of file Bound_Ptr.h.
friend class ACE_Weak_Bound_Ptr< X, ACE_LOCK > [friend] |
Definition at line 234 of file Bound_Ptr.h.
| 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.
COUNTER* ACE_Strong_Bound_Ptr< X, ACE_LOCK >::counter_ [private] |
The reference counter.
Definition at line 243 of file Bound_Ptr.h.
X* ACE_Strong_Bound_Ptr< X, ACE_LOCK >::ptr_ [private] |
The underlying object.
Definition at line 246 of file Bound_Ptr.h.
1.7.0