Merge pull request #1551 from DOCGroup/plm_jira_333
[ACE_TAO.git] / TAO / tao / DynamicAny / DynAnyFactory.cpp
blobc741c9d4f568f68f2bf52e9d6ded8da0aefce182
1 //=============================================================================
2 /**
3 * @file DynAnyFactory.cpp
5 * @author Carlos O'Ryan <coryan@uci.edu>
6 */
7 //=============================================================================
10 #include "tao/AnyTypeCode/AnyTypeCode_methods.h"
12 #include "tao/DynamicAny/DynAnyFactory.h"
14 #include "tao/DynamicAny/DynAny_i.h"
15 #include "tao/DynamicAny/DynStruct_i.h"
16 #include "tao/DynamicAny/DynSequence_i.h"
17 #include "tao/DynamicAny/DynEnum_i.h"
18 #include "tao/DynamicAny/DynArray_i.h"
19 #include "tao/DynamicAny/DynUnion_i.h"
20 #include "tao/DynamicAny/DynAnyUtils_T.h"
22 #include "ace/Auto_Ptr.h"
24 TAO_BEGIN_VERSIONED_NAMESPACE_DECL
26 // Constructor from typecode
27 TAO_DynAnyFactory::TAO_DynAnyFactory (void)
31 DynamicAny::DynAny_ptr
32 TAO_DynAnyFactory::create_dyn_any (const CORBA::Any & value)
34 return
35 TAO::MakeDynAnyUtils::make_dyn_any_t<const CORBA::Any&> (
36 value._tao_get_typecode (),
37 value,
38 true ); // Allow truncation
41 DynamicAny::DynAny_ptr
42 TAO_DynAnyFactory::create_dyn_any_from_type_code (CORBA::TypeCode_ptr type)
44 // Second arg is typed in the template parameter, repeating it
45 // this way allows cleaner template code.
46 return
47 TAO::MakeDynAnyUtils::make_dyn_any_t<CORBA::TypeCode_ptr> (
48 type,
49 type,
50 true ); // Allow truncation
53 DynamicAny::DynAny_ptr
54 TAO_DynAnyFactory::create_dyn_any_without_truncation (
55 const CORBA::Any &value)
57 return
58 TAO::MakeDynAnyUtils::make_dyn_any_t<const CORBA::Any&> (
59 value._tao_get_typecode (),
60 value,
61 false ); // Do NOT allow truncation
64 DynamicAny::DynAnySeq *
65 TAO_DynAnyFactory::create_multiple_dyn_anys (
66 const DynamicAny::AnySeq &values,
67 ::CORBA::Boolean allow_truncate)
69 // NOTE: Since each any is self contained and holds a streamed
70 // representation of the DynAny contents, it is not possiable
71 // to make the collection of the anys we are creating to
72 // refer to the same duplicate DynValue if it crops up in
73 // seporate enteries of the values sequence. Internally
74 // within each any, indirection will occur if a DynValue
75 // self references with one of its own members.
77 const CORBA::ULong length = values.length ();
79 DynamicAny::DynAnySeq_var retseq;
80 ACE_NEW_THROW_EX (
81 retseq.out (),
82 DynamicAny::DynAnySeq (length),
83 CORBA::NO_MEMORY ());
84 retseq->length (length);
86 for (CORBA::ULong i= 0u; i < length; ++i)
88 retseq[i]=
89 (allow_truncate ?
90 this->create_dyn_any (values[i]) :
91 this->create_dyn_any_without_truncation (values[i]));
94 return retseq._retn ();
97 DynamicAny::AnySeq *
98 TAO_DynAnyFactory::create_multiple_anys (
99 const DynamicAny::DynAnySeq &values)
101 // NOTE: Since each any is self contained and holds a streamed
102 // representation of the DynAny contents, it is not possiable
103 // to make the collection of the anys we are creating to
104 // refer to the same duplicate DynValue if it crops up in
105 // seporate enteries of the values sequence. Internally
106 // within each any, indirection will occur if a DynValue
107 // self references with one of its own members.
109 const CORBA::ULong length = values.length ();
111 DynamicAny::AnySeq_var retseq;
112 ACE_NEW_THROW_EX (
113 retseq.out (),
114 DynamicAny::AnySeq (length),
115 CORBA::NO_MEMORY ());
116 retseq->length (length);
118 for (CORBA::ULong i= 0u; i < length; ++i)
120 retseq[i]= *values[i]->to_any ();
123 return retseq._retn ();
126 // Utility function called by all the DynAny classes
127 // to extract the TCKind of possibly aliased types.
128 CORBA::TCKind
129 TAO_DynAnyFactory::unalias (CORBA::TypeCode_ptr tc)
131 CORBA::TCKind tck = tc->kind ();
133 while (tck == CORBA::tk_alias)
135 CORBA::TypeCode_var temp = tc->content_type ();
137 tck = TAO_DynAnyFactory::unalias (temp.in ());
140 return tck;
143 // Same as above, but returns the type code.
144 CORBA::TypeCode_ptr
145 TAO_DynAnyFactory::strip_alias (CORBA::TypeCode_ptr tc)
147 CORBA::TypeCode_var retval = CORBA::TypeCode::_duplicate (tc);
148 CORBA::TCKind tck = retval->kind ();
150 while (tck == CORBA::tk_alias)
152 retval = retval->content_type ();
154 tck = retval->kind ();
157 return retval._retn ();
160 TAO_END_VERSIONED_NAMESPACE_DECL