Alias_TypeCode.cpp

Go to the documentation of this file.
00001 // $Id: Alias_TypeCode.cpp 77000 2007-02-12 07:30:10Z johnnyw $
00002 
00003 #ifndef TAO_ALIAS_TYPECODE_CPP
00004 #define TAO_ALIAS_TYPECODE_CPP
00005 
00006 #include "tao/AnyTypeCode/Alias_TypeCode.h"
00007 
00008 #ifndef __ACE_INLINE__
00009 # include "tao/AnyTypeCode/Alias_TypeCode.inl"
00010 #endif  /* !__ACE_INLINE__ */
00011 
00012 #include "tao/ORB_Core.h"
00013 #include "tao/CDR.h"
00014 #include "tao/SystemException.h"
00015 #include "tao/AnyTypeCode/TypeCode_Traits.h"
00016 
00017 #include "ace/Dynamic_Service.h"
00018 
00019 TAO_BEGIN_VERSIONED_NAMESPACE_DECL
00020 
00021 template <typename StringType,
00022           typename TypeCodeType,
00023           class RefCountPolicy>
00024 bool
00025 TAO::TypeCode::Alias<StringType,
00026                      TypeCodeType,
00027                      RefCountPolicy>::tao_marshal (TAO_OutputCDR & cdr,
00028                                                    CORBA::ULong offset) const
00029 {
00030   // A tk_alias TypeCode has a "complex" parameter list type (see
00031   // Table 15-2 in Section 15.3.5.1 "TypeCode" in the CDR section of
00032   // the CORBA specification), meaning that it must be marshaled into
00033   // a CDR encapsulation.
00034 
00035   // Create a CDR encapsulation.
00036 
00037   TAO_OutputCDR enc;
00038 
00039   // Account for the encoded CDR encapsulation length and byte order.
00040   //
00041   // Aligning on an octet since the next value after the CDR
00042   // encapsulation length will always be the byte order octet/boolean
00043   // in this case.
00044   offset = ACE_align_binary (offset + 4,
00045                              ACE_CDR::OCTET_ALIGN);
00046 
00047   return
00048     enc << TAO_OutputCDR::from_boolean (TAO_ENCAP_BYTE_ORDER)
00049     && enc << TAO_OutputCDR::from_string (this->attributes_.id (), 0)
00050     && enc << TAO_OutputCDR::from_string (this->attributes_.name (), 0)
00051     && marshal (enc,
00052                 Traits<StringType>::get_typecode (this->content_type_),
00053                 offset + enc.total_length ())
00054     && cdr << static_cast<CORBA::ULong> (enc.total_length ())
00055     && cdr.write_octet_array_mb (enc.begin ());
00056 }
00057 
00058 template<typename StringType,
00059          typename TypeCodeType,
00060          class RefCountPolicy>
00061 void
00062 TAO::TypeCode::Alias<StringType,
00063                      TypeCodeType,
00064                      RefCountPolicy>::tao_duplicate (void)
00065 {
00066   this->RefCountPolicy::add_ref ();
00067 }
00068 
00069 template<typename StringType,
00070          typename TypeCodeType,
00071          class RefCountPolicy>
00072 void
00073 TAO::TypeCode::Alias<StringType,
00074                      TypeCodeType,
00075                      RefCountPolicy>::tao_release (void)
00076 {
00077   this->RefCountPolicy::remove_ref ();
00078 }
00079 
00080 template<typename StringType,
00081          typename TypeCodeType,
00082          class RefCountPolicy>
00083 CORBA::Boolean
00084 TAO::TypeCode::Alias<StringType,
00085                      TypeCodeType,
00086                      RefCountPolicy>::equal_i (CORBA::TypeCode_ptr tc) const
00087 {
00088   // The CORBA::TypeCode base class already verified equality of the
00089   // base attributes (id and name).  Perform an equality comparison of
00090   // the content.
00091 
00092   CORBA::TypeCode_var rhs_content_type = tc->content_type ();
00093 
00094   return
00095     Traits<StringType>::get_typecode (this->content_type_)->equal (
00096       rhs_content_type.in ());
00097 }
00098 
00099 template<typename StringType,
00100          typename TypeCodeType,
00101          class RefCountPolicy>
00102 CORBA::Boolean
00103 TAO::TypeCode::Alias<StringType,
00104                      TypeCodeType,
00105                      RefCountPolicy>::equivalent_i (CORBA::TypeCode_ptr) const
00106 {
00107   // Equivalence already verified in the base class
00108   // CORBA::TypeCode::equivalent() method.
00109 
00110   return true;
00111 }
00112 
00113 template<typename StringType,
00114          typename TypeCodeType,
00115          class RefCountPolicy>
00116 CORBA::TypeCode_ptr
00117 TAO::TypeCode::Alias<StringType,
00118                      TypeCodeType,
00119                      RefCountPolicy>::get_compact_typecode_i (void) const
00120 {
00121   TAO_TypeCodeFactory_Adapter * const adapter =
00122     ACE_Dynamic_Service<TAO_TypeCodeFactory_Adapter>::instance (
00123         TAO_ORB_Core::typecodefactory_adapter_name ()
00124       );
00125 
00126   if (adapter == 0)
00127     {
00128       throw ::CORBA::INITIALIZE ();
00129     }
00130 
00131   CORBA::TypeCode_var compact_content_type =
00132     Traits<StringType>::get_typecode (
00133       this->content_type_)->get_compact_typecode ();
00134 
00135   if (this->kind_ == CORBA::tk_alias)
00136     {
00137       return adapter->create_alias_tc (this->attributes_.id (),
00138                                        "",  /* empty name */
00139                                        compact_content_type.in ());
00140     }
00141   else
00142     {
00143       return adapter->create_value_box_tc (this->attributes_.id (),
00144                                            "",  /* empty name */
00145                                            compact_content_type.in ());
00146     }
00147 }
00148 
00149 template<typename StringType,
00150          typename TypeCodeType,
00151          class RefCountPolicy>
00152 char const *
00153 TAO::TypeCode::Alias<StringType,
00154                      TypeCodeType,
00155                      RefCountPolicy>::id_i (void) const
00156 {
00157   // Ownership is retained by the TypeCode, as required by the C++
00158   // mapping.
00159   return this->attributes_.id ();
00160 }
00161 
00162 template<typename StringType,
00163          typename TypeCodeType,
00164          class RefCountPolicy>
00165 char const *
00166 TAO::TypeCode::Alias<StringType,
00167                      TypeCodeType,
00168                      RefCountPolicy>::name_i (void) const
00169 {
00170   // Ownership is retained by the TypeCode, as required by the C++
00171   // mapping.
00172   return this->attributes_.name ();
00173 }
00174 
00175 template<typename StringType,
00176          typename TypeCodeType,
00177          class RefCountPolicy>
00178 CORBA::TypeCode_ptr
00179 TAO::TypeCode::Alias<StringType,
00180                      TypeCodeType,
00181                      RefCountPolicy>::content_type_i (void) const
00182 {
00183   return
00184      CORBA::TypeCode::_duplicate (
00185        Traits<StringType>::get_typecode (this->content_type_));
00186 }
00187 
00188 TAO_END_VERSIONED_NAMESPACE_DECL
00189 
00190 #endif  /*  TAO_ALIAS_TYPECODE_CPP */

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