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