00001
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
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
00028
00029
00030
00031
00032
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
00088
00089
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 if (ACE_OS::strcmp (lhs_name, rhs_name) != 0)
00106 return false;
00107 }
00108
00109 return true;
00110 }
00111
00112 template <typename StringType, class EnumeratorArrayType, class RefCountPolicy>
00113 CORBA::Boolean
00114 TAO::TypeCode::Enum<StringType,
00115 EnumeratorArrayType,
00116 RefCountPolicy>::equivalent_i (
00117 CORBA::TypeCode_ptr tc
00118 ) const
00119 {
00120
00121
00122
00123 CORBA::ULong const tc_nenumerators =
00124 tc->member_count ();
00125
00126 if (tc_nenumerators != this->nenumerators_)
00127 return false;
00128
00129 return true;
00130 }
00131
00132 template <typename StringType, class EnumeratorArrayType, class RefCountPolicy>
00133 CORBA::TypeCode_ptr
00134 TAO::TypeCode::Enum<StringType,
00135 EnumeratorArrayType,
00136 RefCountPolicy>::get_compact_typecode_i (
00137 void) const
00138 {
00139 ACE_Array_Base<CORBA::String_var> tc_enumerators (this->nenumerators_);
00140
00141
00142
00143
00144 static char const empty_name[] = "";
00145
00146 for (CORBA::ULong i = 0; i < this->nenumerators_; ++i)
00147 {
00148
00149
00150
00151 tc_enumerators[i] = empty_name;
00152 }
00153
00154 TAO_TypeCodeFactory_Adapter * adapter =
00155 ACE_Dynamic_Service<TAO_TypeCodeFactory_Adapter>::instance (
00156 TAO_ORB_Core::typecodefactory_adapter_name ());
00157
00158 if (adapter == 0)
00159 {
00160 throw ::CORBA::INTERNAL ();
00161 }
00162
00163 return
00164 adapter->create_enum_tc (this->base_attributes_.id (),
00165 "" ,
00166 tc_enumerators,
00167 this->nenumerators_
00168 );
00169 }
00170
00171 template <typename StringType, class EnumeratorArrayType, class RefCountPolicy>
00172 char const *
00173 TAO::TypeCode::Enum<StringType, EnumeratorArrayType, RefCountPolicy>::id_i (
00174 void) const
00175 {
00176
00177
00178 return this->base_attributes_.id ();
00179 }
00180
00181 template <typename StringType, class EnumeratorArrayType, class RefCountPolicy>
00182 char const *
00183 TAO::TypeCode::Enum<StringType, EnumeratorArrayType, RefCountPolicy>::name_i (
00184 void) const
00185 {
00186
00187
00188 return this->base_attributes_.name ();
00189 }
00190
00191 template <typename StringType, class EnumeratorArrayType, class RefCountPolicy>
00192 CORBA::ULong
00193 TAO::TypeCode::Enum<StringType,
00194 EnumeratorArrayType,
00195 RefCountPolicy>::member_count_i (
00196 void) const
00197 {
00198 return this->nenumerators_;
00199 }
00200
00201 template <typename StringType, class EnumeratorArrayType, class RefCountPolicy>
00202 char const *
00203 TAO::TypeCode::Enum<StringType,
00204 EnumeratorArrayType,
00205 RefCountPolicy>::member_name_i (
00206 CORBA::ULong index
00207 ) const
00208 {
00209
00210
00211 if (index >= this->nenumerators_)
00212 throw ::CORBA::TypeCode::Bounds ();
00213
00214 return Traits<StringType>::get_string (this->enumerators_[index]);
00215 }
00216
00217 TAO_END_VERSIONED_NAMESPACE_DECL
00218
00219 #endif