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
00032 typedef details::bounded_array_allocation_traits<value_type,MAX,true> allocation_traits;
00033 typedef TAO_Array_Forany_T<T_array, T_slice, T_tag> forany;
00034 typedef details::array_traits <forany> element_traits;
00035 typedef details::generic_sequence<value_type, allocation_traits, element_traits> implementation_type;
00036
00037 inline bounded_array_sequence()
00038 : impl_()
00039 {}
00040 inline bounded_array_sequence(
00041 CORBA::ULong length,
00042 value_type * data,
00043 CORBA::Boolean release = false)
00044 : impl_(MAX, length, data, release)
00045 {}
00046 inline CORBA::ULong maximum() const {
00047 return impl_.maximum();
00048 }
00049 inline CORBA::Boolean release() const {
00050 return impl_.release();
00051 }
00052 inline CORBA::ULong length() const {
00053 return impl_.length();
00054 }
00055 inline void length(CORBA::ULong length) {
00056 impl_.length(length);
00057 }
00058 inline value_type const & operator[](CORBA::ULong i) const {
00059 return impl_[i];
00060 }
00061 inline value_type & operator[](CORBA::ULong i) {
00062 return impl_[i];
00063 }
00064 inline void replace(
00065 CORBA::ULong length,
00066 value_type * data,
00067 CORBA::Boolean release = false) {
00068 impl_.replace(MAX, length, data, release);
00069 }
00070 inline value_type const * get_buffer() const {
00071 return impl_.get_buffer();
00072 }
00073 inline value_type * get_buffer(CORBA::Boolean orphan = false) {
00074 return impl_.get_buffer(orphan);
00075 }
00076 inline void swap(bounded_array_sequence & rhs) throw() {
00077 impl_.swap(rhs.impl_);
00078 }
00079 static value_type * allocbuf(CORBA::ULong maximum) {
00080 return implementation_type::allocbuf(maximum);
00081 }
00082 static void freebuf(value_type * buffer) {
00083 implementation_type::freebuf(buffer);
00084 }
00085
00086 private:
00087 implementation_type impl_;
00088 };
00089 }
00090
00091 namespace TAO
00092 {
00093 template <typename stream, typename T_array, typename T_slice, typename T_tag, CORBA::ULong MAX>
00094 bool demarshal_sequence(stream & strm, TAO::bounded_array_sequence<T_array, T_slice, T_tag, MAX> & target) {
00095 typedef typename TAO::bounded_array_sequence<T_array, T_slice, T_tag, MAX> sequence;
00096 typedef TAO_Array_Forany_T<T_array, T_slice, T_tag> forany;
00097 typedef TAO::Array_Traits<forany> array_traits;
00098
00099 ::CORBA::ULong new_length = 0;
00100 if (!(strm >> new_length)) {
00101 return false;
00102 }
00103 if ((new_length > strm.length()) || (new_length > target.maximum ())) {
00104 return false;
00105 }
00106 sequence tmp;
00107 tmp.length(new_length);
00108 typename sequence::value_type * buffer = tmp.get_buffer();
00109 for(CORBA::ULong i = 0; i < new_length; ++i) {
00110 forany tmp (array_traits::alloc ());
00111 bool const _tao_marshal_flag = (strm >> tmp);
00112 if (_tao_marshal_flag) {
00113 array_traits::copy (buffer[i], tmp.in ());
00114 }
00115 array_traits::free (tmp.inout ());
00116 if (!_tao_marshal_flag) {
00117 return false;
00118 }
00119 }
00120 tmp.swap(target);
00121 return true;
00122 }
00123
00124 template <typename stream, typename T_array, typename T_slice, typename T_tag, CORBA::ULong MAX>
00125 bool marshal_sequence(stream & strm, const TAO::bounded_array_sequence<T_array, T_slice, T_tag, MAX> & source) {
00126 typedef TAO_Array_Forany_T<T_array, T_slice, T_tag> forany;
00127 typedef TAO_FixedArray_Var_T <T_array, T_slice, T_tag> fixed_array;
00128 typedef TAO::Array_Traits<forany> array_traits;
00129 ::CORBA::ULong const length = source.length ();
00130 if (!(strm << length)) {
00131 return false;
00132 }
00133 for(CORBA::ULong i = 0; i < length; ++i) {
00134 fixed_array tmp_array = array_traits::dup (source[i]);
00135 forany tmp (tmp_array.inout ());
00136 if (!(strm << tmp)) {
00137 return false;
00138 }
00139 }
00140 return true;
00141 }
00142 }
00143
00144 TAO_END_VERSIONED_NAMESPACE_DECL
00145
00146 #endif // guard_bounded_array_sequence_hpp