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
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
00122
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
00143
00144
00145 static char const empty_name[] = "";
00146
00147 for (CORBA::ULong i = 0; i < this->nenumerators_; ++i)
00148 {
00149
00150
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 "" ,
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
00178
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
00188
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
00211
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