00001 // -*- C++ -*- 00002 00003 //============================================================================= 00004 /** 00005 * @file Servant_Var.h 00006 * 00007 * $Id: Servant_Var.h 77151 2007-02-15 13:24:41Z johnnyw $ 00008 * 00009 * @author Jody Hagins <jody@atdesk.com> 00010 * @author Carlos O'Ryan <coryan@atdesk.com> 00011 * 00012 * @deprecated Use PortableServer::Servant_var instead. 00013 */ 00014 //============================================================================= 00015 00016 #ifndef TAO_UTILS_SERVANT_VAR_H 00017 #define TAO_UTILS_SERVANT_VAR_H 00018 #include /**/ "ace/pre.h" 00019 #include "ace/config-all.h" 00020 00021 #if !defined (ACE_LACKS_PRAGMA_ONCE) 00022 # pragma once 00023 #endif /* ACE_LACKS_PRAGMA_ONCE */ 00024 00025 #include "tao/orbconf.h" 00026 00027 TAO_BEGIN_VERSIONED_NAMESPACE_DECL 00028 00029 namespace TAO 00030 { 00031 namespace Utils 00032 { 00033 00034 /** 00035 * @class Servant_Var 00036 * 00037 * @brief Provides a type safe counted reference to servants. 00038 * 00039 * @author Jody Hagins 00040 * 00041 * @todo Life would be much easier if _add_ref() and _remove_ref() had 00042 * throw specs of "throw ()", that can be hidden in static 00043 * methods though. 00044 */ 00045 template<class T> 00046 class Servant_Var 00047 { 00048 public: 00049 typedef T Servant_Type; 00050 00051 /// Constructor. Assumes ownership of @c p. 00052 Servant_Var(T * p = 0); 00053 00054 /// Copy constructor. Adds reference to @c rhs. 00055 Servant_Var(Servant_Var<T> const & rhs); 00056 00057 /// Assignment operator. Adds reference to @c rhs. 00058 Servant_Var<T> & operator=(Servant_Var<T> const & rhs); 00059 00060 /// Destructor. Removes a reference from the underlying object, 00061 /// possibly destroying it. 00062 ~Servant_Var() throw (); 00063 00064 /// Assignment operator. Assumes ownership of @c p. 00065 Servant_Var<T> & operator=(T * p); 00066 00067 # if !defined(ACE_LACKS_MEMBER_TEMPLATES) 00068 /// Template member constructor from a pointer that will implicitly 00069 /// cast to type T. Assumes ownership of @c p. 00070 /// This constructor allows constructs such as: 00071 /// Servant_Base<Base> p(new Derived); 00072 template <class Y> 00073 Servant_Var(Y * p); 00074 00075 /// Template member copy constructor from a Servant_Var<Y>, where 00076 /// Y can be implicitly cast to type T. 00077 template <class Y> 00078 Servant_Var(Servant_Var<Y> const & rhs); 00079 00080 /// Template member assignment operator from a Servant_Var<Y>, where 00081 /// Y can be implicitly cast to type T. 00082 template <class Y> 00083 Servant_Var<T> & operator=(Servant_Var<Y> const & rhs); 00084 00085 /// Template member assignment operator from a pointer to Y, where Y 00086 /// can be implicitly cast to type T. 00087 template <class Y> 00088 Servant_Var<T> & operator=(Y * p); 00089 # endif /* ACE_LACKS_MEMBER_TEMPLATES */ 00090 00091 /// Smart pointer operator-> provides access to the underlying object. 00092 T const * operator->() const; 00093 00094 /// Smart pointer operator-> provides access to the underlying object. 00095 T * operator->(); 00096 00097 /// Dereference the underlying object. 00098 T const & operator*() const; 00099 00100 /// Dereference the underlying object. 00101 T & operator*(); 00102 00103 /// Return a void pointer to the underlying object. This allows 00104 /// it to be used in conditional code and tested against 0. 00105 operator void const * () const; 00106 00107 /// As an IN parameter. 00108 T * in() const; 00109 00110 /// As an INOUT parameter. 00111 T *& inout(); 00112 00113 /// As an OUT parameter. 00114 T *& out(); 00115 00116 // Return a pointer to the underlying object, and this counted 00117 // reference will no longer own the object. 00118 T * _retn(); 00119 00120 /// Increment the reference count and return the servant. 00121 /** 00122 * It is safe to pass in a null pointer, the pointer is simply 00123 * returned in that case. 00124 * 00125 * @todo We might want to add a throw spec and catch all (potential) 00126 * exceptions in _add_ref() 00127 * 00128 * @todo It might be useful to add an _release() method that handles 00129 * any potential exceptions... 00130 */ 00131 static T * _duplicate (T *); 00132 00133 /// Swap the contents of a Servant_Var<T> with another 00134 /// Servant_Var<T> 00135 /** 00136 * Often used to implement strong exception safety. 00137 */ 00138 void swap(Servant_Var<T> & rhs) throw (); 00139 00140 private: 00141 T * ptr_; 00142 }; 00143 00144 #ifndef ACE_LACKS_MEMBER_TEMPLATES 00145 /// Compare two Servant_Vars for equivalence. 00146 template <class X, class Y> 00147 bool operator==(Servant_Var<X> const & x, 00148 Servant_Var<Y> const & y); 00149 00150 /// Compare two Servant_Vars for non-equivalence. 00151 template <class X, class Y> 00152 bool operator!=(Servant_Var<X> const & x, 00153 Servant_Var<Y> const & y); 00154 #endif /* ! ACE_LACKS_MEMBER_TEMPLATES */ 00155 00156 } // namespace Utils 00157 } // namespace TAO 00158 00159 TAO_END_VERSIONED_NAMESPACE_DECL 00160 00161 #if defined (__ACE_INLINE__) 00162 # include "tao/Utils/Servant_Var.inl" 00163 #endif /* __ACE_INLINE__ */ 00164 00165 #if defined (ACE_TEMPLATES_REQUIRE_SOURCE) 00166 #include "tao/Utils/Servant_Var.cpp" 00167 #endif /* ACE_TEMPLATES_REQUIRE_SOURCE */ 00168 00169 #if defined (ACE_TEMPLATES_REQUIRE_PRAGMA) 00170 #pragma implementation ("Servant_Var.cpp") 00171 #endif 00172 00173 #include /**/ "ace/post.h" 00174 #endif /*TAO_UTILS_SERVANT_VAR_H*/