1 #include "tao/AnyTypeCode/AnyTypeCode_methods.h"
2 #include "tao/DynamicAny/DynAnyFactory.h"
4 #include <ace/streams.h>
6 using namespace StructTest
;
7 using namespace DynamicAny
;
9 //--------------------------------------------------------------------
10 int ACE_TMAIN (int argc
, ACE_TCHAR
*argv
[])
11 //--------------------------------------------------------------------
13 // Generic catch handler
17 CORBA::ORB_var orb
; // _var, so we don't need/may not CORBA::release(orb)
19 orb
= CORBA::ORB_init (argc
, argv
);
21 cerr
<< "Cannot initialize ORB" << endl
;
25 // Get reference to the DynAny Factory
26 CORBA::Object_var obj
= orb
->resolve_initial_references("DynAnyFactory");
28 DynAnyFactory_var daf
=
29 DynAnyFactory::_narrow(obj
.in());
32 MyStructAlias my_struct_alias
;
34 MyUnionAlias my_union_alias
;
36 CORBA::Any any_struct
;
37 CORBA::Any any_struct_alias
;
39 CORBA::Any any_union_alias
;
41 // Write the structs and unions to anys so we can get the TypeCode info
42 any_struct
<<= my_struct
;
43 any_struct_alias
<<= my_struct_alias
;
44 any_union
<<= my_union
;
45 any_union_alias
<<= my_union_alias
;
47 // Explicitly set the TypeCode for the aliased types because the any
48 // doesn't take care of aliases
49 any_struct_alias
.type(_tc_MyStructAlias
);
50 any_union_alias
.type(_tc_MyUnionAlias
);
52 CORBA::TypeCode_var tc_struct
= any_struct
.type();
53 CORBA::TypeCode_var tc_struct_alias
= any_struct_alias
.type();
54 CORBA::TypeCode_var tc_union
= any_union
.type();
55 CORBA::TypeCode_var tc_union_alias
= any_union_alias
.type();
57 cout
<< "Type Code of the struct: " << tc_struct
->kind() << endl
;
58 cout
<< "Type Code of the struct alias: " << tc_struct_alias
->kind() << endl
;
59 cout
<< "Type Code of the union: " << tc_union
->kind() << endl
;
60 cout
<< "Type Code of the union alias: " << tc_union_alias
->kind() << endl
;
62 // equal returns true only when the TypeCodes are exactly the same.
63 if (tc_struct
->equal(tc_struct_alias
.in())) {
64 cout
<< "Type Codes are identical" << endl
;
66 cout
<< "Type Codes are different" << endl
;
68 // equivalent returns true when the TypeCode is an alias
69 if (tc_struct
->equivalent(tc_struct_alias
.in())) {
70 cout
<< "Type Codes are equivalent" << endl
;
72 cout
<< "Type Codes are not equivalent" << endl
;
75 DynAny_var da_struct
= daf
->create_dyn_any_from_type_code (tc_struct
.in());
78 DynAny_var da_struct_alias
= daf
->create_dyn_any_from_type_code (tc_struct_alias
.in());
79 } catch (const CORBA::UNKNOWN
&) {
80 cout
<< "CORBA::UNKNOWN exception when calling create_dyn_any_from_type_code (tc_struct_alias)" << endl
;
84 DynAny_var da_struct_alias
= daf
->create_dyn_any (any_struct_alias
);
85 } catch (const CORBA::UNKNOWN
&) {
86 cout
<< "CORBA::UNKNOWN exception when calling create_dyn_any (any_struct_alias)" << endl
;
89 DynAny_var da_union
= daf
->create_dyn_any_from_type_code (tc_union
.in());
92 DynAny_var da_union_alias
= daf
->create_dyn_any_from_type_code (tc_union_alias
.in());
93 } catch (const CORBA::UNKNOWN
&) {
94 cout
<< "CORBA::UNKNOWN exception when calling create_dyn_any_from_type_code (tc_union_alias)" << endl
;
98 DynAny_var da_union_alias
= daf
->create_dyn_any (any_union_alias
);
99 } catch (const CORBA::UNKNOWN
&) {
100 cout
<< "CORBA::UNKNOWN exception when calling create_dyn_any (any_union_alias)" << endl
;
105 catch (const CORBA::Exception
&) {
106 cerr
<< "Caught CORBA exception" << endl
;