Merge pull request #2309 from mitza-oci/warnings
[ACE_TAO.git] / TAO / tao / Bounded_Array_Sequence_T.h
blobb34c4c4ef23bfbd8f483b5506b7f0247bac8ed41
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))
104 return false;
106 if ((new_length > strm.length ()) || (new_length > target.maximum ()))
108 return false;
110 sequence tmp;
111 tmp.length (new_length);
112 typename sequence::value_type *const buffer = tmp.get_buffer ();
113 for (CORBA::ULong i = 0; i < new_length; ++i)
115 forany wrapper (array_traits::alloc ());
116 bool const _tao_marshal_flag = strm >> wrapper;
117 if (_tao_marshal_flag)
119 array_traits::copy (buffer[i], wrapper.in ());
121 array_traits::free (wrapper.inout ());
122 if (!_tao_marshal_flag)
124 return false;
127 tmp.swap (target);
128 return true;
131 template <typename stream, typename T_array, typename T_slice, typename T_tag, CORBA::ULong MAX>
132 bool marshal_sequence(stream & strm, const TAO::bounded_array_sequence<T_array, T_slice, T_tag, MAX> & source) {
133 typedef TAO_Array_Forany_T<T_array, T_slice, T_tag> forany;
134 typedef TAO_FixedArray_Var_T <T_array, T_slice, T_tag> fixed_array;
135 typedef TAO::Array_Traits<forany> array_traits;
136 ::CORBA::ULong const length = source.length ();
137 if (length > source.maximum () || !(strm << length)) {
138 return false;
140 for(CORBA::ULong i = 0; i < length; ++i) {
141 fixed_array tmp_array = array_traits::dup (source[i]);
142 forany tmp (tmp_array.inout ());
143 if (!(strm << tmp)) {
144 return false;
147 return true;
151 TAO_END_VERSIONED_NAMESPACE_DECL
153 #endif // guard_bounded_array_sequence_hpp