PortableServer::Servant_var< T > Class Template Reference

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

#include <Servant_var.h>

Collaboration diagram for PortableServer::Servant_var< T >:

Collaboration graph
[legend]
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 (void)
Servant_var< T > & operator= (T *p)
 Assignment operator. Assumes ownership of p.
T * operator-> () const
 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)

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 PortableServer::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 41 of file Servant_var.h.


Member Typedef Documentation

template<class T>
typedef T PortableServer::Servant_var< T >::servant_type

Definition at line 44 of file Servant_var.h.


Constructor & Destructor Documentation

template<class T>
ACE_INLINE PortableServer::Servant_var< T >::Servant_var ( T *  p = 0  ) 

Constructor. Assumes ownership of p.

Definition at line 18 of file Servant_var.inl.

00019   : ptr_ (p)
00020 {
00021 }

template<class T>
ACE_INLINE PortableServer::Servant_var< T >::Servant_var ( Servant_var< T > const &  rhs  ) 

Copy constructor. Adds reference to rhs.

Definition at line 27 of file Servant_var.inl.

00028   : ptr_ (Servant_var<T>::_duplicate(rhs.ptr_))
00029 {
00030 }

template<class T>
PortableServer::Servant_var< T >::~Servant_var ( void   ) 

This destructor doesn't throw exceptions.

Definition at line 36 of file Servant_var.cpp.

References PortableServer::Servant_var< T >::ptr_.

00037 {
00038   // Unfortunately, there is no throw spec on _remove_ref, so we
00039   // can't assume that it will not throw.  If it does, then we are in
00040   // trouble.  In any event, we can't let the exception escape our
00041   // destructor.
00042   try
00043     {
00044       if (this->ptr_ != 0)
00045         {
00046           this->ptr_->_remove_ref ();
00047         }
00048     }
00049   catch (...)
00050     {
00051       // Forget the exception..
00052     }
00053 }


Member Function Documentation

template<class T>
TAO_BEGIN_VERSIONED_NAMESPACE_DECL T * PortableServer::Servant_var< T >::_duplicate ( T *   )  [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 catch all (potential) exceptions in _add_ref().
Todo:
It might be useful to add a _release() method that handles any potential exceptions...

Definition at line 18 of file Servant_var.cpp.

00019 {
00020   try
00021     {
00022       if (p != 0)
00023         {
00024           p->_add_ref ();
00025         }
00026     }
00027   catch (...)
00028     {
00029       throw;
00030     }
00031 
00032   return p;
00033 }

template<class T>
ACE_INLINE T * PortableServer::Servant_var< T >::_retn (  ) 

Return a pointer to the underlying object, and this counted reference will no longer own the object.

Definition at line 154 of file Servant_var.inl.

References PortableServer::Servant_var< T >::ptr_.

00155 {
00156   T * const rval = ptr_;
00157   this->ptr_ = 0;
00158   return rval;
00159 }

template<class T>
ACE_INLINE T * PortableServer::Servant_var< T >::in (  )  const

As an IN parameter.

Definition at line 131 of file Servant_var.inl.

References PortableServer::Servant_var< T >::ptr_.

Referenced by TAO::Portable_Server::RequestProcessingStrategyDefaultServant::get_servant(), TAO::Portable_Server::RequestProcessingStrategyDefaultServant::id_to_servant(), TAO::Portable_Server::RequestProcessingStrategyDefaultServant::locate_servant(), TAO::Portable_Server::RequestProcessingStrategyDefaultServant::servant_to_id(), and TAO::Portable_Server::RequestProcessingStrategyDefaultServant::system_id_to_servant().

00132 {
00133   return this->ptr_;
00134 }

template<class T>
ACE_INLINE T *& PortableServer::Servant_var< T >::inout (  ) 

As an INOUT parameter.

Definition at line 138 of file Servant_var.inl.

References PortableServer::Servant_var< T >::ptr_.

00139 {
00140   return this->ptr_;
00141 }

template<class T>
ACE_INLINE T & PortableServer::Servant_var< T >::operator * (  ) 

Dereference the underlying object.

Definition at line 118 of file Servant_var.inl.

References PortableServer::Servant_var< T >::ptr_.

00119 {
00120   return *this->ptr_;
00121 }

template<class T>
ACE_INLINE T const & PortableServer::Servant_var< T >::operator * (  )  const

Dereference the underlying object.

Definition at line 111 of file Servant_var.inl.

References PortableServer::Servant_var< T >::ptr_.

00112 {
00113   return *this->ptr_;
00114 }

template<class T>
ACE_INLINE PortableServer::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 124 of file Servant_var.inl.

References PortableServer::Servant_var< T >::ptr_.

00125 {
00126   return this->ptr_;
00127 }

template<class T>
ACE_INLINE T * PortableServer::Servant_var< T >::operator-> (  )  const

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

@ Ciju: The below member templates was commented out because: 1. gcc 2.95 doesn't support them. 2. Sun cc 5.8 member templates support is buggy (Bug Id: 6463114).

Once these have been fixed a decision can be made regards uncommenting them. My own openion is that they shouldn't be used since making implicit constructors, member templates, you could potentially get an unwanted conversion where one was unwarranted.

Definition at line 104 of file Servant_var.inl.

References PortableServer::Servant_var< T >::ptr_.

00105 {
00106   return this->ptr_;
00107 }

template<class T>
ACE_INLINE PortableServer::Servant_var< T > & PortableServer::Servant_var< T >::operator= ( T *  p  ) 

Assignment operator. Assumes ownership of p.

Definition at line 43 of file Servant_var.inl.

References PortableServer::Servant_var< T >::swap().

00044 {
00045   if (this->ptr_ != p)
00046     {
00047       // This constructor doesn't increase the reference count, nor is
00048       // it a copy constructor, so we must check for self-assignment.
00049       // Otherwise the reference count would be prematurely
00050       // decremented upon exiting this scope.
00051       PortableServer::Servant_var<T> tmp (p);
00052       this->swap (tmp);
00053     }
00054 
00055   return *this;
00056 }

template<class T>
ACE_INLINE PortableServer::Servant_var< T > & PortableServer::Servant_var< T >::operator= ( Servant_var< T > const &  rhs  ) 

Assignment operator. Adds reference to rhs.

Definition at line 34 of file Servant_var.inl.

References PortableServer::Servant_var< T >::swap().

00035 {
00036   PortableServer::Servant_var<T> tmp (rhs);
00037   this->swap (tmp);
00038   return *this;
00039 }

template<class T>
ACE_INLINE T *& PortableServer::Servant_var< T >::out (  ) 

As an OUT parameter.

Definition at line 145 of file Servant_var.inl.

References PortableServer::Servant_var< T >::ptr_, and PortableServer::Servant_var< T >::swap().

00146 {
00147   PortableServer::Servant_var<T> tmp;
00148   this->swap (tmp);
00149   return this->ptr_;
00150 }

template<class T>
TAO_BEGIN_VERSIONED_NAMESPACE_DECL ACE_INLINE void PortableServer::Servant_var< T >::swap ( Servant_var< T > &  rhs  ) 

Non-throwing swap operation. Often used to implement strong exception safety.

Definition at line 11 of file Servant_var.inl.

References PortableServer::Servant_var< T >::ptr_.

Referenced by PortableServer::Servant_var< T >::operator=(), and PortableServer::Servant_var< T >::out().

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


Member Data Documentation

template<class T>
T* PortableServer::Servant_var< T >::ptr_ [private]

Definition at line 150 of file Servant_var.h.

Referenced by PortableServer::Servant_var< T >::_retn(), PortableServer::Servant_var< T >::in(), PortableServer::Servant_var< T >::inout(), PortableServer::Servant_var< T >::operator *(), PortableServer::Servant_var< T >::operator void const *(), PortableServer::Servant_var< T >::operator->(), PortableServer::Servant_var< T >::out(), PortableServer::Servant_var< T >::swap(), and PortableServer::Servant_var< T >::~Servant_var().


The documentation for this class was generated from the following files:
Generated on Tue Feb 2 17:41:37 2010 for TAO_PortableServer by  doxygen 1.4.7