00001 #ifndef guard_bounded_valuetype_sequence_hpp
00002 #define guard_bounded_valuetype_sequence_hpp
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012 #include "Bounded_Valuetype_Allocation_Traits_T.h"
00013 #include "Valuetype_Traits_T.h"
00014 #include "tao/Generic_Sequence_T.h"
00015 #include "Valuetype_Sequence_Element_T.h"
00016 #include "tao/MM_Sequence_Iterator_T.h"
00017 #include "tao/Bounded_Reference_Allocation_Traits_T.h"
00018
00019 TAO_BEGIN_VERSIONED_NAMESPACE_DECL
00020
00021 namespace TAO
00022 {
00023
00024 template<typename object_t, typename object_t_var, CORBA::ULong MAX>
00025 class bounded_valuetype_sequence
00026 {
00027 public:
00028 typedef object_t object_type;
00029 typedef object_type * value_type;
00030 typedef value_type const const_value_type;
00031 typedef object_t_var object_type_var;
00032 typedef ::CORBA::ULong size_type;
00033
00034 typedef details::valuetype_traits<object_type,object_type_var,true> element_traits;
00035 typedef details::bounded_reference_allocation_traits<value_type,element_traits,MAX,true> allocation_traits;
00036
00037 typedef details::valuetype_sequence_element<element_traits> element_type;
00038 typedef element_type subscript_type;
00039 typedef value_type const & const_subscript_type;
00040
00041 typedef details::generic_sequence<value_type, allocation_traits, element_traits> implementation_type;
00042
00043 inline bounded_valuetype_sequence()
00044 : impl_()
00045 {}
00046 inline bounded_valuetype_sequence(
00047 CORBA::ULong length,
00048 value_type * data,
00049 CORBA::Boolean release)
00050 : impl_(MAX, length, data, release)
00051 {}
00052
00053
00054 inline CORBA::ULong maximum() const {
00055 return impl_.maximum();
00056 }
00057 inline CORBA::Boolean release() const {
00058 return impl_.release();
00059 }
00060 inline CORBA::ULong length() const {
00061 return impl_.length();
00062 }
00063
00064 inline void length(CORBA::ULong length) {
00065 implementation_type::range::check_length(length, MAX);
00066 impl_.length(length);
00067 }
00068 inline value_type const & operator[](CORBA::ULong i) const {
00069 return impl_[i];
00070 }
00071 inline element_type operator[](CORBA::ULong i) {
00072 return element_type(impl_[i], release());
00073 }
00074 inline value_type const * get_buffer() const {
00075 return impl_.get_buffer();
00076 }
00077 inline void replace(
00078 CORBA::ULong length,
00079 value_type * data,
00080 CORBA::Boolean release = false) {
00081 impl_.replace(MAX, length, data, release);
00082 }
00083 inline value_type * get_buffer(CORBA::Boolean orphan = false) {
00084 return impl_.get_buffer(orphan);
00085 }
00086 inline void swap(bounded_valuetype_sequence & rhs) throw() {
00087 impl_.swap(rhs.impl_);
00088 }
00089
00090 static value_type * allocbuf(CORBA::ULong maximum)
00091 {
00092 return implementation_type::allocbuf(maximum);
00093 }
00094 static value_type * allocbuf()
00095 {
00096 return implementation_type::allocbuf(MAX);
00097 }
00098 static void freebuf(value_type * buffer)
00099 {
00100 implementation_type::freebuf(buffer);
00101 }
00102
00103 #if defined TAO_HAS_SEQUENCE_ITERATORS && TAO_HAS_SEQUENCE_ITERATORS == 1
00104
00105
00106
00107
00108
00109
00110
00111 typedef MM_Sequence_Iterator<bounded_valuetype_sequence<object_t, object_t_var, MAX> > iterator;
00112 typedef Const_MM_Sequence_Iterator<bounded_valuetype_sequence<object_t, object_t_var, MAX> > const_iterator;
00113 typedef MM_Sequence_Reverse_Iterator<bounded_valuetype_sequence<object_t, object_t_var, MAX> > reverse_iterator;
00114 typedef Const_MM_Sequence_Reverse_Iterator<bounded_valuetype_sequence<object_t, object_t_var, MAX> > const_reverse_iterator;
00115
00116
00117 inline iterator begin (void)
00118 {
00119 return iterator (&this->impl_);
00120 }
00121
00122
00123 inline const_iterator begin (void) const
00124 {
00125 return const_iterator (&this->impl_);
00126 }
00127
00128
00129 inline iterator end (void)
00130 {
00131 return iterator (&this->impl_,
00132 this->impl_.length ());
00133 }
00134
00135
00136 inline const_iterator end (void) const
00137 {
00138 return const_iterator (&this->impl_,
00139 this->impl_.length ());
00140 }
00141
00142
00143 inline reverse_iterator rbegin (void)
00144 {
00145 return reverse_iterator (&this->impl_,
00146 this->impl_.length () - 1);
00147 }
00148
00149
00150 inline const_reverse_iterator rbegin (void) const
00151 {
00152 return const_reverse_iterator (&this->impl_,
00153 this->impl_.length () - 1);
00154 }
00155
00156
00157
00158 inline reverse_iterator rend (void)
00159 {
00160 return reverse_iterator (&this->impl_,
00161 -1);
00162 }
00163
00164
00165
00166 inline const_reverse_iterator rend (void) const
00167 {
00168 return const_reverse_iterator (&this->impl_,
00169 -1);
00170 }
00171
00172 #endif
00173
00174
00175 private:
00176 implementation_type impl_;
00177 };
00178
00179
00180 template <typename stream, typename object_t, typename object_t_var, CORBA::ULong MAX>
00181 bool marshal_sequence(stream & strm, const TAO::bounded_valuetype_sequence<object_t, object_t_var, MAX> & source) {
00182
00183 const ::CORBA::ULong length = source.length ();
00184 if (length > source.maximum () || !(strm << length)) {
00185 return false;
00186 }
00187 for(CORBA::ULong i = 0; i < length; ++i) {
00188 if (!(strm << source[i])) {
00189 return false;
00190 }
00191 }
00192 return true;
00193 }
00194
00195 template <typename stream, typename object_t, typename object_t_var, CORBA::ULong MAX>
00196 bool demarshal_sequence(stream & strm, TAO::bounded_valuetype_sequence<object_t, object_t_var, MAX> & target) {
00197 typedef TAO::bounded_valuetype_sequence<object_t, object_t_var, MAX> sequence;
00198 typedef typename sequence::allocation_traits sequence_allocation_traits;
00199 ::CORBA::ULong new_length = 0;
00200 if (!(strm >> new_length)) {
00201 return false;
00202 }
00203 if ((new_length > strm.length()) || (new_length > target.maximum ())) {
00204 return false;
00205 }
00206 sequence tmp(new_length,
00207 sequence_allocation_traits::allocbuf_noinit(new_length),
00208 true);
00209 typename sequence::value_type * buffer = tmp.get_buffer();
00210 for(CORBA::ULong i = 0; i < new_length; ++i) {
00211 if (!(strm >> buffer[i])) {
00212 return false;
00213 }
00214 }
00215 tmp.swap(target);
00216 return true;
00217 }
00218
00219 }
00220
00221 TAO_END_VERSIONED_NAMESPACE_DECL
00222
00223
00224 #endif // guard_bounded_valuetype_sequence_hpp