Revert "Minor modernization of DynamicAny code"
[ACE_TAO.git] / TAO / tao / Bounded_Array_Sequence_T.h
blobdc2c6b22f2b4d699e1479a8238756d46654ee326
1 #ifndef guard_bounded_array_sequence_hpp
2 #define guard_bounded_array_sequence_hpp
3 /**
4 * @file
6 * @brief Implement unbounded sequences for arrays.
8 * @author Carlos O'Ryan
9 */
10 #include "tao/Bounded_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, CORBA::ULong MAX>
19 class bounded_array_sequence
21 public:
22 typedef T_array * element_type;
23 typedef T_array value_type;
24 typedef T_array * T_slice_ptr;
25 typedef T_slice_ptr * const_value_type;
26 typedef value_type & subscript_type;
27 typedef value_type const & const_subscript_type;
28 typedef ::CORBA::ULong size_type;
30 typedef details::bounded_array_allocation_traits<value_type,MAX,true> allocation_traits;
31 typedef TAO_Array_Forany_T<T_array, T_slice, T_tag> forany;
32 typedef details::array_traits <forany> element_traits;
33 typedef details::generic_sequence<value_type, allocation_traits, element_traits> implementation_type;
35 inline bounded_array_sequence()
36 : impl_()
38 inline bounded_array_sequence(
39 CORBA::ULong length,
40 value_type * data,
41 CORBA::Boolean release = false)
42 : impl_(MAX, length, data, release)
44 inline CORBA::ULong maximum() const {
45 return impl_.maximum();
47 inline CORBA::Boolean release() const {
48 return impl_.release();
50 inline CORBA::ULong length() const {
51 return impl_.length();
53 inline void length(CORBA::ULong length) {
54 implementation_type::range::check_length(length, MAX);
55 impl_.length(length);
57 inline value_type const & operator[](CORBA::ULong i) const {
58 return impl_[i];
60 inline value_type & operator[](CORBA::ULong i) {
61 return impl_[i];
63 inline void replace(
64 CORBA::ULong length,
65 value_type * data,
66 CORBA::Boolean release = false) {
67 impl_.replace(MAX, length, data, release);
69 inline value_type const * get_buffer() const {
70 return impl_.get_buffer();
72 inline value_type * get_buffer(CORBA::Boolean orphan = false) {
73 return impl_.get_buffer(orphan);
75 inline void swap(bounded_array_sequence & rhs) noexcept {
76 impl_.swap(rhs.impl_);
78 static value_type * allocbuf(CORBA::ULong maximum) {
79 return implementation_type::allocbuf(maximum);
81 static value_type * allocbuf() {
82 return implementation_type::allocbuf(MAX);
84 static void freebuf(value_type * buffer) {
85 implementation_type::freebuf(buffer);
88 private:
89 implementation_type impl_;
93 namespace TAO
95 template <typename stream, typename T_array, typename T_slice, typename T_tag, CORBA::ULong MAX>
96 bool demarshal_sequence(stream & strm, TAO::bounded_array_sequence<T_array, T_slice, T_tag, MAX> & target) {
97 typedef typename TAO::bounded_array_sequence<T_array, T_slice, T_tag, MAX> sequence;
98 typedef TAO_Array_Forany_T<T_array, T_slice, T_tag> forany;
99 typedef TAO::Array_Traits<forany> array_traits;
101 ::CORBA::ULong new_length = 0;
102 if (!(strm >> new_length)) {
103 return false;
105 if ((new_length > strm.length()) || (new_length > target.maximum ())) {
106 return false;
108 sequence tmp;
109 tmp.length(new_length);
110 typename sequence::value_type * buffer = tmp.get_buffer();
111 for(CORBA::ULong i = 0; i < new_length; ++i) {
112 forany tmp (array_traits::alloc ());
113 bool const _tao_marshal_flag = (strm >> tmp);
114 if (_tao_marshal_flag) {
115 array_traits::copy (buffer[i], tmp.in ());
117 array_traits::free (tmp.inout ());
118 if (!_tao_marshal_flag) {
119 return false;
122 tmp.swap(target);
123 return true;
126 template <typename stream, typename T_array, typename T_slice, typename T_tag, CORBA::ULong MAX>
127 bool marshal_sequence(stream & strm, const TAO::bounded_array_sequence<T_array, T_slice, T_tag, MAX> & source) {
128 typedef TAO_Array_Forany_T<T_array, T_slice, T_tag> forany;
129 typedef TAO_FixedArray_Var_T <T_array, T_slice, T_tag> fixed_array;
130 typedef TAO::Array_Traits<forany> array_traits;
131 ::CORBA::ULong const length = source.length ();
132 if (length > source.maximum () || !(strm << length)) {
133 return false;
135 for(CORBA::ULong i = 0; i < length; ++i) {
136 fixed_array tmp_array = array_traits::dup (source[i]);
137 forany tmp (tmp_array.inout ());
138 if (!(strm << tmp)) {
139 return false;
142 return true;
146 TAO_END_VERSIONED_NAMESPACE_DECL
148 #endif // guard_bounded_array_sequence_hpp