1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
|
/* -*- C++ -*- */
// $Id$
#include "DynAny_i.h"
#include "DynAnyFactory.h"
#include "tao/AnyTypeCode/Any_Unknown_IDL_Type.h"
#include "tao/CDR.h"
#include "ace/OS_NS_wchar.h"
#include "ace/OS_NS_string.h"
ACE_RCSID (DynamicAny,
DynAny_i,
"$Id$")
TAO_DynAny_i::TAO_DynAny_i (void)
{
}
TAO_DynAny_i::~TAO_DynAny_i (void)
{
}
void
TAO_DynAny_i::check_typecode (CORBA::TypeCode_ptr tc
ACE_ENV_ARG_DECL)
{
// Check to see if it's a simple type.
CORBA::TCKind tk = TAO_DynAnyFactory::unalias (tc ACE_ENV_ARG_PARAMETER);
ACE_CHECK;
switch (tk)
{
case CORBA::tk_null:
case CORBA::tk_void:
case CORBA::tk_short:
case CORBA::tk_long:
case CORBA::tk_ushort:
case CORBA::tk_ulong:
case CORBA::tk_float:
case CORBA::tk_double:
case CORBA::tk_longlong:
case CORBA::tk_ulonglong:
case CORBA::tk_boolean:
case CORBA::tk_char:
case CORBA::tk_wchar:
case CORBA::tk_octet:
case CORBA::tk_any:
case CORBA::tk_TypeCode:
case CORBA::tk_objref:
case CORBA::tk_string:
case CORBA::tk_wstring:
break;
default:
ACE_THROW (DynamicAny::DynAnyFactory::InconsistentTypeCode ());
}
}
void
TAO_DynAny_i::set_to_default_value (CORBA::TypeCode_ptr tc
ACE_ENV_ARG_DECL)
{
CORBA::TCKind tk = TAO_DynAnyFactory::unalias (tc ACE_ENV_ARG_PARAMETER);
ACE_CHECK;
switch (tk)
{
case CORBA::tk_null:
break;
case CORBA::tk_void:
this->any_._tao_set_typecode (CORBA::_tc_void);
break;
case CORBA::tk_short:
this->any_ <<= static_cast<CORBA::Short> (0);
break;
case CORBA::tk_long:
this->any_ <<= static_cast<CORBA::Long> (0);
break;
case CORBA::tk_ushort:
this->any_ <<= static_cast<CORBA::UShort> (0);
break;
case CORBA::tk_ulong:
this->any_ <<= static_cast<CORBA::ULong> (0);
break;
#if !defined (ACE_LACKS_LONGLONG_T)
case CORBA::tk_longlong:
this->any_ <<= static_cast<CORBA::LongLong> (0);
break;
case CORBA::tk_ulonglong:
this->any_ <<= static_cast<CORBA::ULongLong> (0);
break;
#endif /* ACE_LACKS_LONGLONG_T */
case CORBA::tk_boolean:
this->any_ <<= CORBA::Any::from_boolean (0);
break;
case CORBA::tk_octet:
this->any_ <<= CORBA::Any::from_octet (0);
break;
case CORBA::tk_char:
this->any_ <<= CORBA::Any::from_char (0);
break;
case CORBA::tk_wchar:
this->any_ <<= CORBA::Any::from_wchar (0);
break;
case CORBA::tk_float:
this->any_ <<= static_cast<CORBA::Float> (0);
break;
case CORBA::tk_double:
this->any_ <<= static_cast<CORBA::Double> (0);
break;
case CORBA::tk_any:
this->any_._tao_set_typecode (CORBA::_tc_null);
break;
case CORBA::tk_TypeCode:
this->any_ <<= CORBA::_tc_null;
break;
case CORBA::tk_objref:
{
TAO_OutputCDR stream;
stream << CORBA::Object::_nil ();
TAO_InputCDR in (stream);
TAO::Unknown_IDL_Type *unk = 0;
ACE_NEW (unk,
TAO::Unknown_IDL_Type (tc, in));
this->any_.replace (unk);
break;
}
case CORBA::tk_string:
this->any_ <<= "";
break;
case CORBA::tk_wstring:
{
CORBA::WChar wstr[1];
wstr[0] = 0;
this->any_ <<= wstr;
break;
}
default:
// Should never get here - check_typecode() has already been called.
break;
}
}
void
TAO_DynAny_i::init_common (void)
{
this->ref_to_component_ = 0;
this->container_is_destroying_ = 0;
this->has_components_ = 0;
this->destroyed_ = 0;
this->current_position_ = -1;
this->component_count_ = 0;
}
void
TAO_DynAny_i::init (CORBA::TypeCode_ptr tc
ACE_ENV_ARG_DECL)
{
this->check_typecode (tc
ACE_ENV_ARG_PARAMETER);
ACE_CHECK;
this->set_to_default_value (tc
ACE_ENV_ARG_PARAMETER);
ACE_CHECK;
this->init_common ();
this->type_ = CORBA::TypeCode::_duplicate (tc);
}
void
TAO_DynAny_i::init (const CORBA::Any& any
ACE_ENV_ARG_DECL)
{
this->type_ = any.type ();
this->check_typecode (this->type_.in ()
ACE_ENV_ARG_PARAMETER);
ACE_CHECK;
this->init_common ();
this->any_ = any;
}
// ****************************************************************
TAO_DynAny_i *
TAO_DynAny_i::_narrow (CORBA::Object_ptr _tao_objref
ACE_ENV_ARG_DECL_NOT_USED)
{
if (CORBA::is_nil (_tao_objref))
{
return 0;
}
return dynamic_cast<TAO_DynAny_i *> (_tao_objref);
}
// ****************************************************************
void
TAO_DynAny_i::from_any (const CORBA::Any &any
ACE_ENV_ARG_DECL)
ACE_THROW_SPEC ((
CORBA::SystemException,
DynamicAny::DynAny::TypeMismatch,
DynamicAny::DynAny::InvalidValue
))
{
if (this->destroyed_)
{
ACE_THROW (CORBA::OBJECT_NOT_EXIST ());
}
CORBA::TypeCode_var any_tc = any.type ();
CORBA::Boolean equiv =
this->type_->equivalent (any_tc.in ()
ACE_ENV_ARG_PARAMETER);
ACE_CHECK;
if (!equiv)
{
ACE_THROW (DynamicAny::DynAny::TypeMismatch ());
}
// @@@ (JP) Spec also says we should check for illegal Any
// value here, and throw InvalidValue if we find one.
// Something like a null string will be caught in the constructor.
this->any_ = any;
}
CORBA::Any_ptr
TAO_DynAny_i::to_any (ACE_ENV_SINGLE_ARG_DECL)
ACE_THROW_SPEC ((
CORBA::SystemException
))
{
if (this->destroyed_)
{
ACE_THROW_RETURN (CORBA::OBJECT_NOT_EXIST (),
0);
}
CORBA::Any_ptr retval;
ACE_NEW_THROW_EX (retval,
CORBA::Any (this->any_),
CORBA::NO_MEMORY ());
ACE_CHECK_RETURN (0);
return retval;
}
CORBA::Boolean
TAO_DynAny_i::equal (DynamicAny::DynAny_ptr rhs
ACE_ENV_ARG_DECL)
ACE_THROW_SPEC ((
CORBA::SystemException
))
{
if (this->destroyed_)
{
ACE_THROW_RETURN (CORBA::OBJECT_NOT_EXIST (),
0);
}
TAO_DynAny_i *rhs_n = TAO_DynAny_i::_narrow (rhs
ACE_ENV_ARG_PARAMETER);
ACE_CHECK_RETURN (0);
if (rhs_n == 0)
{
return 0;
}
CORBA::Boolean equiv = this->type_->equivalent (rhs_n->type_.in ()
ACE_ENV_ARG_PARAMETER);
ACE_CHECK_RETURN (0);
if (!equiv)
{
return 0;
}
CORBA::TCKind tk = TAO_DynAnyFactory::unalias (this->type_.in ()
ACE_ENV_ARG_PARAMETER);
ACE_CHECK_RETURN (0);
switch (tk)
{
case CORBA::tk_null:
case CORBA::tk_void:
return 1;
case CORBA::tk_short:
{
CORBA::Short rhs_v;
rhs_n->any_ >>= rhs_v;
CORBA::Short lhs_v;
this->any_ >>= lhs_v;
return (lhs_v == rhs_v);
}
case CORBA::tk_long:
{
CORBA::Long rhs_v;
rhs_n->any_ >>= rhs_v;
CORBA::Long lhs_v;
this->any_ >>= lhs_v;
return (lhs_v == rhs_v);
}
case CORBA::tk_ushort:
{
CORBA::UShort rhs_v;
rhs_n->any_ >>= rhs_v;
CORBA::UShort lhs_v;
this->any_ >>= lhs_v;
return (lhs_v == rhs_v);
}
case CORBA::tk_ulong:
{
CORBA::ULong rhs_v;
rhs_n->any_ >>= rhs_v;
CORBA::ULong lhs_v;
this->any_ >>= lhs_v;
return (lhs_v == rhs_v);
}
case CORBA::tk_float:
{
CORBA::Float rhs_v;
rhs_n->any_ >>= rhs_v;
CORBA::Float lhs_v;
this->any_ >>= lhs_v;
return (lhs_v == rhs_v);
}
case CORBA::tk_double:
{
CORBA::Double rhs_v;
rhs_n->any_ >>= rhs_v;
CORBA::Double lhs_v;
this->any_ >>= lhs_v;
return (lhs_v == rhs_v);
}
case CORBA::tk_longlong:
{
CORBA::LongLong rhs_v;
rhs_n->any_ >>= rhs_v;
CORBA::LongLong lhs_v;
this->any_ >>= lhs_v;
return (lhs_v == rhs_v);
}
case CORBA::tk_ulonglong:
{
CORBA::ULongLong rhs_v;
rhs_n->any_ >>= rhs_v;
CORBA::ULongLong lhs_v;
this->any_ >>= lhs_v;
return (lhs_v == rhs_v);
}
case CORBA::tk_boolean:
{
CORBA::Boolean rhs_v;
rhs_n->any_ >>= CORBA::Any::to_boolean (rhs_v);
CORBA::Boolean lhs_v;
this->any_ >>= CORBA::Any::to_boolean (lhs_v);
return (lhs_v == rhs_v);
}
case CORBA::tk_char:
{
CORBA::Char rhs_v;
rhs_n->any_ >>= CORBA::Any::to_char (rhs_v);
CORBA::Char lhs_v;
this->any_ >>= CORBA::Any::to_char (lhs_v);
return (lhs_v == rhs_v);
}
case CORBA::tk_wchar:
{
CORBA::WChar rhs_v;
rhs_n->any_ >>= CORBA::Any::to_wchar (rhs_v);
CORBA::WChar lhs_v;
this->any_ >>= CORBA::Any::to_wchar (lhs_v);
return (lhs_v == rhs_v);
}
case CORBA::tk_octet:
{
CORBA::Octet rhs_v;
rhs_n->any_ >>= CORBA::Any::to_octet (rhs_v);
CORBA::Octet lhs_v;
this->any_ >>= CORBA::Any::to_octet (lhs_v);
return (lhs_v == rhs_v);
}
case CORBA::tk_any:
{
const CORBA::Any *rhs_v;
rhs_n->any_ >>= rhs_v;
const CORBA::Any *lhs_v;
this->any_ >>= lhs_v;
DynamicAny::DynAny_var rhs_dyn =
TAO_DynAnyFactory::make_dyn_any (*rhs_v
ACE_ENV_ARG_PARAMETER);
ACE_CHECK_RETURN (0);
DynamicAny::DynAny_var lhs_dyn =
TAO_DynAnyFactory::make_dyn_any (*lhs_v
ACE_ENV_ARG_PARAMETER);
ACE_CHECK_RETURN (0);
CORBA::Boolean b = rhs_dyn->equal (lhs_dyn.in ()
ACE_ENV_ARG_PARAMETER);
ACE_CHECK_RETURN (0);
rhs_dyn->destroy (ACE_ENV_SINGLE_ARG_PARAMETER);
ACE_CHECK_RETURN (0);
lhs_dyn->destroy (ACE_ENV_SINGLE_ARG_PARAMETER);
ACE_CHECK_RETURN (0);
return b;
}
case CORBA::tk_TypeCode:
{
CORBA::TypeCode_ptr rhs_v;
rhs_n->any_ >>= rhs_v;
CORBA::TypeCode_ptr lhs_v;
this->any_ >>= lhs_v;
// See CORBA 2.4.2 - must use equal() here.
return lhs_v->equal (lhs_v
ACE_ENV_ARG_PARAMETER);
}
case CORBA::tk_objref:
{
CORBA::Object_ptr rhs_v;
rhs_n->any_ >>= CORBA::Any::to_object (rhs_v);
CORBA::Object_ptr lhs_v;
this->any_ >>= CORBA::Any::to_object (lhs_v);
return lhs_v->_is_equivalent (lhs_v
ACE_ENV_ARG_PARAMETER);
}
case CORBA::tk_string:
{
CORBA::TypeCode_var unaliased_tc =
TAO_DynAnyFactory::strip_alias (this->type_.in ()
ACE_ENV_ARG_PARAMETER);
ACE_CHECK_RETURN (0);
CORBA::ULong bound =
unaliased_tc->length (ACE_ENV_SINGLE_ARG_PARAMETER);
ACE_CHECK_RETURN (0);
const char *rhs_v, *lhs_v;
CORBA::Boolean rstatus, lstatus;
if (bound == 0)
{
rstatus = rhs_n->any_ >>= rhs_v;
lstatus = this->any_ >>= lhs_v;
if ((rstatus && lstatus) == 0)
{
return 0;
}
}
else
{
rstatus = rhs_n->any_ >>= CORBA::Any::to_string (rhs_v,
bound);
lstatus = this->any_ >>= CORBA::Any::to_string (lhs_v,
bound);
if ((rstatus && lstatus) == 0)
{
return 0;
}
}
return ACE_OS::strcmp (rhs_v, lhs_v) == 0;
}
case CORBA::tk_wstring:
{
CORBA::TypeCode_var unaliased_tc =
TAO_DynAnyFactory::strip_alias (this->type_.in ()
ACE_ENV_ARG_PARAMETER);
ACE_CHECK_RETURN (0);
CORBA::ULong bound =
unaliased_tc->length (ACE_ENV_SINGLE_ARG_PARAMETER);
ACE_CHECK_RETURN (0);
const CORBA::WChar *rhs_v, *lhs_v;
CORBA::Boolean rstatus, lstatus;
if (bound == 0)
{
rstatus = rhs_n->any_ >>= rhs_v;
lstatus = this->any_ >>= lhs_v;
if ((rstatus && lstatus) == 0)
{
return 0;
}
}
else
{
rstatus = rhs_n->any_ >>= CORBA::Any::to_wstring (rhs_v,
bound);
lstatus = this->any_ >>= CORBA::Any::to_wstring (lhs_v,
bound);
if ((rstatus && lstatus) == 0)
{
return 0;
}
}
return ACE_OS::wscmp (rhs_v, lhs_v) == 0;
}
default:
break; // Cannot happen...
}
return 0;
}
void
TAO_DynAny_i::destroy (ACE_ENV_SINGLE_ARG_DECL)
ACE_THROW_SPEC ((
CORBA::SystemException
))
{
if (this->destroyed_)
{
ACE_THROW (CORBA::OBJECT_NOT_EXIST ());
}
if (!this->ref_to_component_ || this->container_is_destroying_)
{
this->destroyed_ = 1;
}
}
DynamicAny::DynAny_ptr
TAO_DynAny_i::current_component (ACE_ENV_SINGLE_ARG_DECL)
ACE_THROW_SPEC ((
CORBA::SystemException,
DynamicAny::DynAny::TypeMismatch
))
{
if (this->destroyed_)
{
ACE_THROW_RETURN (CORBA::OBJECT_NOT_EXIST (),
DynamicAny::DynAny::_nil ());
}
ACE_THROW_RETURN (DynamicAny::DynAny::TypeMismatch (),
DynamicAny::DynAny::_nil ());
}
|