Enum_TypeCode.cpp

Go to the documentation of this file.
00001 // $Id: Enum_TypeCode.cpp 76874 2007-02-02 14:12:41Z johnnyw $
00002 
00003 #ifndef TAO_ENUM_TYPECODE_CPP
00004 #define TAO_ENUM_TYPECODE_CPP
00005 
00006 #include "tao/AnyTypeCode/Enum_TypeCode.h"
00007 #include "tao/AnyTypeCode/TypeCode_Traits.h"
00008 #include "tao/TypeCodeFactory_Adapter.h"
00009 #include "tao/ORB_Core.h"
00010 #include "tao/CDR.h"
00011 
00012 #include "ace/Dynamic_Service.h"
00013 
00014 #ifndef __ACE_INLINE__
00015 # include "tao/AnyTypeCode/Enum_TypeCode.inl"
00016 #endif  /* !__ACE_INLINE__ */
00017 
00018 TAO_BEGIN_VERSIONED_NAMESPACE_DECL
00019 
00020 template <typename StringType, class EnumeratorArrayType, class RefCountPolicy>
00021 bool
00022 TAO::TypeCode::Enum<StringType,
00023                     EnumeratorArrayType,
00024                     RefCountPolicy>::tao_marshal (TAO_OutputCDR & cdr,
00025                                                   CORBA::ULong) const
00026 {
00027   // A tk_enum TypeCode has a "complex" parameter list type (see
00028   // Table 15-2 in Section 15.3.5.1 "TypeCode" in the CDR section of
00029   // the CORBA specification), meaning that it must be marshaled into
00030   // a CDR encapsulation.
00031 
00032   // Create a CDR encapsulation.
00033   TAO_OutputCDR enc;
00034 
00035   bool const success =
00036     (enc << TAO_OutputCDR::from_boolean (TAO_ENCAP_BYTE_ORDER))
00037     && (enc << TAO_OutputCDR::from_string (this->base_attributes_.id (), 0))
00038     && (enc << TAO_OutputCDR::from_string (this->base_attributes_.name (), 0))
00039     && (enc << this->nenumerators_);
00040 
00041   if (!success)
00042     return false;
00043 
00044   StringType const * const begin = &this->enumerators_[0];
00045   StringType const * const end   = begin + this->nenumerators_;
00046 
00047   for (StringType const * i = begin; i != end; ++i)
00048     {
00049       StringType const & enumerator = *i;
00050 
00051       if (!(enc << TAO_OutputCDR::from_string (
00052               Traits<StringType>::get_string (enumerator), 0)))
00053         return false;
00054     }
00055 
00056   return
00057     cdr << static_cast<CORBA::ULong> (enc.total_length ())
00058     && cdr.write_octet_array_mb (enc.begin ());
00059 }
00060 
00061 template <typename StringType, class EnumeratorArrayType, class RefCountPolicy>
00062 void
00063 TAO::TypeCode::Enum<StringType,
00064                     EnumeratorArrayType,
00065                     RefCountPolicy>::tao_duplicate (void)
00066 {
00067   this->RefCountPolicy::add_ref ();
00068 }
00069 
00070 template <typename StringType, class EnumeratorArrayType, class RefCountPolicy>
00071 void
00072 TAO::TypeCode::Enum<StringType,
00073                     EnumeratorArrayType,
00074                     RefCountPolicy>::tao_release (void)
00075 {
00076   this->RefCountPolicy::remove_ref ();
00077 }
00078 
00079 template <typename StringType, class EnumeratorArrayType, class RefCountPolicy>
00080 CORBA::Boolean
00081 TAO::TypeCode::Enum<StringType,
00082                     EnumeratorArrayType,
00083                     RefCountPolicy>::equal_i (
00084   CORBA::TypeCode_ptr tc
00085   ) const
00086 {
00087   // This call shouldn't throw since CORBA::TypeCode::equal() verified
00088   // that the TCKind is the same as our's prior to invoking this
00089   // method, meaning that member_count() is supported.
00090 
00091   CORBA::ULong const tc_nenumerators =
00092     tc->member_count ();
00093 
00094   if (tc_nenumerators != this->nenumerators_)
00095     return false;
00096 
00097   for (CORBA::ULong i = 0; i < this->nenumerators_; ++i)
00098     {
00099       StringType const & lhs_enumerator = this->enumerators_[i];
00100 
00101       char const * const lhs_name =
00102         Traits<StringType>::get_string (lhs_enumerator);
00103       char const * const rhs_name = tc->member_name (i
00104                                                     );
00105 
00106       if (ACE_OS::strcmp (lhs_name, rhs_name) != 0)
00107         return false;
00108     }
00109 
00110   return true;
00111 }
00112 
00113 template <typename StringType, class EnumeratorArrayType, class RefCountPolicy>
00114 CORBA::Boolean
00115 TAO::TypeCode::Enum<StringType,
00116                     EnumeratorArrayType,
00117                     RefCountPolicy>::equivalent_i (
00118   CORBA::TypeCode_ptr tc
00119   ) const
00120 {
00121   // Perform a structural comparison, excluding the name() and
00122   // member_name() operations.
00123 
00124   CORBA::ULong const tc_nenumerators =
00125     tc->member_count ();
00126 
00127   if (tc_nenumerators != this->nenumerators_)
00128     return false;
00129 
00130   return true;
00131 }
00132 
00133 template <typename StringType, class EnumeratorArrayType, class RefCountPolicy>
00134 CORBA::TypeCode_ptr
00135 TAO::TypeCode::Enum<StringType,
00136                     EnumeratorArrayType,
00137                     RefCountPolicy>::get_compact_typecode_i (
00138   void) const
00139 {
00140   ACE_Array_Base<CORBA::String_var> tc_enumerators (this->nenumerators_);
00141 
00142   // Dynamically construct a new array of enumerators stripped of
00143   // member names.
00144 
00145   static char const empty_name[] = "";
00146 
00147   for (CORBA::ULong i = 0; i < this->nenumerators_; ++i)
00148     {
00149       // Member names will be stripped, i.e. not embedded within
00150       // the compact TypeCode.
00151 
00152       tc_enumerators[i] = empty_name;
00153     }
00154 
00155   TAO_TypeCodeFactory_Adapter * adapter =
00156     ACE_Dynamic_Service<TAO_TypeCodeFactory_Adapter>::instance (
00157       TAO_ORB_Core::typecodefactory_adapter_name ());
00158 
00159   if (adapter == 0)
00160     {
00161       throw ::CORBA::INTERNAL ();
00162     }
00163 
00164   return
00165     adapter->create_enum_tc (this->base_attributes_.id (),
00166                              ""  /* empty name */,
00167                              tc_enumerators,
00168                              this->nenumerators_
00169                             );
00170 }
00171 
00172 template <typename StringType, class EnumeratorArrayType, class RefCountPolicy>
00173 char const *
00174 TAO::TypeCode::Enum<StringType, EnumeratorArrayType, RefCountPolicy>::id_i (
00175   void) const
00176 {
00177   // Ownership is retained by the TypeCode, as required by the C++
00178   // mapping.
00179   return this->base_attributes_.id ();
00180 }
00181 
00182 template <typename StringType, class EnumeratorArrayType, class RefCountPolicy>
00183 char const *
00184 TAO::TypeCode::Enum<StringType, EnumeratorArrayType, RefCountPolicy>::name_i (
00185   void) const
00186 {
00187   // Ownership is retained by the TypeCode, as required by the C++
00188   // mapping.
00189   return this->base_attributes_.name ();
00190 }
00191 
00192 template <typename StringType, class EnumeratorArrayType, class RefCountPolicy>
00193 CORBA::ULong
00194 TAO::TypeCode::Enum<StringType,
00195                     EnumeratorArrayType,
00196                     RefCountPolicy>::member_count_i (
00197   void) const
00198 {
00199   return this->nenumerators_;
00200 }
00201 
00202 template <typename StringType, class EnumeratorArrayType, class RefCountPolicy>
00203 char const *
00204 TAO::TypeCode::Enum<StringType,
00205                     EnumeratorArrayType,
00206                     RefCountPolicy>::member_name_i (
00207   CORBA::ULong index
00208   ) const
00209 {
00210   // Ownership is retained by the TypeCode, as required by the C++
00211   // mapping.
00212   if (index >= this->nenumerators_)
00213     throw ::CORBA::TypeCode::Bounds ();
00214 
00215   return Traits<StringType>::get_string (this->enumerators_[index]);
00216 }
00217 
00218 TAO_END_VERSIONED_NAMESPACE_DECL
00219 
00220 #endif  /* TAO_ENUM_TYPECODE_CPP */

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