Revert "Minor modernization of DynamicAny code"
[ACE_TAO.git] / TAO / tao / Unbounded_Array_Sequence_T.h
blob873376148af4b47fa49f40def8eaad0aec553122
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)) {
105 return false;
107 if (new_length > strm.length()) {
108 return false;
110 sequence tmp(new_length);
111 tmp.length(new_length);
112 typename sequence::value_type * buffer = tmp.get_buffer();
113 for(CORBA::ULong i = 0; i < new_length; ++i) {
114 forany tmp (array_traits::alloc ());
115 bool const _tao_marshal_flag = (strm >> tmp);
116 if (_tao_marshal_flag) {
117 array_traits::copy (buffer[i], tmp.in ());
119 array_traits::free (tmp.inout ());
120 if (!_tao_marshal_flag) {
121 return false;
124 tmp.swap(target);
125 return true;
128 template <typename stream, typename T_array, typename T_slice, typename T_tag>
129 bool marshal_sequence(stream & strm, const TAO::unbounded_array_sequence<T_array, T_slice, T_tag> & source) {
130 typedef TAO_FixedArray_Var_T <T_array, T_slice, T_tag> fixed_array;
131 typedef TAO_Array_Forany_T <T_array, T_slice, T_tag> forany;
132 typedef TAO::Array_Traits<forany> array_traits;
133 ::CORBA::ULong const length = source.length ();
134 if (!(strm << length)) {
135 return false;
137 for(CORBA::ULong i = 0; i < length; ++i) {
138 fixed_array tmp_array = array_traits::dup (source[i]);
139 forany const tmp (tmp_array.inout ());
140 if (!(strm << tmp)) {
141 return false;
144 return true;
148 TAO_END_VERSIONED_NAMESPACE_DECL
150 #endif // guard_unbounded_array_sequence_hpp