Public Member Functions | Public Attributes | Protected Types | Static Protected Member Functions | Protected Attributes

ACE_Intrusive_Auto_Ptr< X > Class Template Reference

This class implements support for a reference counted auto_ptr. It assumes reference counting abilities of the parameterizing class. More...

#include <Intrusive_Auto_Ptr.h>

Collaboration diagram for ACE_Intrusive_Auto_Ptr< X >:
Collaboration graph
[legend]

List of all members.

Public Member Functions

 operator unspecified_bool_type () const
 Enables "if (sp) ...".
 ACE_Intrusive_Auto_Ptr (X *p=0, bool addref=true)
 ACE_Intrusive_Auto_Ptr (const ACE_Intrusive_Auto_Ptr< X > &r)
template<class U >
 ACE_Intrusive_Auto_Ptr (const ACE_Intrusive_Auto_Ptr< U > &rhs)
virtual ~ACE_Intrusive_Auto_Ptr (void)
void operator= (const ACE_Intrusive_Auto_Ptr< X > &r)
X * operator-> (void) const
 Redirection operator.
X & operator* () const
 Accessor method.
X * release (void)
void reset (X *p=0)
X * get (void) const
 Get the pointer value.
long count (void) const
 Get the reference count value.

Public Attributes

 ACE_ALLOC_HOOK_DECLARE
 Returns true if this object does not contain a valid pointer.

Protected Types

typedef void(* unspecified_bool_type )(ACE_Intrusive_Auto_Ptr< X > ***)

Static Protected Member Functions

static void unspecified_bool (ACE_Intrusive_Auto_Ptr< X > ***)
 Used to define a proper boolean conversion for "if (sp) ...".

Protected Attributes

X * rep_
 Protect operations on the ACE_Intrusive_Auto_Ptr.

Detailed Description

template<class X>
class ACE_Intrusive_Auto_Ptr< X >

This class implements support for a reference counted auto_ptr. It assumes reference counting abilities of the parameterizing class.

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

The ACE_Intrusive_Auto_Ptr works by maintaining a reference to a separate representation object, ACE_Intrusive_Auto_Ptr_Rep. That separate representation object contains the reference count and the actual pointer value.

Definition at line 50 of file Intrusive_Auto_Ptr.h.


Member Typedef Documentation

template<class X>
typedef void(* ACE_Intrusive_Auto_Ptr< X >::unspecified_bool_type)(ACE_Intrusive_Auto_Ptr< X > ***) [protected]

Definition at line 56 of file Intrusive_Auto_Ptr.h.


Constructor & Destructor Documentation

template<class X>
ACE_Intrusive_Auto_Ptr< X >::ACE_Intrusive_Auto_Ptr ( X *  p = 0,
bool  addref = true 
) [inline]

Constructor that initializes an ACE_Intrusive_Auto_Ptr to the specified pointer value.

Definition at line 11 of file Intrusive_Auto_Ptr.inl.

  : rep_ (p)
{
  if (rep_ != 0  && addref)
    X::intrusive_add_ref (rep_);
}

template<class X>
ACE_Intrusive_Auto_Ptr< X >::ACE_Intrusive_Auto_Ptr ( const ACE_Intrusive_Auto_Ptr< X > &  r  )  [inline]

Copy constructor binds the new ACE_Intrusive_Auto_Ptr to the representation object referenced by r. An ACE_Intrusive_Auto_Ptr_Rep is created if necessary.

Definition at line 19 of file Intrusive_Auto_Ptr.inl.

  : rep_ (r.rep_)
{
  if (rep_ != 0)
    X::intrusive_add_ref (rep_);
}

template<class X >
template<class U >
ACE_Intrusive_Auto_Ptr< X >::ACE_Intrusive_Auto_Ptr ( const ACE_Intrusive_Auto_Ptr< U > &  rhs  )  [inline]

Definition at line 100 of file Intrusive_Auto_Ptr.inl.

{
  // note implicit cast from U* to T* so illegal copy will generate a
  // compiler warning here
  this->rep_ = rhs.operator-> ();
  X::intrusive_add_ref(this->rep_);
}

template<class X >
ACE_Intrusive_Auto_Ptr< X >::~ACE_Intrusive_Auto_Ptr ( void   )  [virtual]

Destructor. Releases the reference to the underlying representation. If the release of that reference causes its reference count to reach 0, the representation object will also be destroyed.

Definition at line 15 of file Intrusive_Auto_Ptr.cpp.

{
  reset (0);
}


Member Function Documentation

template<class X>
long ACE_Intrusive_Auto_Ptr< X >::count ( void   )  const

Get the reference count value.

template<class X >
X * ACE_Intrusive_Auto_Ptr< X >::get ( void   )  const [inline]

Get the pointer value.

Definition at line 39 of file Intrusive_Auto_Ptr.inl.

{
  // We return the ACE_Future_rep.
  return this->rep_;
}

template<class X>
ACE_Intrusive_Auto_Ptr< X >::operator unspecified_bool_type (  )  const [inline]

Enables "if (sp) ...".

Definition at line 61 of file Intrusive_Auto_Ptr.h.

    {
        return rep_ == 0 ? 0: unspecified_bool;
    }

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

Accessor method.

Definition at line 33 of file Intrusive_Auto_Ptr.inl.

{
  return *this->rep_;
}

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

Redirection operator.

Definition at line 27 of file Intrusive_Auto_Ptr.inl.

{
    return this->rep_;
}

template<class X>
void ACE_Intrusive_Auto_Ptr< X >::operator= ( const ACE_Intrusive_Auto_Ptr< X > &  r  )  [inline]

Assignment operator that binds the current object and r to the same ACE_Intrusive_Auto_Ptr_Rep. An ACE_Intrusive_Auto_Ptr_Rep is created if necessary.

Definition at line 77 of file Intrusive_Auto_Ptr.inl.

{
  // do nothing when aliasing
  if (this->rep_ == rhs.rep_)
    return;

  // assign a zero
  if (rhs.rep_  == 0)
    {
      X::intrusive_remove_ref (rhs.rep_);
      this->rep_ = 0;
      return;
    }

  //  bind <this> to the same <ACE_Intrusive_Auto_Ptr_Rep> as <rhs>.
  X *old_rep = this->rep_;
  this->rep_ = rhs.rep_;
  X::intrusive_add_ref (this->rep_);
  X::intrusive_remove_ref (old_rep);
}

template<class X >
X * ACE_Intrusive_Auto_Ptr< X >::release ( void   )  [inline]

Releases the reference to the underlying representation object.

Return values:
The pointer value prior to releasing it.

Definition at line 46 of file Intrusive_Auto_Ptr.inl.

{
  X *p = this->rep_;
  if (this->rep_ != 0)
    X::intrusive_remove_ref (this->rep_);

  this->rep_ = 0;
  return p;
}

template<class X>
void ACE_Intrusive_Auto_Ptr< X >::reset ( X *  p = 0  )  [inline]

Releases the current pointer value and then sets a new pointer value specified by p.

Definition at line 57 of file Intrusive_Auto_Ptr.inl.

{
  // Avoid deleting the underlying auto_ptr if assigning the same actual
  // pointer value.
  if (this->rep_ == p)
    return;

  X *old_rep = this->rep_;
  this->rep_ = p;

  if (this->rep_ != 0)
    X::intrusive_add_ref (this->rep_);

  if (old_rep != 0)
    X::intrusive_remove_ref (old_rep);

  return;
}

template<class X>
static void ACE_Intrusive_Auto_Ptr< X >::unspecified_bool ( ACE_Intrusive_Auto_Ptr< X > ***   )  [inline, static, protected]

Used to define a proper boolean conversion for "if (sp) ...".

Definition at line 55 of file Intrusive_Auto_Ptr.h.

{};


Member Data Documentation

Returns true if this object does not contain a valid pointer.

Declare the dynamic allocation hooks.

Definition at line 115 of file Intrusive_Auto_Ptr.h.

template<class X>
X* ACE_Intrusive_Auto_Ptr< X >::rep_ [protected]

Protect operations on the ACE_Intrusive_Auto_Ptr.

Definition at line 120 of file Intrusive_Auto_Ptr.h.


The documentation for this class was generated from the following files:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines