1 //Copyright (c) 2008-2016 Emil Dotchevski and Reverge Studios, Inc. 2 3 //Distributed under the Boost Software License, Version 1.0. (See accompanying 4 //file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 5 6 #ifndef UUID_DEC6035EA1C211DEA5E8ECB856D89593 7 #define UUID_DEC6035EA1C211DEA5E8ECB856D89593 8 9 #include <boost/qvm/inline.hpp> 10 #include <boost/qvm/deduce_vec.hpp> 11 #include <boost/qvm/detail/remove_const.hpp> 12 #include <boost/qvm/assert.hpp> 13 14 namespace 15 boost 16 { 17 namespace 18 qvm 19 { 20 template <class T,int M,int N> 21 struct 22 vec_traits<T[M][N]> 23 { 24 static int const dim=0; 25 typedef void scalar_type; 26 }; 27 28 template <class T,int Dim> 29 struct 30 vec_traits<T[Dim]> 31 { 32 typedef T this_vector[Dim]; 33 typedef typename qvm_detail::remove_const<T>::type scalar_type; 34 static int const dim=Dim; 35 36 template <int I> 37 static 38 BOOST_QVM_INLINE_CRITICAL 39 scalar_type read_elementboost::qvm::vec_traits40 read_element( this_vector const & x ) 41 { 42 BOOST_QVM_STATIC_ASSERT(I>=0); 43 BOOST_QVM_STATIC_ASSERT(I<Dim); 44 return x[I]; 45 } 46 47 template <int I> 48 static 49 BOOST_QVM_INLINE_CRITICAL 50 scalar_type & write_elementboost::qvm::vec_traits51 write_element( this_vector & x ) 52 { 53 BOOST_QVM_STATIC_ASSERT(I>=0); 54 BOOST_QVM_STATIC_ASSERT(I<Dim); 55 return x[I]; 56 } 57 58 static 59 BOOST_QVM_INLINE_CRITICAL 60 scalar_type read_element_idxboost::qvm::vec_traits61 read_element_idx( int i, this_vector const & x ) 62 { 63 BOOST_QVM_ASSERT(i>=0); 64 BOOST_QVM_ASSERT(i<Dim); 65 return x[i]; 66 } 67 68 static 69 BOOST_QVM_INLINE_CRITICAL 70 scalar_type & write_element_idxboost::qvm::vec_traits71 write_element_idx( int i, this_vector & x ) 72 { 73 BOOST_QVM_ASSERT(i>=0); 74 BOOST_QVM_ASSERT(i<Dim); 75 return x[i]; 76 } 77 }; 78 79 template <class T,int Dim,int D> 80 struct 81 deduce_vec<T[Dim],D> 82 { 83 typedef vec<T,D> type; 84 }; 85 86 template <class T,int Dim,int D> 87 struct 88 deduce_vec<T const[Dim],D> 89 { 90 typedef vec<T,D> type; 91 }; 92 93 template <class T1,class T2,int Dim,int D> 94 struct 95 deduce_vec2<T1[Dim],T2[Dim],D> 96 { 97 typedef vec<typename deduce_scalar<T1,T2>::type,D> type; 98 }; 99 100 template <int Dim,class T> 101 T (&ptr_vref( T * ptr ))[Dim] __anonb64a9d630102null102 { 103 return *reinterpret_cast<T (*)[Dim]>(ptr); 104 } 105 } 106 } 107 108 #endif 109