vector_raw.hpp

Go to the documentation of this file.
00001 //
00002 //  Copyright (c) 2002,2003,2004
00003 //  Toon Knapen, Kresimir Fresl, Joerg Walter, Karl Meerbergen
00004 //
00005 // Distributed under the Boost Software License, Version 1.0. 
00006 // (See accompanying file LICENSE_1_0.txt or copy at 
00007 // http://www.boost.org/LICENSE_1_0.txt)
00008 //
00009 
00010 #ifndef BOOST_NUMERIC_BINDINGS_TRAITS_VECTOR_RAW_HPP
00011 #define BOOST_NUMERIC_BINDINGS_TRAITS_VECTOR_RAW_HPP
00012 
00013 #include <cstddef> 
00014 #include <boost/numeric/ublas/config.hpp> 
00015 #ifndef BOOST_UBLAS_HAVE_BINDINGS
00016 #  include <boost/numeric/ublas/vector.hpp> 
00017 #endif 
00018 #include <vector> 
00019 #include <boost/numeric/bindings/traits/detail/array_impl.hpp> 
00020 
00021 namespace boost { namespace numeric { namespace bindings { namespace traits {
00022 
00023   template <typename V>
00024   BOOST_UBLAS_INLINE
00025   int vector_size (const V &v) {
00026     return (int) v.size();
00027   }
00028 
00030   // ublas::vector<> etc. 
00031 
00032   namespace ublas = boost::numeric::ublas; 
00033 
00034 #if 0
00035   // MSVC seems to dislike overloads if there is `generic' template 
00036   template <typename V>
00037   BOOST_UBLAS_INLINE
00038   int vector_size (const ublas::vector_reference<V> &v) {
00039     return vector_size (v.expression());
00040   }
00041 #endif 
00042 
00043 #if 0
00044   // MSVC seems to dislike overloads if there is `generic' template 
00045   template <typename V>
00046   BOOST_UBLAS_INLINE
00047   int vector_stride (const V &v) { return 1; }
00048 #endif 
00049   template <typename T, typename A>
00050   BOOST_UBLAS_INLINE
00051   int vector_stride (const ublas::vector<T,A> &v) { return 1; }
00052   template <typename V>
00053   BOOST_UBLAS_INLINE
00054   int vector_stride (const ublas::vector_reference<V> &v) {
00055     return (int) vector_stride (v.expression());
00056   }
00057   template <typename T, std::size_t N>
00058   BOOST_UBLAS_INLINE
00059   int vector_stride (const ublas::c_vector<T, N> &v) { return 1; }
00060   template <typename V>
00061   int vector_stride (const ublas::vector_slice<V>&);
00062   template <typename V>
00063   BOOST_UBLAS_INLINE
00064   int vector_stride (const ublas::vector_range<V> &v) {
00065     return (int) vector_stride (v.data());
00066   }
00067   template <typename V>
00068   BOOST_UBLAS_INLINE
00069   int vector_stride (const ublas::vector_slice<V> &v) {
00070     return (int) (v.stride() * vector_stride (v.data()));
00071   }
00072 
00073 
00074 #ifndef BOOST_NO_FUNCTION_TEMPLATE_ORDERING
00075   template <typename T, typename A>
00076   BOOST_UBLAS_INLINE
00077   typename ublas::vector<T,A>::value_type const* 
00078   vector_storage (const ublas::vector<T,A> &v) {
00079     return &v.data().begin()[0];
00080   }
00081 #endif
00082   // We need storage_const() mostly due to MSVC 6.0.
00083   // But how shall we write portable code otherwise?
00084   template <typename T, typename A>
00085   BOOST_UBLAS_INLINE
00086   typename ublas::vector<T,A>::value_type const* 
00087   vector_storage_const (const ublas::vector<T,A> &v) {
00088     return &v.data().begin()[0];
00089   }
00090   template <typename T, typename A>
00091   BOOST_UBLAS_INLINE
00092   typename ublas::vector<T,A>::value_type* 
00093   vector_storage (ublas::vector<T,A> &v) {
00094     return &v.data().begin()[0];
00095   }
00096 
00097 #if 0
00098   // MSVC seems to dislike overloads if there is `generic' template 
00099 #ifndef BOOST_NO_FUNCTION_TEMPLATE_ORDERING
00100   template <typename V>
00101   BOOST_UBLAS_INLINE
00102   typename V::const_pointer vector_storage (const V &v) {
00103     return &v.data().begin()[0];
00104   }
00105 #endif
00106   // We need storage_const() mostly due to MSVC 6.0.
00107   // But how shall we write portable code otherwise?
00108   template <typename V>
00109   BOOST_UBLAS_INLINE
00110   typename V::const_pointer vector_storage_const (const V &v) {
00111     return &v.data().begin()[0];
00112   }
00113   template <typename V>
00114   BOOST_UBLAS_INLINE
00115   typename V::pointer vector_storage (V &v) {
00116     return &v.data().begin()[0];
00117   }
00118 #endif 
00119 
00120 #ifndef BOOST_NO_FUNCTION_TEMPLATE_ORDERING
00121   template <typename V>
00122   BOOST_UBLAS_INLINE
00123   typename V::value_type const* 
00124   vector_storage (const ublas::vector_reference<V> &v) {
00125     return vector_storage (v.expression());
00126   }
00127 #endif
00128   // We need storage_const() mostly due to MSVC 6.0.
00129   // But how shall we write portable code otherwise?
00130   template <typename V>
00131   BOOST_UBLAS_INLINE
00132   typename V::value_type const* 
00133   vector_storage_const (const ublas::vector_reference<V> &v) {
00134     return vector_storage_const (v.expression());
00135   }
00136   template <typename V>
00137   BOOST_UBLAS_INLINE
00138   typename V::value_type* vector_storage (ublas::vector_reference<V> &v) {
00139     return vector_storage (v.expression());
00140   }
00141 
00142 #ifndef BOOST_NO_FUNCTION_TEMPLATE_ORDERING
00143   template <typename T, std::size_t N>
00144   BOOST_UBLAS_INLINE
00145   typename ublas::c_vector<T, N>::value_type const* 
00146   vector_storage (const ublas::c_vector<T, N> &v) {
00147     return v.data();
00148   }
00149 #endif
00150 #ifndef BOOST_MSVC
00151   // We need storage_const() mostly due to MSVC 6.0.
00152   // But how shall we write portable code otherwise?
00153   template <typename T, std::size_t N>
00154   BOOST_UBLAS_INLINE
00155   typename ublas::c_vector<T, N>::value_type const* 
00156   vector_storage_const (const ublas::c_vector<T, N> &v) {
00157     return v.data();
00158   }
00159   template <typename T, std::size_t N>
00160   BOOST_UBLAS_INLINE
00161   typename ublas::c_vector<T, N>::value_type* 
00162   vector_storage (ublas::c_vector<T, N> &v) {
00163     return v.data();
00164   }
00165 #endif
00166 
00167 #ifndef BOOST_NO_FUNCTION_TEMPLATE_ORDERING
00168   template <typename V>
00169   typename V::value_type const* vector_storage (const ublas::vector_slice<V>&);
00170   template <typename V>
00171   BOOST_UBLAS_INLINE
00172   typename V::value_type const* vector_storage (const ublas::vector_range<V> &v) {
00173     typename V::value_type const* ptr = vector_storage (v.data());
00174     ptr += v.start() * vector_stride (v.data());
00175     return ptr;
00176   }
00177   template <typename V>
00178   BOOST_UBLAS_INLINE
00179   typename V::value_type const* vector_storage (const ublas::vector_slice<V> &v) {
00180     typename V::value_type const* ptr = vector_storage (v.data());
00181     ptr += v.start() * vector_stride (v.data());
00182     return ptr;
00183   }
00184 #endif
00185   // We need storage_const() mostly due to MSVC 6.0.
00186   // But how shall we write portable code otherwise?
00187   template <typename V>
00188   typename V::value_type const* 
00189   vector_storage_const (const ublas::vector_slice<V>&);
00190   template <typename V>
00191   BOOST_UBLAS_INLINE
00192   typename V::value_type const* 
00193   vector_storage_const (const ublas::vector_range<V> &v) {
00194     typename V::value_type const* ptr = vector_storage_const (v.data());
00195     ptr += v.start() * vector_stride (v.data());
00196     return ptr;
00197   }
00198   template <typename V>
00199   BOOST_UBLAS_INLINE
00200   typename V::value_type const* 
00201   vector_storage_const (const ublas::vector_slice<V> &v) {
00202     typename V::value_type const* ptr = vector_storage_const (v.data());
00203     ptr += v.start() * vector_stride (v.data());
00204     return ptr;
00205   }
00206   template <typename V>
00207   typename V::value_type* vector_storage (ublas::vector_slice<V>&);
00208   template <typename V>
00209   BOOST_UBLAS_INLINE
00210   typename V::value_type* vector_storage (ublas::vector_range<V> &v) {
00211     typename V::value_type* ptr = vector_storage (v.data());
00212     ptr += v.start() * vector_stride (v.data());
00213     return ptr;
00214   }
00215   template <typename V>
00216   BOOST_UBLAS_INLINE
00217   typename V::value_type* vector_storage (ublas::vector_slice<V> &v) {
00218     typename V::value_type* ptr = vector_storage (v.data());
00219     ptr += v.start() * vector_stride (v.data());
00220     return ptr;
00221   }
00222 
00223 
00225   // std::vector<> 
00226 
00227   template <typename T, typename A>
00228   BOOST_UBLAS_INLINE
00229   int vector_stride (const std::vector<T,A> &v) { return 1; }
00230 
00231 #ifndef BOOST_NO_FUNCTION_TEMPLATE_ORDERING
00232   template <typename T, typename A>
00233   BOOST_UBLAS_INLINE
00234   typename std::vector<T, A>::value_type const* 
00235   vector_storage (const std::vector<T, A> &v) { return &v.front(); }
00236 #endif
00237   // We need storage_const() mostly due to MSVC 6.0.
00238   // But how shall we write portable code otherwise?
00239   template <typename T, typename A>
00240   BOOST_UBLAS_INLINE
00241   typename std::vector<T, A>::value_type const* 
00242   vector_storage_const (const std::vector<T, A> &v) { return &v.front(); }
00243   template <typename T, typename A>
00244   BOOST_UBLAS_INLINE
00245   typename std::vector<T, A>::value_type* vector_storage (std::vector<T, A> &v) {
00246     return &v.front();
00247   }
00248 
00249 
00251   // bindings::traits::detail::array<>
00252 
00253   template <typename T>
00254   BOOST_UBLAS_INLINE
00255   int vector_stride (const detail::array<T> &a) { return 1; }
00256 
00257 #ifndef BOOST_NO_FUNCTION_TEMPLATE_ORDERING
00258   template <typename T> 
00259   BOOST_UBLAS_INLINE
00260   const T* vector_storage (const detail::array<T> &a) { return a.storage(); }
00261 #endif 
00262   // We need storage_const() mostly due to MSVC 6.0.
00263   // But how shall we write portable code otherwise?
00264   template <typename T> 
00265   BOOST_UBLAS_INLINE
00266   const T* vector_storage_const (const detail::array<T> &a) { 
00267     return a.storage(); 
00268   }
00269   template <typename T> 
00270   BOOST_UBLAS_INLINE
00271   T* vector_storage (detail::array<T> &a) { return a.storage(); }
00272 
00273 
00274 }}}}
00275 
00276 #endif

Generated on Wed Nov 23 19:00:56 2011 for FreeCAD by  doxygen 1.6.1