Revert "Minor modernization of DynamicAny code"
[ACE_TAO.git] / TAO / tao / PortableServer / Servant_var.h
blobd2215dcf05117ed5646366a0014d1d5061198130
1 // -*- C++ -*-
3 //=============================================================================
4 /**
5 * @file Servant_var.h
7 * @author Jody Hagins <jody@atdesk.com>
8 * @author Carlos O'Ryan <coryan@atdesk.com>
9 */
10 //=============================================================================
12 #ifndef TAO_PORTABLESERVER_SERVANT_VAR_H
13 #define TAO_PORTABLESERVER_SERVANT_VAR_H
14 #include /**/ "ace/pre.h"
15 #include "ace/config-all.h"
17 #if !defined (ACE_LACKS_PRAGMA_ONCE)
18 # pragma once
19 #endif /* ACE_LACKS_PRAGMA_ONCE */
21 #include "tao/orbconf.h"
23 TAO_BEGIN_VERSIONED_NAMESPACE_DECL
25 namespace PortableServer
27 /**
28 * @class Servant_var
30 * @brief Provides a type safe counted reference to servants.
32 * @author Jody Hagins
34 * @todo Life would be much easier if _add_ref() and _remove_ref() had
35 * throw specs of "noexcept", that can be hidden in static
36 * methods though.
38 template<class T>
39 class Servant_var
41 public:
42 typedef T servant_type;
44 /// Constructor. Assumes ownership of @c p.
45 Servant_var (T * p = 0);
47 /// Copy constructor. Adds reference to @c rhs.
48 Servant_var (Servant_var<T> const & rhs);
50 /// Assignment operator. Adds reference to @c rhs.
51 Servant_var<T> & operator= (Servant_var<T> const & rhs);
53 /// Destructor. Removes a reference from the underlying object,
54 /// possibly destroying it.
55 /**
56 * This destructor doesn't throw exceptions.
58 ~Servant_var ();
60 /// Assignment operator. Assumes ownership of @c p.
61 Servant_var<T> & operator= (T * p);
63 /// Smart pointer operator-> provides access to the underlying object.
64 T * operator->() const;
66 /// Dereference the underlying object.
67 T const & operator*() const;
69 /// Dereference the underlying object.
70 T & operator*();
72 /// Return a void pointer to the underlying object. This allows
73 /// it to be used in conditional code and tested against 0.
74 operator void const * () const;
76 /// As an IN parameter.
77 T * in() const;
79 /// As an INOUT parameter.
80 T *& inout();
82 /// As an OUT parameter.
83 T *& out();
85 /// Return a pointer to the underlying object, and this counted
86 /// reference will no longer own the object.
87 T * _retn();
89 /// Increment the reference count and return the servant.
90 /**
91 * It is safe to pass in a null pointer, the pointer is simply
92 * returned in that case.
94 * @todo We might want to catch all (potential) exceptions in
95 * _add_ref().
97 * @todo It might be useful to add a _release() method that handles
98 * any potential exceptions...
100 static T * _duplicate (T *);
102 /// Swap the contents of a Servant_var<T> with another
103 /// Servant_var<T>
105 * Non-throwing swap operation.
106 * Often used to implement strong exception safety.
108 void swap (Servant_var<T> & rhs);
110 private:
111 T * ptr_;
114 /// Compare two Servant_vars for equivalence.
115 template <class X, class Y>
116 bool operator==(Servant_var<X> const & x, Servant_var<Y> const & y);
118 /// Compare two Servant_vars for non-equivalence.
119 template <class X, class Y>
120 bool operator!=(Servant_var<X> const & x, Servant_var<Y> const & y);
121 } // namespace PortableServer
123 TAO_END_VERSIONED_NAMESPACE_DECL
125 #if defined (__ACE_INLINE__)
126 # include "tao/PortableServer/Servant_var.inl"
127 #endif /* __ACE_INLINE__ */
129 #include "tao/PortableServer/Servant_var.cpp"
131 #include /**/ "ace/post.h"
132 #endif /* TAO_PORTABLESERVER_SERVANT_VAR_H */