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