3 //=============================================================================
7 * @author Jody Hagins <jody@atdesk.com>
8 * @author Carlos O'Ryan <coryan@atdesk.com>
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)
19 #endif /* ACE_LACKS_PRAGMA_ONCE */
21 #include "tao/orbconf.h"
23 TAO_BEGIN_VERSIONED_NAMESPACE_DECL
25 namespace PortableServer
30 * @brief Provides a type safe counted reference to servants.
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
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.
56 * This destructor doesn't throw exceptions.
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.
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.
79 /// As an INOUT parameter.
82 /// As an OUT parameter.
85 /// Return a pointer to the underlying object, and this counted
86 /// reference will no longer own the object.
89 /// Increment the reference count and return the servant.
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
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
105 * Non-throwing swap operation.
106 * Often used to implement strong exception safety.
108 void swap (Servant_var
<T
> & rhs
);
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 */