00001 /* 00002 * 00003 * Copyright (c) 2002, 2003 Kresimir Fresl, Toon Knapen and 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 * KF acknowledges the support of the Faculty of Civil Engineering, 00010 * University of Zagreb, Croatia. 00011 * 00012 */ 00013 00014 #ifndef BOOST_NUMERIC_BINDINGS_TRAITS_VECTOR_TRAITS_HPP 00015 #define BOOST_NUMERIC_BINDINGS_TRAITS_VECTOR_TRAITS_HPP 00016 00017 #include <boost/numeric/bindings/traits/config.hpp> 00018 00019 #ifndef BOOST_NUMERIC_BINDINGS_POOR_MANS_TRAITS 00020 00021 #include <boost/numeric/bindings/traits/detail/generate_const.hpp> 00022 #include <boost/type_traits/remove_const.hpp> 00023 #ifndef BOOST_NUMERIC_BINDINGS_NO_SANITY_CHECK 00024 # include <boost/type_traits/is_same.hpp> 00025 # include <boost/static_assert.hpp> 00026 #endif 00027 00028 namespace boost { namespace numeric { namespace bindings { namespace traits { 00029 00034 template <typename V, typename T = typename V::value_type > 00035 struct default_vector_traits { 00036 typedef T value_type; 00037 typedef typename detail::generate_const<V,value_type>::type* pointer; // if V is const, pointer will be a const value_type* 00038 00039 static pointer storage (V& v) { return &v[0]; } 00040 static int size (V& v) { return static_cast<int>(v.size()); } 00041 static int stride (V&) { return 1; } 00042 }; 00043 00044 // vector_detail_traits is used to implement specializations of vector_traits. 00045 // VIdentifier is the vector_type without const, while VType can have a const. 00046 // VIdentifier is used to write template specializations for VType and const VType. 00047 // e.g. vector_detail_traits< std::vector<int>, std::vector<int> const > 00048 // e.g. vector_detail_traits< std::vector<int>, std::vector<int> > 00049 // Note that boost::remove_const<VType>::type == VIdentifier. 00050 template <typename VIdentifier, typename VType> 00051 struct vector_detail_traits : default_vector_traits<VType, typename VType::value_type > 00052 { 00053 typedef VIdentifier identifier_type; 00054 typedef VType vector_type; 00055 }; 00056 00057 // vector_traits<> generic version: 00058 template <typename V> 00059 struct vector_traits : vector_detail_traits< typename boost::remove_const<V>::type, V > {}; 00060 00061 00063 // 00064 // free accessor functions: 00065 // 00067 00068 template <typename V> 00069 inline 00070 typename vector_traits<V>::pointer vector_storage (V& v) { 00071 return vector_traits<V>::storage (v); 00072 } 00073 00074 template <typename V> 00075 inline 00076 int vector_size (V& v) { 00077 return vector_traits<V>::size (v); 00078 } 00079 00080 template <typename V> 00081 inline 00082 int vector_stride (V& v) { 00083 return vector_traits<V>::stride (v); 00084 } 00085 00086 }}}} 00087 00088 #else // BOOST_NUMERIC_BINDINGS_POOR_MANS_TRAITS 00089 00090 #include <boost/numeric/bindings/traits/vector_raw.hpp> 00091 00092 #endif // BOOST_NUMERIC_BINDINGS_POOR_MANS_TRAITS 00093 00094 #endif // BOOST_NUMERIC_BINDINGS_TRAITS_VECTOR_TRAITS_HPP