00001
00002
00003 #ifndef TAO_ANY_ARRAY_IMPL_T_CPP
00004 #define TAO_ANY_ARRAY_IMPL_T_CPP
00005
00006 #include "tao/AnyTypeCode/Any_Array_Impl_T.h"
00007 #include "tao/AnyTypeCode/Any.h"
00008 #include "tao/AnyTypeCode/Any_Unknown_IDL_Type.h"
00009 #include "tao/AnyTypeCode/Marshal.h"
00010 #include "tao/debug.h"
00011 #include "tao/CDR.h"
00012 #include "tao/SystemException.h"
00013
00014 #include "ace/Auto_Ptr.h"
00015
00016 #if !defined (__ACE_INLINE__)
00017 # include "tao/AnyTypeCode/Any_Array_Impl_T.inl"
00018 #endif
00019
00020 TAO_BEGIN_VERSIONED_NAMESPACE_DECL
00021
00022 template<typename T_slice, typename T_forany>
00023 TAO::Any_Array_Impl_T<T_slice, T_forany>::Any_Array_Impl_T (
00024 _tao_destructor destructor,
00025 CORBA::TypeCode_ptr tc,
00026 T_slice * const val
00027 )
00028 : Any_Impl (destructor,
00029 tc),
00030 value_ (val)
00031 {
00032 }
00033
00034 template<typename T_slice, typename T_forany>
00035 TAO::Any_Array_Impl_T<T_slice, T_forany>::~Any_Array_Impl_T (void)
00036 {
00037 }
00038
00039 template<typename T_slice, typename T_forany>
00040 void
00041 TAO::Any_Array_Impl_T<T_slice, T_forany>::insert (CORBA::Any & any,
00042 _tao_destructor destructor,
00043 CORBA::TypeCode_ptr tc,
00044 T_slice * const value)
00045 {
00046 TAO::Any_Array_Impl_T<T_slice, T_forany> *new_impl = 0;
00047 typedef TAO::Any_Array_Impl_T<T_slice, T_forany> ARRAY_ANY_IMPL;
00048 ACE_NEW (new_impl,
00049 ARRAY_ANY_IMPL (destructor,
00050 tc,
00051 value));
00052 any.replace (new_impl);
00053 }
00054
00055 template<typename T_slice, typename T_forany>
00056 CORBA::Boolean
00057 TAO::Any_Array_Impl_T<T_slice, T_forany>::extract (const CORBA::Any & any,
00058 _tao_destructor destructor,
00059 CORBA::TypeCode_ptr tc,
00060 T_slice *& _tao_elem)
00061 {
00062 _tao_elem = 0;
00063
00064 try
00065 {
00066 CORBA::TypeCode_ptr any_tc = any._tao_get_typecode ();
00067 CORBA::Boolean const _tao_equiv = any_tc->equivalent (tc);
00068
00069 if (_tao_equiv == false)
00070 {
00071 return false;
00072 }
00073
00074 TAO::Any_Impl *impl = any.impl ();
00075
00076 if (!impl->encoded ())
00077 {
00078 TAO::Any_Array_Impl_T<T_slice, T_forany> *narrow_impl =
00079 dynamic_cast <TAO::Any_Array_Impl_T <T_slice, T_forany> *> (impl);
00080
00081 if (narrow_impl == 0)
00082 {
00083 return false;
00084 }
00085
00086 _tao_elem = reinterpret_cast <T_slice*> (narrow_impl->value_);
00087 return true;
00088 }
00089
00090 TAO::Any_Array_Impl_T<T_slice, T_forany> *replacement = 0;
00091 typedef TAO::Any_Array_Impl_T<T_slice, T_forany> ARRAY_ANY_IMPL;
00092 ACE_NEW_RETURN (replacement,
00093 ARRAY_ANY_IMPL (destructor,
00094 any_tc,
00095 T_forany::tao_alloc ()),
00096 false);
00097
00098 auto_ptr<TAO::Any_Array_Impl_T<T_slice, T_forany> > replacement_safety (
00099 replacement
00100 );
00101
00102
00103 TAO::Unknown_IDL_Type * const unk =
00104 dynamic_cast<TAO::Unknown_IDL_Type *> (impl);
00105
00106 if (!unk)
00107 return false;
00108
00109
00110
00111 TAO_InputCDR for_reading (unk->_tao_get_cdr ());
00112
00113 CORBA::Boolean const good_decode =
00114 replacement->demarshal_value (for_reading);
00115
00116 if (good_decode)
00117 {
00118 _tao_elem = reinterpret_cast <T_slice*> (replacement->value_);
00119 const_cast<CORBA::Any &> (any).replace (replacement);
00120 replacement_safety.release ();
00121 return true;
00122 }
00123
00124
00125 ::CORBA::release (any_tc);
00126 }
00127 catch (const ::CORBA::Exception&)
00128 {
00129 }
00130
00131 return false;
00132 }
00133
00134 template<typename T_slice, typename T_forany>
00135 CORBA::Boolean
00136 TAO::Any_Array_Impl_T<T_slice, T_forany>::marshal_value (TAO_OutputCDR &cdr)
00137 {
00138 return (cdr << T_forany (this->value_));
00139 }
00140
00141 template<typename T_slice, typename T_forany>
00142 const void *
00143 TAO::Any_Array_Impl_T<T_slice, T_forany>::value (void) const
00144 {
00145 return this->value_;
00146 }
00147
00148 template<typename T_slice, typename T_forany>
00149 void
00150 TAO::Any_Array_Impl_T<T_slice, T_forany>::free_value (void)
00151 {
00152 if (this->value_destructor_ != 0)
00153 {
00154 (*this->value_destructor_) (this->value_);
00155 this->value_destructor_ = 0;
00156 }
00157
00158 this->value_ = 0;
00159 ::CORBA::release (this->type_);
00160 }
00161
00162 template<typename T_slice, typename T_forany>
00163 void
00164 TAO::Any_Array_Impl_T<T_slice, T_forany>::_tao_decode (TAO_InputCDR &cdr
00165 )
00166 {
00167 if (! this->demarshal_value (cdr))
00168 {
00169 throw ::CORBA::MARSHAL ();
00170 }
00171 }
00172
00173 TAO_END_VERSIONED_NAMESPACE_DECL
00174
00175 #endif