Unbounded_Array_Sequence_T.h

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

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