File indexing completed on 2025-01-30 09:59:07
0001 #ifndef BOOST_QVM_MAT_TRAITS_DEFAULTS_HPP_INCLUDED
0002 #define BOOST_QVM_MAT_TRAITS_DEFAULTS_HPP_INCLUDED
0003
0004
0005
0006
0007
0008
0009 #include <boost/qvm/config.hpp>
0010 #include <boost/qvm/assert.hpp>
0011
0012 namespace boost { namespace qvm {
0013
0014 template <class>
0015 struct mat_traits;
0016
0017 namespace
0018 qvm_detail
0019 {
0020 template <int I,int N>
0021 struct
0022 matrix_w
0023 {
0024 template <class A>
0025 static
0026 BOOST_QVM_CONSTEXPR BOOST_QVM_INLINE_CRITICAL
0027 typename mat_traits<A>::scalar_type &
0028 write_element_idx( int r, int c, A & a )
0029 {
0030 return (I/mat_traits<A>::cols)==r && (I%mat_traits<A>::cols)==c?
0031 mat_traits<A>::template write_element<I/mat_traits<A>::cols,I%mat_traits<A>::cols>(a) :
0032 matrix_w<I+1,N>::write_element_idx(r,c,a);
0033 }
0034 };
0035
0036 template <int N>
0037 struct
0038 matrix_w<N,N>
0039 {
0040 template <class A>
0041 static
0042 BOOST_QVM_CONSTEXPR BOOST_QVM_INLINE_TRIVIAL
0043 typename mat_traits<A>::scalar_type &
0044 write_element_idx( int, int, A & a )
0045 {
0046 BOOST_QVM_ASSERT(0);
0047 return mat_traits<A>::template write_element<0,0>(a);
0048 }
0049 };
0050 }
0051
0052 template <class MatType,class ScalarType,int Rows,int Cols>
0053 struct
0054 mat_traits_defaults
0055 {
0056 typedef MatType mat_type;
0057 typedef ScalarType scalar_type;
0058 static int const rows=Rows;
0059 static int const cols=Cols;
0060
0061 template <int Row,int Col>
0062 static
0063 BOOST_QVM_CONSTEXPR BOOST_QVM_INLINE_CRITICAL
0064 scalar_type
0065 read_element( mat_type const & x )
0066 {
0067 return mat_traits<mat_type>::template write_element<Row,Col>(const_cast<mat_type &>(x));
0068 }
0069
0070 static
0071 BOOST_QVM_CONSTEXPR BOOST_QVM_INLINE_CRITICAL
0072 scalar_type
0073 read_element_idx( int r, int c, mat_type const & x )
0074 {
0075 return mat_traits<mat_type>::write_element_idx(r,c,const_cast<mat_type &>(x));
0076 }
0077
0078 protected:
0079
0080 static
0081 BOOST_QVM_CONSTEXPR BOOST_QVM_INLINE_TRIVIAL
0082 scalar_type &
0083 write_element_idx( int r, int c, mat_type & m )
0084 {
0085 return qvm_detail::matrix_w<0,mat_traits<mat_type>::rows*mat_traits<mat_type>::cols>::write_element_idx(r,c,m);
0086 }
0087 };
0088
0089 } }
0090
0091 #endif