Any_Impl_T.cpp

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

Generated on Sun Jan 27 13:21:06 2008 for TAO_AnyTypeCode by doxygen 1.3.6