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