00001
00002
00003 #include "tao/AnyTypeCode/Enum_TypeCode_Static.h"
00004 #include "tao/AnyTypeCode/TypeCode_Traits.h"
00005 #include "tao/ORB_Core.h"
00006 #include "tao/CDR.h"
00007 #include "tao/TypeCodeFactory_Adapter.h"
00008 #include "tao/SystemException.h"
00009
00010 #include "ace/Dynamic_Service.h"
00011
00012 #ifndef __ACE_INLINE__
00013 # include "tao/AnyTypeCode/Enum_TypeCode_Static.inl"
00014 #endif
00015
00016
00017 ACE_RCSID (AnyTypeCode,
00018 Enum_TypeCode_Static,
00019 "$Id: Enum_TypeCode_Static.cpp 76995 2007-02-11 12:51:42Z johnnyw $")
00020
00021 TAO_BEGIN_VERSIONED_NAMESPACE_DECL
00022
00023 bool
00024 TAO::TypeCode::Enum<char const *,
00025 char const * const *,
00026 TAO::Null_RefCount_Policy>::tao_marshal (
00027 TAO_OutputCDR & cdr,
00028 CORBA::ULong) const
00029 {
00030
00031
00032
00033
00034
00035
00036 TAO_OutputCDR enc;
00037
00038 bool const success =
00039 (enc << TAO_OutputCDR::from_boolean (TAO_ENCAP_BYTE_ORDER))
00040 && (enc << TAO_OutputCDR::from_string (this->base_attributes_.id (), 0))
00041 && (enc << TAO_OutputCDR::from_string (this->base_attributes_.name (), 0))
00042 && (enc << this->nenumerators_);
00043
00044 if (!success)
00045 return false;
00046
00047 char const * const * const begin = &this->enumerators_[0];
00048 char const * const * const end = begin + this->nenumerators_;
00049
00050 for (char const * const * i = begin; i != end; ++i)
00051 {
00052 char const * const & enumerator = *i;
00053
00054 if (!(enc << TAO_OutputCDR::from_string (
00055 Traits<char const *>::get_string (enumerator), 0)))
00056 return false;
00057 }
00058
00059 return
00060 cdr << static_cast<CORBA::ULong> (enc.total_length ())
00061 && cdr.write_octet_array_mb (enc.begin ());
00062 }
00063
00064 void
00065 TAO::TypeCode::Enum<char const *,
00066 char const * const *,
00067 TAO::Null_RefCount_Policy>::tao_duplicate (void)
00068 {
00069 }
00070
00071 void
00072 TAO::TypeCode::Enum<char const *,
00073 char const * const *,
00074 TAO::Null_RefCount_Policy>::tao_release (void)
00075 {
00076 }
00077
00078 CORBA::Boolean
00079 TAO::TypeCode::Enum<char const *,
00080 char const * const *,
00081 TAO::Null_RefCount_Policy>::equal_i (
00082 CORBA::TypeCode_ptr tc
00083 ) const
00084 {
00085
00086
00087
00088
00089 CORBA::ULong const tc_nenumerators =
00090 tc->member_count ();
00091
00092 if (tc_nenumerators != this->nenumerators_)
00093 return false;
00094
00095 for (CORBA::ULong i = 0; i < this->nenumerators_; ++i)
00096 {
00097 char const * const & lhs_enumerator = this->enumerators_[i];
00098
00099 char const * const lhs_name =
00100 Traits<char const *>::get_string (lhs_enumerator);
00101 char const * const rhs_name = tc->member_name (i
00102 );
00103
00104 if (ACE_OS::strcmp (lhs_name, rhs_name) != 0)
00105 return false;
00106 }
00107
00108 return true;
00109 }
00110
00111 CORBA::Boolean
00112 TAO::TypeCode::Enum<char const *,
00113 char const * const *,
00114 TAO::Null_RefCount_Policy>::equivalent_i (
00115 CORBA::TypeCode_ptr tc
00116 ) const
00117 {
00118
00119
00120
00121 CORBA::ULong const tc_nenumerators =
00122 tc->member_count ();
00123
00124 if (tc_nenumerators != this->nenumerators_)
00125 return false;
00126
00127 return true;
00128 }
00129
00130 CORBA::TypeCode_ptr
00131 TAO::TypeCode::Enum<char const *,
00132 char const * const *,
00133 TAO::Null_RefCount_Policy>::get_compact_typecode_i (
00134 void) const
00135 {
00136 ACE_Array_Base<CORBA::String_var> tc_enumerators (this->nenumerators_);
00137
00138
00139
00140
00141 static char const empty_name[] = "";
00142
00143 for (CORBA::ULong i = 0; i < this->nenumerators_; ++i)
00144 {
00145
00146
00147
00148 tc_enumerators[i] = empty_name;
00149 }
00150
00151 TAO_TypeCodeFactory_Adapter * adapter =
00152 ACE_Dynamic_Service<TAO_TypeCodeFactory_Adapter>::instance (
00153 TAO_ORB_Core::typecodefactory_adapter_name ());
00154
00155 if (adapter == 0)
00156 {
00157 throw ::CORBA::INTERNAL ();
00158 }
00159
00160 return
00161 adapter->create_enum_tc (this->base_attributes_.id (),
00162 "" ,
00163 tc_enumerators,
00164 this->nenumerators_
00165 );
00166 }
00167
00168 char const *
00169 TAO::TypeCode::Enum<char const *,
00170 char const * const *,
00171 TAO::Null_RefCount_Policy>::id_i (
00172 void) const
00173 {
00174
00175
00176 return this->base_attributes_.id ();
00177 }
00178
00179 char const *
00180 TAO::TypeCode::Enum<char const *,
00181 char const * const *,
00182 TAO::Null_RefCount_Policy>::name_i (
00183 void) const
00184 {
00185
00186
00187 return this->base_attributes_.name ();
00188 }
00189
00190 CORBA::ULong
00191 TAO::TypeCode::Enum<char const *,
00192 char const * const *,
00193 TAO::Null_RefCount_Policy>::member_count_i (
00194 void) const
00195 {
00196 return this->nenumerators_;
00197 }
00198
00199 char const *
00200 TAO::TypeCode::Enum<char const *,
00201 char const * const *,
00202 TAO::Null_RefCount_Policy>::member_name_i (
00203 CORBA::ULong index
00204 ) const
00205 {
00206
00207
00208 if (index >= this->nenumerators_)
00209 throw ::CORBA::TypeCode::Bounds ();
00210
00211 return Traits<char const *>::get_string (this->enumerators_[index]);
00212 }
00213
00214 TAO_END_VERSIONED_NAMESPACE_DECL