Revert "Minor modernization of DynamicAny code"
[ACE_TAO.git] / TAO / tao / Transport_Selection_Guard.h
blobd33a8469d776cf9bfb3f01f701d298cc7acb5d37
1 // -*- C++ -*-
3 // ===================================================================
4 /**
5 * @file Transport_Selection_Guard.h
7 * @author Iliyan Jeliazkov <iliyan@ociweb.com>
8 */
9 // ===================================================================
11 #ifndef TAO_TRANSPORT_SELECTION_GUARD_H
12 #define TAO_TRANSPORT_SELECTION_GUARD_H
14 #include /**/ "ace/pre.h"
16 #include "tao/TAO_Export.h"
18 #if !defined (ACE_LACKS_PRAGMA_ONCE)
19 # pragma once
20 #endif /* ACE_LACKS_PRAGMA_ONCE */
22 #include "tao/orbconf.h"
24 TAO_BEGIN_VERSIONED_NAMESPACE_DECL
26 // Forward declarations
27 class TAO_Transport;
28 class TAO_ORB_Core;
30 namespace TAO
32 /**
33 * @class Transport_Selection_Guard
35 * @brief Used by the Transport Current feature to keep track of
36 * which Transport is currently active.
38 * Whenever a Transport is selected: during an upcall, or prior to a
39 * client invocation an instance of this class is created [on the
40 * stack, or as a member of another class] to keep track of the said
41 * Transport. The class implements the RAII idiom, which makes it
42 * possible to build a stack of these instances as the thread is
43 * doing nested upcalls or client invocations.
45 * It utilizes TAO_TSS_Resources::tsg_ member pointer to keep track
46 * of stack-linked Transport_Selection_Guard instances.
48 * If the Transport Current feature is disabled most methods are
49 * no-ops and add no overhead on the critical path.
51 * <B>See Also:</B>
53 * https://htmlpreview.github.io/?https://github.com/DOCGroup/ACE_TAO/blob/master/TAO/docs/transport_current/index.html
56 class TAO_Export Transport_Selection_Guard
58 public:
59 static Transport_Selection_Guard* current (TAO_ORB_Core* core,
60 size_t tss_slot_id);
62 public:
63 /// Ctor
64 Transport_Selection_Guard (TAO_Transport* t);
66 /// Dtor
67 ~Transport_Selection_Guard ();
69 /// getter
70 TAO_Transport* operator-> () const
72 return this->get ();
75 /// getter
76 TAO_Transport& operator* () const
78 return *this->get ();
81 /// Getter
82 TAO_Transport* get () const
84 return this->curr_;
87 /// Setter
88 Transport_Selection_Guard& set (TAO_Transport* t)
90 this->curr_ = t;
91 return *this;
94 Transport_Selection_Guard& operator=(const Transport_Selection_Guard& rhs) {
95 if (this != &rhs)
97 #if TAO_HAS_TRANSPORT_CURRENT == 1
98 prev_ = rhs.prev_;
99 #endif /* TAO_HAS_TRANSPORT_CURRENT == 1 */
100 curr_ = rhs.curr_;
102 return *this;
105 private:
106 Transport_Selection_Guard (const Transport_Selection_Guard&) = delete;
108 #if TAO_HAS_TRANSPORT_CURRENT == 1
109 /// This is pointing to the guard that was active prior to
110 /// instantiating us.
111 Transport_Selection_Guard* prev_;
113 #endif /* TAO_HAS_TRANSPORT_CURRENT == 1 */
115 /// The "real" Transport, i.e. the one selected at present
116 TAO_Transport* curr_;
118 friend TAO_Export bool
119 operator== (const Transport_Selection_Guard& lhs,
120 const TAO_Transport* rhs);
122 friend TAO_Export bool
123 operator== (const TAO_Transport* lhs,
124 const Transport_Selection_Guard& rhs);
126 friend TAO_Export bool
127 operator!= (const Transport_Selection_Guard& lhs,
128 const TAO_Transport* rhs);
130 friend TAO_Export bool
131 operator!= (const TAO_Transport* lhs,
132 const Transport_Selection_Guard& rhs);
134 template <class U> inline friend bool
135 operator== (const Transport_Selection_Guard& lhs,
136 const U* rhs)
138 return lhs.curr_ == rhs;
141 template <class U> inline friend bool
142 operator== (const U* lhs,
143 const Transport_Selection_Guard& rhs)
145 return lhs == rhs.curr_;
148 template <class U> inline friend bool
149 operator!= (const Transport_Selection_Guard& lhs,
150 const U* rhs)
152 return lhs.curr_ != rhs;
155 template <class U> inline friend bool
156 operator!= (const U* lhs,
157 const Transport_Selection_Guard& rhs)
159 return lhs != rhs.curr_;
163 TAO_Export bool
164 operator== (const Transport_Selection_Guard& lhs,
165 const TAO_Transport* rhs);
167 TAO_Export bool
168 operator== (const TAO_Transport* lhs,
169 const Transport_Selection_Guard& rhs);
171 TAO_Export bool
172 operator!= (const Transport_Selection_Guard& lhs,
173 const TAO_Transport* rhs);
175 TAO_Export bool
176 operator!= (const TAO_Transport* lhs,
177 const Transport_Selection_Guard& rhs);
178 } /* namespace TAO */
180 TAO_END_VERSIONED_NAMESPACE_DECL
182 #include /**/ "ace/post.h"
184 #endif /* TAO_TRANSPORT_SELECTION_GUARD_H */