Public Types | Public Member Functions | Static Public Member Functions | Private Attributes

TAO::Utils::Servant_Var< T > Class Template Reference

Provides a type safe counted reference to servants. More...

#include <Servant_Var.h>

List of all members.

Public Types

typedef T Servant_Type

Public Member Functions

 Servant_Var (T *p=0)
 Constructor. Assumes ownership of p.
 Servant_Var (Servant_Var< T > const &rhs)
 Copy constructor. Adds reference to rhs.
Servant_Var< T > & operator= (Servant_Var< T > const &rhs)
 Assignment operator. Adds reference to rhs.
 ~Servant_Var () throw ()
Servant_Var< T > & operator= (T *p)
 Assignment operator. Assumes ownership of p.
template<class Y >
 Servant_Var (Y *p)
template<class Y >
 Servant_Var (Servant_Var< Y > const &rhs)
template<class Y >
Servant_Var< T > & operator= (Servant_Var< Y > const &rhs)
template<class Y >
Servant_Var< T > & operator= (Y *p)
T const * operator-> () const
 Smart pointer operator-> provides access to the underlying object.
T * operator-> ()
 Smart pointer operator-> provides access to the underlying object.
T const & operator* () const
 Dereference the underlying object.
T & operator* ()
 Dereference the underlying object.
 operator void const * () const
T * in () const
 As an IN parameter.
T *& inout ()
 As an INOUT parameter.
T *& out ()
 As an OUT parameter.
T * _retn ()
void swap (Servant_Var< T > &rhs) throw ()

Static Public Member Functions

static T * _duplicate (T *)
 Increment the reference count and return the servant.

Private Attributes

T * ptr_

Detailed Description

template<class T>
class TAO::Utils::Servant_Var< T >

Provides a type safe counted reference to servants.

Author:
Jody Hagins
Todo:
Life would be much easier if _add_ref() and _remove_ref() had throw specs of "throw ()", that can be hidden in static methods though.

Definition at line 46 of file Servant_Var.h.


Member Typedef Documentation

template<class T>
typedef T TAO::Utils::Servant_Var< T >::Servant_Type

Definition at line 49 of file Servant_Var.h.


Constructor & Destructor Documentation

template<class T >
TAO::Utils::Servant_Var< T >::Servant_Var ( T *  p = 0  ) 

Constructor. Assumes ownership of p.

Definition at line 29 of file Servant_Var.inl.

  : ptr_ (p)
{
}

template<class T >
TAO::Utils::Servant_Var< T >::Servant_Var ( Servant_Var< T > const &  rhs  ) 

Copy constructor. Adds reference to rhs.

Definition at line 37 of file Servant_Var.inl.

  : ptr_ (Servant_Var<T>::_duplicate(rhs.ptr_))
{
}

template<class T >
TAO::Utils::Servant_Var< T >::~Servant_Var ( void   )  throw ()

Destructor. Removes a reference from the underlying object, possibly destroying it.

Definition at line 69 of file Servant_Var.inl.

{
  if (ptr_ != 0)
    {
      ptr_->_remove_ref ();
    }
}

template<class T >
template<class Y >
TAO::Utils::Servant_Var< T >::Servant_Var ( Y *  p  ) 

Template member constructor from a pointer that will implicitly cast to type T. Assumes ownership of p. This constructor allows constructs such as: Servant_Base<Base> p(new Derived);

Definition at line 79 of file Servant_Var.inl.

  : ptr_ (p)
{
}

template<class T >
template<class Y >
TAO::Utils::Servant_Var< T >::Servant_Var ( Servant_Var< Y > const &  rhs  ) 

Template member copy constructor from a Servant_Var<Y>, where Y can be implicitly cast to type T.

Definition at line 85 of file Servant_Var.inl.

  : ptr_ (Servant_Var<T>::_duplicate (rhs.in ()))
{
}


Member Function Documentation

template<class T >
T * TAO::Utils::Servant_Var< T >::_duplicate ( T *  p  )  [static]

Increment the reference count and return the servant.

It is safe to pass in a null pointer, the pointer is simply returned in that case.

Todo:
We might want to add a throw spec and catch all (potential) exceptions in _add_ref()
Todo:
It might be useful to add an _release() method that handles any potential exceptions...

Definition at line 11 of file Servant_Var.inl.

{
  if (p != 0)
    {
      p->_add_ref ();
    }

  return p;
}

template<class T >
T * TAO::Utils::Servant_Var< T >::_retn ( void   ) 

Definition at line 175 of file Servant_Var.inl.

{
  T * rval = ptr_;
  ptr_ = 0;
  return rval;
}

template<class T >
T * TAO::Utils::Servant_Var< T >::in ( void   )  const

As an IN parameter.

Definition at line 152 of file Servant_Var.inl.

{
  return ptr_;
}

template<class T >
T *& TAO::Utils::Servant_Var< T >::inout ( void   ) 

As an INOUT parameter.

Definition at line 159 of file Servant_Var.inl.

{
  return ptr_;
}

template<class T >
TAO::Utils::Servant_Var< T >::operator void const * (  )  const

Return a void pointer to the underlying object. This allows it to be used in conditional code and tested against 0.

Definition at line 145 of file Servant_Var.inl.

{
  return ptr_;
}

template<class T >
T & TAO::Utils::Servant_Var< T >::operator* ( void   ) 

Dereference the underlying object.

Definition at line 139 of file Servant_Var.inl.

{
  return *ptr_;
}

template<class T >
T const & TAO::Utils::Servant_Var< T >::operator* ( void   )  const

Dereference the underlying object.

Definition at line 133 of file Servant_Var.inl.

{
  return *ptr_;
}

template<class T >
T const * TAO::Utils::Servant_Var< T >::operator-> ( void   )  const

Smart pointer operator-> provides access to the underlying object.

Definition at line 120 of file Servant_Var.inl.

{
  return ptr_;
}

template<class T >
T * TAO::Utils::Servant_Var< T >::operator-> ( void   ) 

Smart pointer operator-> provides access to the underlying object.

Definition at line 127 of file Servant_Var.inl.

{
  return ptr_;
}

template<class T >
template<class Y >
TAO::Utils::Servant_Var< T > & TAO::Utils::Servant_Var< T >::operator= ( Y *  p  ) 

Template member assignment operator from a pointer to Y, where Y can be implicitly cast to type T.

Definition at line 102 of file Servant_Var.inl.

{
  if (this->ptr_ != p)
    {
      // This constructor doesn't increase the reference count so we
      // we must check for self-assignment.  Otherwise the reference
      // count would be prematurely decremented upon exiting this
      // scope.
      TAO::Utils::Servant_Var<T> tmp (p);
      this->swap (tmp);
    }

  return *this;
}

template<class T >
TAO::Utils::Servant_Var< T > & TAO::Utils::Servant_Var< T >::operator= ( Servant_Var< T > const &  rhs  ) 

Assignment operator. Adds reference to rhs.

Definition at line 44 of file Servant_Var.inl.

{
  TAO::Utils::Servant_Var<T> tmp (rhs);
  this->swap (tmp);
  return *this;
}

template<class T >
TAO::Utils::Servant_Var< T > & TAO::Utils::Servant_Var< T >::operator= ( T *  p  ) 

Assignment operator. Assumes ownership of p.

Definition at line 53 of file Servant_Var.inl.

{
  if (this->ptr_ != p)
    {
      // This constructor doesn't increase the reference count so we
      // we must check for self-assignment.  Otherwise the reference
      // count would be prematurely decremented upon exiting this
      // scope.
      TAO::Utils::Servant_Var<T> tmp (p);
      this->swap (tmp);
    }

  return *this;
}

template<class T >
template<class Y >
TAO::Utils::Servant_Var< T > & TAO::Utils::Servant_Var< T >::operator= ( Servant_Var< Y > const &  rhs  ) 

Template member assignment operator from a Servant_Var<Y>, where Y can be implicitly cast to type T.

Definition at line 93 of file Servant_Var.inl.

{
  TAO::Utils::Servant_Var<T> tmp (rhs);
  this->swap (tmp);
  return *this;
}

template<class T >
T *& TAO::Utils::Servant_Var< T >::out ( void   ) 

As an OUT parameter.

Definition at line 166 of file Servant_Var.inl.

{
  TAO::Utils::Servant_Var<T> tmp;
  this->swap (tmp);
  return ptr_;
}

template<class T >
void TAO::Utils::Servant_Var< T >::swap ( Servant_Var< T > &  rhs  )  throw ()

Swap the contents of a Servant_Var<T> with another Servant_Var<T> Often used to implement strong exception safety.

Definition at line 23 of file Servant_Var.inl.

{
  std::swap (this->ptr_, rhs.ptr_);
}


Member Data Documentation

template<class T>
T* TAO::Utils::Servant_Var< T >::ptr_ [private]

Definition at line 141 of file Servant_Var.h.


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