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