00001 #ifndef guard_bounded_array_sequence_hpp
00002 #define guard_bounded_array_sequence_hpp
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012 #include "tao/Bounded_Array_Allocation_Traits_T.h"
00013 #include "tao/Generic_Sequence_T.h"
00014 #include "tao/Array_Traits_T.h"
00015
00016 TAO_BEGIN_VERSIONED_NAMESPACE_DECL
00017
00018 namespace TAO
00019 {
00020
00021 template<typename T_array, typename T_slice, typename T_tag, CORBA::ULong MAX>
00022 class bounded_array_sequence
00023 {
00024 public:
00025 typedef T_array * element_type;
00026 typedef T_array value_type;
00027 typedef T_array * T_slice_ptr;
00028 typedef T_slice_ptr * const_value_type;
00029 typedef value_type & subscript_type;
00030 typedef value_type const & const_subscript_type;
00031 typedef ::CORBA::ULong size_type;
00032
00033 typedef details::bounded_array_allocation_traits<value_type,MAX,true> allocation_traits;
00034 typedef TAO_Array_Forany_T<T_array, T_slice, T_tag> forany;
00035 typedef details::array_traits <forany> element_traits;
00036 typedef details::generic_sequence<value_type, allocation_traits, element_traits> implementation_type;
00037
00038 inline bounded_array_sequence()
00039 : impl_()
00040 {}
00041 inline bounded_array_sequence(
00042 CORBA::ULong length,
00043 value_type * data,
00044 CORBA::Boolean release = false)
00045 : impl_(MAX, length, data, release)
00046 {}
00047 inline CORBA::ULong maximum() const {
00048 return impl_.maximum();
00049 }
00050 inline CORBA::Boolean release() const {
00051 return impl_.release();
00052 }
00053 inline CORBA::ULong length() const {
00054 return impl_.length();
00055 }
00056 inline void length(CORBA::ULong length) {
00057 implementation_type::range::check_length(length, MAX);
00058 impl_.length(length);
00059 }
00060 inline value_type const & operator[](CORBA::ULong i) const {
00061 return impl_[i];
00062 }
00063 inline value_type & operator[](CORBA::ULong i) {
00064 return impl_[i];
00065 }
00066 inline void replace(
00067 CORBA::ULong length,
00068 value_type * data,
00069 CORBA::Boolean release = false) {
00070 impl_.replace(MAX, length, data, release);
00071 }
00072 inline value_type const * get_buffer() const {
00073 return impl_.get_buffer();
00074 }
00075 inline value_type * get_buffer(CORBA::Boolean orphan = false) {
00076 return impl_.get_buffer(orphan);
00077 }
00078 inline void swap(bounded_array_sequence & rhs) throw() {
00079 impl_.swap(rhs.impl_);
00080 }
00081 static value_type * allocbuf(CORBA::ULong maximum) {
00082 return implementation_type::allocbuf(maximum);
00083 }
00084 static value_type * allocbuf() {
00085 return implementation_type::allocbuf(MAX);
00086 }
00087 static void freebuf(value_type * buffer) {
00088 implementation_type::freebuf(buffer);
00089 }
00090
00091 private:
00092 implementation_type impl_;
00093 };
00094 }
00095
00096 namespace TAO
00097 {
00098 template <typename stream, typename T_array, typename T_slice, typename T_tag, CORBA::ULong MAX>
00099 bool demarshal_sequence(stream & strm, TAO::bounded_array_sequence<T_array, T_slice, T_tag, MAX> & target) {
00100 typedef typename TAO::bounded_array_sequence<T_array, T_slice, T_tag, MAX> sequence;
00101 typedef TAO_Array_Forany_T<T_array, T_slice, T_tag> forany;
00102 typedef TAO::Array_Traits<forany> array_traits;
00103
00104 ::CORBA::ULong new_length = 0;
00105 if (!(strm >> new_length)) {
00106 return false;
00107 }
00108 if ((new_length > strm.length()) || (new_length > target.maximum ())) {
00109 return false;
00110 }
00111 sequence tmp;
00112 tmp.length(new_length);
00113 typename sequence::value_type * buffer = tmp.get_buffer();
00114 for(CORBA::ULong i = 0; i < new_length; ++i) {
00115 forany tmp (array_traits::alloc ());
00116 bool const _tao_marshal_flag = (strm >> tmp);
00117 if (_tao_marshal_flag) {
00118 array_traits::copy (buffer[i], tmp.in ());
00119 }
00120 array_traits::free (tmp.inout ());
00121 if (!_tao_marshal_flag) {
00122 return false;
00123 }
00124 }
00125 tmp.swap(target);
00126 return true;
00127 }
00128
00129 template <typename stream, typename T_array, typename T_slice, typename T_tag, CORBA::ULong MAX>
00130 bool marshal_sequence(stream & strm, const TAO::bounded_array_sequence<T_array, T_slice, T_tag, MAX> & source) {
00131 typedef TAO_Array_Forany_T<T_array, T_slice, T_tag> forany;
00132 typedef TAO_FixedArray_Var_T <T_array, T_slice, T_tag> fixed_array;
00133 typedef TAO::Array_Traits<forany> array_traits;
00134 ::CORBA::ULong const length = source.length ();
00135 if (length > source.maximum () || !(strm << length)) {
00136 return false;
00137 }
00138 for(CORBA::ULong i = 0; i < length; ++i) {
00139 fixed_array tmp_array = array_traits::dup (source[i]);
00140 forany tmp (tmp_array.inout ());
00141 if (!(strm << tmp)) {
00142 return false;
00143 }
00144 }
00145 return true;
00146 }
00147 }
00148
00149 TAO_END_VERSIONED_NAMESPACE_DECL
00150
00151 #endif // guard_bounded_array_sequence_hpp