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