=default for generated implementation copy ctor
[ACE_TAO.git] / TAO / tao / Unbounded_Array_Sequence_T.h
blob9ed973a8f5bd3d74b7b509bacb908cf1b96ccbb5
1 #ifndef guard_unbounded_array_sequence_hpp
2 #define guard_unbounded_array_sequence_hpp
3 /**
4 * @file
6 * @brief Implement unbounded sequences for arrays.
8 * @author Carlos O'Ryan
9 */
10 #include "tao/Unbounded_Array_Allocation_Traits_T.h"
11 #include "tao/Generic_Sequence_T.h"
12 #include "tao/Array_Traits_T.h"
14 TAO_BEGIN_VERSIONED_NAMESPACE_DECL
16 namespace TAO
18 template<typename T_array, typename T_slice, typename T_tag>
19 class unbounded_array_sequence
21 public:
22 typedef T_array * element_type;
23 typedef T_array value_type;
24 typedef T_slice * T_slice_ptr;
25 typedef T_slice * slice_type;
26 typedef T_slice_ptr * const_value_type;
27 typedef value_type & subscript_type;
28 typedef value_type const & const_subscript_type;
29 typedef ::CORBA::ULong size_type;
31 typedef details::unbounded_array_allocation_traits<value_type,true> allocation_traits;
32 typedef TAO_Array_Forany_T<T_array, T_slice, T_tag> forany;
33 typedef details::array_traits <forany> element_traits;
34 typedef details::generic_sequence<value_type, allocation_traits, element_traits> implementation_type;
36 inline unbounded_array_sequence()
37 : impl_()
39 inline explicit unbounded_array_sequence(CORBA::ULong maximum)
40 : impl_(maximum)
42 inline unbounded_array_sequence(
43 CORBA::ULong maximum,
44 CORBA::ULong length,
45 value_type * data,
46 CORBA::Boolean release = false)
47 : impl_(maximum, length, data, release)
49 inline CORBA::ULong maximum() const {
50 return impl_.maximum();
52 inline CORBA::Boolean release() const {
53 return impl_.release();
55 inline CORBA::ULong length() const {
56 return impl_.length();
58 inline void length(CORBA::ULong length) {
59 impl_.length(length);
61 inline value_type const & operator[](CORBA::ULong i) const {
62 return impl_[i];
64 inline value_type & operator[](CORBA::ULong i) {
65 return impl_[i];
67 inline void replace(
68 CORBA::ULong maximum,
69 CORBA::ULong length,
70 value_type * data,
71 CORBA::Boolean release = false) {
72 impl_.replace(maximum, length, data, release);
74 inline value_type const * get_buffer() const {
75 return impl_.get_buffer();
77 inline value_type * get_buffer(CORBA::Boolean orphan = false) {
78 return impl_.get_buffer(orphan);
80 inline void swap(unbounded_array_sequence & rhs) noexcept {
81 impl_.swap(rhs.impl_);
83 static value_type * allocbuf(CORBA::ULong maximum) {
84 return implementation_type::allocbuf(maximum);
86 static void freebuf(value_type * buffer) {
87 implementation_type::freebuf(buffer);
90 private:
91 implementation_type impl_;
95 namespace TAO
97 template <typename stream, typename T_array, typename T_slice, typename T_tag>
98 bool demarshal_sequence (stream &strm, TAO::unbounded_array_sequence<T_array, T_slice, T_tag> &target) {
99 typedef TAO::unbounded_array_sequence<T_array, T_slice, T_tag> sequence;
100 typedef TAO_Array_Forany_T <T_array, T_slice, T_tag> forany;
101 typedef TAO::Array_Traits<forany> array_traits;
103 ::CORBA::ULong new_length = 0;
104 if (!(strm >> new_length))
106 return false;
108 if (new_length > strm.length ())
110 return false;
112 sequence tmp (new_length);
113 tmp.length (new_length);
114 typename sequence::value_type *const buffer = tmp.get_buffer ();
115 for (CORBA::ULong i = 0; i < new_length; ++i)
117 forany wrapper (array_traits::alloc ());
118 bool const _tao_marshal_flag = strm >> wrapper;
119 if (_tao_marshal_flag)
121 array_traits::copy (buffer[i], wrapper.in ());
123 array_traits::free (wrapper.inout ());
124 if (!_tao_marshal_flag)
126 return false;
129 tmp.swap (target);
130 return true;
133 template <typename stream, typename T_array, typename T_slice, typename T_tag>
134 bool marshal_sequence(stream & strm, const TAO::unbounded_array_sequence<T_array, T_slice, T_tag> & source) {
135 typedef TAO_FixedArray_Var_T <T_array, T_slice, T_tag> fixed_array;
136 typedef TAO_Array_Forany_T <T_array, T_slice, T_tag> forany;
137 typedef TAO::Array_Traits<forany> array_traits;
138 ::CORBA::ULong const length = source.length ();
139 if (!(strm << length)) {
140 return false;
142 for(CORBA::ULong i = 0; i < length; ++i) {
143 fixed_array tmp_array = array_traits::dup (source[i]);
144 forany const tmp (tmp_array.inout ());
145 if (!(strm << tmp)) {
146 return false;
149 return true;
153 TAO_END_VERSIONED_NAMESPACE_DECL
155 #endif // guard_unbounded_array_sequence_hpp