Bounded_Array_Sequence_T.h

Go to the documentation of this file.
00001 #ifndef guard_bounded_array_sequence_hpp
00002 #define guard_bounded_array_sequence_hpp
00003 /**
00004  * @file
00005  *
00006  * @brief Implement unbounded sequences for arrays.
00007  *
00008  * Bounded_Array_Sequence_T.h,v 1.9 2006/06/29 09:25:28 jwillemsen Exp
00009  *
00010  * @author Carlos O'Ryan
00011  */
00012 #include "tao/Bounded_Array_Allocation_Traits_T.h"
00013 #include "tao/Generic_Sequence_T.h"
00014 #include "tao/Array_Traits_T.h"
00015 #include "tao/SystemException.h"
00016 
00017 TAO_BEGIN_VERSIONED_NAMESPACE_DECL
00018 
00019 namespace TAO
00020 {
00021 
00022 template<typename T_array, typename T_slice, typename T_tag, CORBA::ULong MAX>
00023 class bounded_array_sequence
00024 {
00025 public:
00026   typedef T_array * element_type;
00027   typedef T_array value_type;
00028   typedef T_array * T_slice_ptr;
00029   typedef T_slice_ptr * const_value_type;
00030   typedef value_type & subscript_type;
00031   typedef value_type const & const_subscript_type;
00032 
00033   typedef details::bounded_array_allocation_traits<value_type,MAX,true> allocation_traits;
00034   typedef TAO_Array_Forany_T<T_array, T_slice, T_tag> forany;
00035   typedef details::array_traits <forany> element_traits;
00036   typedef details::generic_sequence<value_type, allocation_traits, element_traits> implementation_type;
00037 
00038   inline bounded_array_sequence()
00039     : impl_()
00040   {}
00041   inline bounded_array_sequence(
00042       CORBA::ULong length,
00043       value_type * data,
00044       CORBA::Boolean release = false)
00045     : impl_(MAX, length, data, release)
00046   {}
00047   inline CORBA::ULong maximum() const {
00048     return impl_.maximum();
00049   }
00050   inline CORBA::Boolean release() const {
00051     return impl_.release();
00052   }
00053   inline CORBA::ULong length() const {
00054     return impl_.length();
00055   }
00056   inline void length(CORBA::ULong length) {
00057     impl_.length(length);
00058   }
00059   inline value_type const & operator[](CORBA::ULong i) const {
00060     return impl_[i];
00061   }
00062   inline value_type & operator[](CORBA::ULong i) {
00063     return impl_[i];
00064   }
00065   inline void replace(
00066       CORBA::ULong length,
00067       value_type * data,
00068       CORBA::Boolean release = false) {
00069     impl_.replace(MAX, length, data, release);
00070   }
00071   inline value_type const * get_buffer() const {
00072     return impl_.get_buffer();
00073   }
00074   inline value_type * get_buffer(CORBA::Boolean orphan = false) {
00075     return impl_.get_buffer(orphan);
00076   }
00077   inline void swap(bounded_array_sequence & rhs) throw() {
00078     impl_.swap(rhs.impl_);
00079   }
00080   static value_type * allocbuf(CORBA::ULong maximum) {
00081     return implementation_type::allocbuf(maximum);
00082   }
00083   static void freebuf(value_type * buffer) {
00084     implementation_type::freebuf(buffer);
00085   }
00086 
00087 private:
00088   implementation_type impl_;
00089 };
00090 }
00091 
00092 namespace TAO
00093 {
00094   template <typename stream, typename T_array, typename T_slice, typename T_tag, CORBA::ULong MAX>
00095   bool demarshal_sequence(stream & strm, TAO::bounded_array_sequence<T_array, T_slice, T_tag, MAX> & target) {
00096     typedef typename TAO::bounded_array_sequence<T_array, T_slice, T_tag, MAX> sequence;
00097     typedef TAO_Array_Forany_T<T_array, T_slice, T_tag> forany;
00098     typedef TAO::Array_Traits<forany> array_traits;
00099 
00100     ::CORBA::ULong new_length = 0;
00101     if (!(strm >> new_length)) {
00102       return false;
00103     }
00104     if ((new_length > strm.length()) || (new_length > target.maximum ())) {
00105       return false;
00106     }
00107     sequence tmp;
00108     tmp.length(new_length);
00109     typename sequence::value_type * buffer = tmp.get_buffer();
00110     for(CORBA::ULong i = 0; i < new_length; ++i) {
00111       forany tmp (array_traits::alloc ());
00112       bool const _tao_marshal_flag = (strm >> tmp);
00113       if (_tao_marshal_flag) {
00114         array_traits::copy (buffer[i], tmp.in ());
00115       }
00116       array_traits::free (tmp.inout ());
00117       if (!_tao_marshal_flag) {
00118         return false;
00119       }
00120     }
00121     tmp.swap(target);
00122     return true;
00123   }
00124 
00125   template <typename stream, typename T_array, typename T_slice, typename T_tag, CORBA::ULong MAX>
00126   bool marshal_sequence(stream & strm, const TAO::bounded_array_sequence<T_array, T_slice, T_tag, MAX> & source) {
00127     if (0 == &source)
00128       ACE_THROW_RETURN (::CORBA::BAD_PARAM(0, CORBA::COMPLETED_MAYBE), false);
00129     typedef TAO_Array_Forany_T<T_array, T_slice, T_tag> forany;
00130     typedef TAO_FixedArray_Var_T <T_array, T_slice, T_tag> fixed_array;
00131     typedef TAO::Array_Traits<forany> array_traits;
00132     ::CORBA::ULong const length = source.length ();
00133     if (!(strm << length)) {
00134       return false;
00135     }
00136     for(CORBA::ULong i = 0; i < length; ++i) {
00137       fixed_array tmp_array = array_traits::dup (source[i]);
00138       forany tmp (tmp_array.inout ());
00139       if (!(strm << tmp)) {
00140         return false;
00141       }
00142     }
00143     return true;
00144   }
00145 }
00146 
00147 TAO_END_VERSIONED_NAMESPACE_DECL
00148 
00149 #endif // guard_bounded_array_sequence_hpp

Generated on Thu Nov 9 11:54:08 2006 for TAO by doxygen 1.3.6