Servant_var.h

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

Generated on Tue Feb 2 17:40:54 2010 for TAO_PortableServer by  doxygen 1.4.7