Revert "Minor modernization of DynamicAny code"
[ACE_TAO.git] / TAO / tao / AnyTypeCode / Any.h
blob769132bf0a5269cb127839586985ba9ef78d2fa9
1 // -*- C++ -*-
3 //=============================================================================
4 /**
5 * @file Any.h
7 * @author Carlos O'Ryan
8 * @author Jeff Parsons
9 */
10 //=============================================================================
12 #ifndef TAO_ANY_H
13 #define TAO_ANY_H
15 #include /**/ "ace/pre.h"
17 #include "tao/AnyTypeCode/TAO_AnyTypeCode_Export.h"
19 #if !defined (ACE_LACKS_PRAGMA_ONCE)
20 # pragma once
21 #endif /* ACE_LACKS_PRAGMA_ONCE */
23 #include "tao/AnyTypeCode/AnyTypeCode_methods.h"
24 #include "tao/Pseudo_VarOut_T.h"
25 #include "tao/Arg_Traits_T.h"
26 #include "tao/Object.h"
28 #include "ace/CDR_Stream.h"
30 TAO_BEGIN_VERSIONED_NAMESPACE_DECL
32 namespace TAO
34 class Any_Impl;
37 namespace CORBA
39 class Any;
40 typedef Any *Any_ptr;
41 class Any_var;
42 class Any_out;
44 class TypeCode;
45 typedef TypeCode *TypeCode_ptr;
47 class AbstractBase;
48 typedef AbstractBase *AbstractBase_ptr;
50 class ValueBase;
51 class Exception;
53 /**
54 * @class Any
56 * @brief Generic container for IDL types.
58 * This is the top-level class of the Any implementation. It exposes the
59 * spec-required functionality, but is mostly a wrapper for one of the
60 * template classes below.
62 class TAO_AnyTypeCode_Export Any
64 public:
65 typedef Any_ptr _ptr_type;
66 typedef Any_var _var_type;
67 typedef Any_out _out_type;
69 Any () = default;
70 Any (const Any &);
72 ~Any ();
74 Any &operator= (const Any &);
75 TAO::Any_Impl *impl () const;
77 /// Used in our destruction if we ourselves are stored in an Any.
78 static void _tao_any_destructor (void *);
80 /// These are needed for insertion and extraction of booleans,
81 /// octets, chars, and bounded strings. CORBA spec requires
82 /// that they be here, we just typedef to the already-defined
83 /// ACE_OutputCDR types.
85 typedef ACE_OutputCDR::from_boolean from_boolean;
86 typedef ACE_OutputCDR::from_octet from_octet;
87 typedef ACE_OutputCDR::from_char from_char;
88 typedef ACE_OutputCDR::from_wchar from_wchar;
89 typedef ACE_OutputCDR::from_string from_string;
90 typedef ACE_OutputCDR::from_wstring from_wstring;
92 /// Insertion of the special types.
94 void operator<<= (from_boolean);
95 void operator<<= (from_char);
96 void operator<<= (from_wchar);
97 void operator<<= (from_octet);
98 void operator<<= (from_string);
99 void operator<<= (from_wstring);
101 /// These extract octets, chars, booleans, bounded strings, and
102 /// object references. All these are defined in ACE_InputCDR.
104 typedef ACE_InputCDR::to_boolean to_boolean;
105 typedef ACE_InputCDR::to_char to_char;
106 typedef ACE_InputCDR::to_wchar to_wchar;
107 typedef ACE_InputCDR::to_octet to_octet;
108 typedef ACE_InputCDR::to_string to_string;
109 typedef ACE_InputCDR::to_wstring to_wstring;
111 /// These are not in ACE.
113 struct TAO_AnyTypeCode_Export to_object
115 // This signature reflects the change set out in
116 // issue 154 of the 1.3 RTF.
117 explicit to_object (Object_out obj);
118 Object_ptr &ref_;
121 struct TAO_AnyTypeCode_Export to_abstract_base
123 explicit to_abstract_base (AbstractBase_ptr &obj);
124 AbstractBase_ptr &ref_;
127 struct TAO_AnyTypeCode_Export to_value
129 explicit to_value (ValueBase *&base);
130 ValueBase *&ref_;
133 /// Extraction of the special types.
135 Boolean operator>>= (to_boolean) const;
136 Boolean operator>>= (to_octet) const;
137 Boolean operator>>= (to_char) const;
138 Boolean operator>>= (to_wchar) const;
139 Boolean operator>>= (to_string) const;
140 Boolean operator>>= (to_wstring) const;
141 Boolean operator>>= (to_object) const;
142 Boolean operator>>= (to_abstract_base) const;
143 Boolean operator>>= (to_value) const;
145 /// TAO-specific signature.
146 void replace (TAO::Any_Impl *);
148 /// Return TypeCode of the element stored in the Any.
149 TypeCode_ptr type () const;
151 /// For use along with <<= of a value of aliased type when the alias must
152 /// be preserved.
153 void type (TypeCode_ptr);
155 /// TAO extension, does not return a duplicate.
156 CORBA::TypeCode_ptr _tao_get_typecode () const;
158 /// TAO extension.
159 void _tao_set_typecode (const CORBA::TypeCode_ptr);
161 int _tao_byte_order () const;
163 private:
164 CORBA::Boolean checked_to_object (CORBA::Object_ptr &) const;
165 CORBA::Boolean checked_to_value (CORBA::ValueBase *&) const;
166 CORBA::Boolean checked_to_abstract_base (CORBA::AbstractBase_ptr &) const;
168 // Unimplemented - hides unsigned char insert/extract.
169 void operator<<= (unsigned char);
170 CORBA::Boolean operator>>= (unsigned char&) const;
172 private:
173 TAO::Any_Impl *impl_ {};
175 friend class TAO_Marshal_Any;
179 * @class CORBA::Any_var
181 * @brief Provide for automatic storage deallocation on going out of
182 * scope.
184 class TAO_AnyTypeCode_Export Any_var
186 public:
187 Any_var ();
188 Any_var (Any *a);
189 Any_var (const Any_var &);
190 ~Any_var ();
192 Any_var &operator= (Any *);
195 * Assignment from an Any_var
196 * This operation requires memory allocation.
197 * If the allocation fails, *this is returned
198 * unmodified.
200 Any_var &operator= (const Any_var &);
202 /// Arrow operator (smart pointer).
203 Any *operator-> ();
205 /// Cast.
206 operator const Any *() const;
208 /// Cast.
209 operator Any *&();
211 /// For in Any parameter.
212 const Any &in () const;
214 /// For inout Any parameter.
215 Any &inout ();
217 /// For out Any parameter.
218 Any *&out ();
220 /// For Any return type.
221 Any *_retn ();
223 /// TAO specific extension
224 Any *ptr () const;
225 private:
226 /// Holds the Any.
227 Any *ptr_ {};
231 * @class CORBA::Any_out
233 * @brief CORBA::Any_out
235 * The _out class for CORBA::Any. This is used to help in
236 * managing the out parameters.
238 class TAO_AnyTypeCode_Export Any_out
240 public:
241 Any_out (Any *&);
242 Any_out (Any_var &);
243 Any_out (const Any_out &);
245 /// Assignment from a Any_out.
246 Any_out &operator= (const Any_out &s);
248 /// Assignment from a Any.
249 Any_out &operator= (Any *);
251 /// Cast.
252 operator Any *&();
254 /// Return underlying instance.
255 Any *& ptr ();
257 Any *operator-> ();
259 private:
260 /// Assignment from _var disallowed.
261 void operator= (const Any_var &);
263 private:
264 /// Instance.
265 Any *&ptr_;
269 TAO_AnyTypeCode_Export CORBA::Boolean
270 operator<< (TAO_OutputCDR &, const CORBA::Any &);
272 TAO_AnyTypeCode_Export CORBA::Boolean
273 operator>> (TAO_InputCDR &, CORBA::Any &);
275 #if defined (GEN_OSTREAM_OPS)
277 // Used in optionally generated ostream operators (for debugging).
278 TAO_AnyTypeCode_Export std::ostream &
279 operator<< (std::ostream &, const CORBA::Any &);
281 #endif /* GEN_OSTREAM_OPS */
283 namespace CORBA
285 /// Typesafe insertion.
287 TAO_AnyTypeCode_Export void operator<<= (CORBA::Any &, CORBA::Short);
288 TAO_AnyTypeCode_Export void operator<<= (CORBA::Any &, CORBA::UShort);
289 TAO_AnyTypeCode_Export void operator<<= (CORBA::Any &, CORBA::Long);
290 TAO_AnyTypeCode_Export void operator<<= (CORBA::Any &, CORBA::ULong);
291 TAO_AnyTypeCode_Export void operator<<= (CORBA::Any &, CORBA::LongLong);
292 TAO_AnyTypeCode_Export void operator<<= (CORBA::Any &, CORBA::ULongLong);
293 TAO_AnyTypeCode_Export void operator<<= (CORBA::Any &, CORBA::Float);
294 TAO_AnyTypeCode_Export void operator<<= (CORBA::Any &, CORBA::Double);
295 TAO_AnyTypeCode_Export void operator<<= (CORBA::Any &, CORBA::LongDouble);
296 TAO_AnyTypeCode_Export void operator<<= (CORBA::Any &, const CORBA::Any &);
297 TAO_AnyTypeCode_Export void operator<<= (CORBA::Any &, CORBA::Any *);
298 TAO_AnyTypeCode_Export void operator<<= (CORBA::Any &, const char *);
299 TAO_AnyTypeCode_Export void operator<<= (CORBA::Any &, const CORBA::WChar *);
300 TAO_AnyTypeCode_Export void operator<<= (CORBA::Any &, CORBA::TypeCode_ptr);
301 TAO_AnyTypeCode_Export void operator<<= (CORBA::Any &, CORBA::TypeCode_ptr *);
302 TAO_AnyTypeCode_Export void operator<<= (CORBA::Any &, const CORBA::Object_ptr);
303 TAO_AnyTypeCode_Export void operator<<= (CORBA::Any &, CORBA::Object_ptr *);
304 TAO_AnyTypeCode_Export void operator<<= (CORBA::Any &, const std::string &);
305 TAO_AnyTypeCode_Export void operator<<= (CORBA::Any &, std::string *);
306 #if !defined(ACE_LACKS_STD_WSTRING)
307 TAO_AnyTypeCode_Export void operator<<= (CORBA::Any &, const std::wstring &);
308 TAO_AnyTypeCode_Export void operator<<= (CORBA::Any &, std::wstring *);
309 #endif
311 /// Typesafe extraction.
313 TAO_AnyTypeCode_Export CORBA::Boolean operator>>= (const CORBA::Any &,
314 CORBA::Short &);
315 TAO_AnyTypeCode_Export CORBA::Boolean operator>>= (const CORBA::Any &,
316 CORBA::UShort &);
317 TAO_AnyTypeCode_Export CORBA::Boolean operator>>= (const CORBA::Any &,
318 CORBA::Long &);
319 TAO_AnyTypeCode_Export CORBA::Boolean operator>>= (const CORBA::Any &,
320 CORBA::ULong &);
321 TAO_AnyTypeCode_Export CORBA::Boolean operator>>= (const CORBA::Any &,
322 CORBA::LongLong &);
323 TAO_AnyTypeCode_Export CORBA::Boolean operator>>= (const CORBA::Any &,
324 CORBA::ULongLong &);
325 TAO_AnyTypeCode_Export CORBA::Boolean operator>>= (const CORBA::Any &,
326 CORBA::Float &);
327 TAO_AnyTypeCode_Export CORBA::Boolean operator>>= (const CORBA::Any &,
328 CORBA::Double &);
329 TAO_AnyTypeCode_Export CORBA::Boolean operator>>= (const CORBA::Any &,
330 CORBA::LongDouble &);
331 TAO_AnyTypeCode_Export CORBA::Boolean operator>>= (const CORBA::Any &,
332 const CORBA::Any *&);
333 TAO_AnyTypeCode_Export CORBA::Boolean operator>>= (const CORBA::Any &,
334 CORBA::TypeCode_ptr &);
335 TAO_AnyTypeCode_Export CORBA::Boolean operator>>= (const CORBA::Any &,
336 const CORBA::Char *&);
337 TAO_AnyTypeCode_Export CORBA::Boolean operator>>= (const CORBA::Any &,
338 const CORBA::WChar *&);
339 TAO_AnyTypeCode_Export CORBA::Boolean operator>>= (const CORBA::Any &,
340 std::string &);
341 #if !defined(ACE_LACKS_STD_WSTRING)
342 TAO_AnyTypeCode_Export CORBA::Boolean operator>>= (const CORBA::Any &,
343 std::wstring &);
344 #endif
348 TAO_END_VERSIONED_NAMESPACE_DECL
350 #if defined (__ACE_INLINE__)
351 # include "tao/AnyTypeCode/Any.inl"
352 #else
354 TAO_BEGIN_VERSIONED_NAMESPACE_DECL
356 namespace CORBA
358 /// Copying versions of insertion operators for basic types
359 /// must also be defined for CORBA::Any_var.
361 TAO_AnyTypeCode_Export void operator<<= (CORBA::Any_var &, CORBA::Short);
362 TAO_AnyTypeCode_Export void operator<<= (CORBA::Any_var &, CORBA::UShort);
363 TAO_AnyTypeCode_Export void operator<<= (CORBA::Any_var &, CORBA::Long);
364 TAO_AnyTypeCode_Export void operator<<= (CORBA::Any_var &, CORBA::ULong);
365 TAO_AnyTypeCode_Export void operator<<= (CORBA::Any_var &, CORBA::LongLong);
366 TAO_AnyTypeCode_Export void operator<<= (CORBA::Any_var &, CORBA::ULongLong);
367 TAO_AnyTypeCode_Export void operator<<= (CORBA::Any_var &, CORBA::Float);
368 TAO_AnyTypeCode_Export void operator<<= (CORBA::Any_var &, CORBA::Double);
369 TAO_AnyTypeCode_Export void operator<<= (CORBA::Any_var &, const CORBA::Any *&);
370 TAO_AnyTypeCode_Export void operator<<= (CORBA::Any_var &, const char *);
371 TAO_AnyTypeCode_Export void operator<<= (CORBA::Any_var &, CORBA::TypeCode_ptr);
372 TAO_AnyTypeCode_Export void operator<<= (CORBA::Any_var &, const CORBA::Object_ptr);
373 TAO_AnyTypeCode_Export void operator<<= (CORBA::Any_var &, ACE_OutputCDR::from_boolean);
374 TAO_AnyTypeCode_Export void operator<<= (CORBA::Any_var &, CORBA::Any::from_char);
375 TAO_AnyTypeCode_Export void operator<<= (CORBA::Any_var &, CORBA::Any::from_wchar);
376 TAO_AnyTypeCode_Export void operator<<= (CORBA::Any_var &, CORBA::Any::from_octet);
377 TAO_AnyTypeCode_Export void operator<<= (CORBA::Any_var &, CORBA::Any::from_string);
378 TAO_AnyTypeCode_Export void operator<<= (CORBA::Any_var &, CORBA::Any::from_wstring);
380 /// These are not required by the spec, but will make users
381 /// of other ORBs that are used to them more comfortable.
383 TAO_AnyTypeCode_Export CORBA::Boolean operator>>= (const CORBA::Any_var &,
384 CORBA::Short &);
385 TAO_AnyTypeCode_Export CORBA::Boolean operator>>= (const CORBA::Any_var &,
386 CORBA::UShort &);
387 TAO_AnyTypeCode_Export CORBA::Boolean operator>>= (const CORBA::Any_var &,
388 CORBA::Long &);
389 TAO_AnyTypeCode_Export CORBA::Boolean operator>>= (const CORBA::Any_var &,
390 CORBA::ULong &);
391 TAO_AnyTypeCode_Export CORBA::Boolean operator>>= (const CORBA::Any_var &,
392 CORBA::LongLong &);
393 TAO_AnyTypeCode_Export CORBA::Boolean operator>>= (const CORBA::Any_var &,
394 CORBA::ULongLong &);
395 TAO_AnyTypeCode_Export CORBA::Boolean operator>>= (const CORBA::Any_var &,
396 CORBA::Float &);
397 TAO_AnyTypeCode_Export CORBA::Boolean operator>>= (const CORBA::Any_var &,
398 CORBA::Double &);
399 TAO_AnyTypeCode_Export CORBA::Boolean operator>>= (const CORBA::Any_var &,
400 CORBA::Any &);
401 TAO_AnyTypeCode_Export CORBA::Boolean operator>>= (const CORBA::Any_var &,
402 CORBA::TypeCode_ptr &);
403 TAO_AnyTypeCode_Export CORBA::Boolean operator>>= (const CORBA::Any_var &,
404 const char *&);
405 TAO_AnyTypeCode_Export CORBA::Boolean operator>>= (const CORBA::Any_var &,
406 const CORBA::WChar *&);
407 TAO_AnyTypeCode_Export CORBA::Boolean operator>>= (const CORBA::Any_var &,
408 CORBA::Any::to_boolean);
409 TAO_AnyTypeCode_Export CORBA::Boolean operator>>= (const CORBA::Any_var &,
410 CORBA::Any::to_octet);
411 TAO_AnyTypeCode_Export CORBA::Boolean operator>>= (const CORBA::Any_var &,
412 CORBA::Any::to_char);
413 TAO_AnyTypeCode_Export CORBA::Boolean operator>>= (const CORBA::Any_var &,
414 CORBA::Any::to_wchar);
415 TAO_AnyTypeCode_Export CORBA::Boolean operator>>= (const CORBA::Any_var &,
416 CORBA::Any::to_string);
417 TAO_AnyTypeCode_Export CORBA::Boolean operator>>= (const CORBA::Any_var &,
418 CORBA::Any::to_wstring);
419 TAO_AnyTypeCode_Export CORBA::Boolean operator>>= (const CORBA::Any_var &,
420 CORBA::Any::to_object);
423 TAO_END_VERSIONED_NAMESPACE_DECL
425 #endif /* __ACE_INLINE__ */
427 #include /**/ "ace/post.h"
429 #endif /* TAO_ANY_H */