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