File indexing completed on 2025-01-18 09:51:07
0001 #ifndef BOOST_QVM_MAT_TRAITS_ARRAY_HPP_INCLUDED
0002 #define BOOST_QVM_MAT_TRAITS_ARRAY_HPP_INCLUDED
0003
0004
0005
0006
0007
0008
0009 #include <boost/qvm/config.hpp>
0010 #include <boost/qvm/deduce_mat.hpp>
0011 #include <boost/qvm/assert.hpp>
0012
0013 #if __cplusplus > 199711L
0014
0015 #include <array>
0016
0017 namespace boost { namespace qvm {
0018
0019 template <class T,std::size_t R,std::size_t Q,std::size_t C>
0020 struct
0021 mat_traits<std::array<std::array<std::array<T,R>,Q>,C> >
0022 {
0023 static int const rows=0;
0024 static int const cols=0;
0025 typedef void scalar_type;
0026 };
0027
0028 template <class T,std::size_t Rows,std::size_t Cols>
0029 struct
0030 mat_traits<std::array<std::array<T,Rows>,Cols> >
0031 {
0032 typedef std::array<std::array<T,Rows>,Cols> this_matrix;
0033 typedef T scalar_type;
0034 static int const rows=Rows;
0035 static int const cols=Cols;
0036
0037 template <int Row,int Col>
0038 static
0039 BOOST_QVM_CONSTEXPR BOOST_QVM_INLINE_CRITICAL
0040 scalar_type
0041 read_element( this_matrix const & x )
0042 {
0043 BOOST_QVM_STATIC_ASSERT(Row>=0);
0044 BOOST_QVM_STATIC_ASSERT(Row<rows);
0045 BOOST_QVM_STATIC_ASSERT(Col>=0);
0046 BOOST_QVM_STATIC_ASSERT(Col<cols);
0047 return x[Row][Col];
0048 }
0049
0050 template <int Row,int Col>
0051 static
0052 BOOST_QVM_CONSTEXPR BOOST_QVM_INLINE_CRITICAL
0053 scalar_type &
0054 write_element( this_matrix & x )
0055 {
0056 BOOST_QVM_STATIC_ASSERT(Row>=0);
0057 BOOST_QVM_STATIC_ASSERT(Row<rows);
0058 BOOST_QVM_STATIC_ASSERT(Col>=0);
0059 BOOST_QVM_STATIC_ASSERT(Col<cols);
0060 return x[Row][Col];
0061 }
0062
0063 static
0064 BOOST_QVM_CONSTEXPR BOOST_QVM_INLINE_CRITICAL
0065 scalar_type
0066 read_element_idx( int row, int col, this_matrix const & x )
0067 {
0068 BOOST_QVM_ASSERT(row>=0);
0069 BOOST_QVM_ASSERT(row<rows);
0070 BOOST_QVM_ASSERT(col>=0);
0071 BOOST_QVM_ASSERT(col<cols);
0072 return x[row][col];
0073 }
0074
0075 static
0076 BOOST_QVM_CONSTEXPR BOOST_QVM_INLINE_CRITICAL
0077 scalar_type &
0078 write_element_idx( int row, int col, this_matrix & x )
0079 {
0080 BOOST_QVM_ASSERT(row>=0);
0081 BOOST_QVM_ASSERT(row<rows);
0082 BOOST_QVM_ASSERT(col>=0);
0083 BOOST_QVM_ASSERT(col<cols);
0084 return x[row][col];
0085 }
0086 };
0087
0088 template <class T,std::size_t Rows,std::size_t Cols>
0089 struct
0090 mat_traits<std::array<std::array<T,Rows>,Cols> const>
0091 {
0092 typedef std::array<std::array<T,Rows>,Cols> const this_matrix;
0093 typedef T scalar_type;
0094 static int const rows=Rows;
0095 static int const cols=Cols;
0096
0097 template <int Row,int Col>
0098 static
0099 BOOST_QVM_CONSTEXPR BOOST_QVM_INLINE_CRITICAL
0100 scalar_type
0101 read_element( this_matrix & x )
0102 {
0103 BOOST_QVM_STATIC_ASSERT(Row>=0);
0104 BOOST_QVM_STATIC_ASSERT(Row<rows);
0105 BOOST_QVM_STATIC_ASSERT(Col>=0);
0106 BOOST_QVM_STATIC_ASSERT(Col<cols);
0107 return x[Row][Col];
0108 }
0109
0110 static
0111 BOOST_QVM_CONSTEXPR BOOST_QVM_INLINE_CRITICAL
0112 scalar_type
0113 read_element_idx( int row, int col, this_matrix & x )
0114 {
0115 BOOST_QVM_ASSERT(row>=0);
0116 BOOST_QVM_ASSERT(row<rows);
0117 BOOST_QVM_ASSERT(col>=0);
0118 BOOST_QVM_ASSERT(col<cols);
0119 return x[row][col];
0120 }
0121 };
0122
0123 template <class T,std::size_t Rows,std::size_t Cols,int R,int C>
0124 struct
0125 deduce_mat<std::array<std::array<T,Rows>,Cols>,R,C>
0126 {
0127 typedef mat<T,R,C> type;
0128 };
0129
0130 template <class T,std::size_t Rows,std::size_t Cols,int R,int C>
0131 struct
0132 deduce_mat<std::array<std::array<T,Rows>,Cols> const,R,C>
0133 {
0134 typedef mat<T,R,C> type;
0135 };
0136
0137 template <class T1,class T2,std::size_t Rows,std::size_t Cols,int R,int C>
0138 struct
0139 deduce_mat2<std::array<std::array<T1,Rows>,Cols>,std::array<std::array<T2,Rows>,Cols>,R,C>
0140 {
0141 typedef mat<typename deduce_scalar<T1,T2>::type,R,C> type;
0142 };
0143
0144 template <class T1,class T2,std::size_t Rows,std::size_t Cols,int R,int C>
0145 struct
0146 deduce_mat2<std::array<std::array<T1,Rows>,Cols> const,std::array<std::array<T2,Rows>,Cols>,R,C>
0147 {
0148 typedef mat<typename deduce_scalar<T1,T2>::type,R,C> type;
0149 };
0150
0151 template <class T1,class T2,std::size_t Rows,std::size_t Cols,int R,int C>
0152 struct
0153 deduce_mat2<std::array<std::array<T1,Rows>,Cols>,std::array<std::array<T2,Rows> const,Cols>,R,C>
0154 {
0155 typedef mat<typename deduce_scalar<T1,T2>::type,R,C> type;
0156 };
0157
0158 template <class T1,class T2,std::size_t Rows,std::size_t Cols,int R,int C>
0159 struct
0160 deduce_mat2<std::array<std::array<T1,Rows>,Cols> const,std::array<std::array<T2,Rows>,Cols> const,R,C>
0161 {
0162 typedef mat<typename deduce_scalar<T1,T2>::type,R,C> type;
0163 };
0164
0165 } }
0166
0167 #endif
0168
0169 namespace boost { namespace qvm {
0170
0171 template <class T,int R,int Q,int C>
0172 struct
0173 mat_traits<T[R][Q][C]>
0174 {
0175 static int const rows=0;
0176 static int const cols=0;
0177 typedef void scalar_type;
0178 };
0179
0180 template <class T,int Rows,int Cols>
0181 struct
0182 mat_traits<T[Rows][Cols]>
0183 {
0184 typedef T this_matrix[Rows][Cols];
0185 typedef T scalar_type;
0186 static int const rows=Rows;
0187 static int const cols=Cols;
0188
0189 template <int Row,int Col>
0190 static
0191 BOOST_QVM_CONSTEXPR BOOST_QVM_INLINE_CRITICAL
0192 scalar_type
0193 read_element( this_matrix const & x )
0194 {
0195 BOOST_QVM_STATIC_ASSERT(Row>=0);
0196 BOOST_QVM_STATIC_ASSERT(Row<rows);
0197 BOOST_QVM_STATIC_ASSERT(Col>=0);
0198 BOOST_QVM_STATIC_ASSERT(Col<cols);
0199 return x[Row][Col];
0200 }
0201
0202 template <int Row,int Col>
0203 static
0204 BOOST_QVM_CONSTEXPR BOOST_QVM_INLINE_CRITICAL
0205 scalar_type &
0206 write_element( this_matrix & x )
0207 {
0208 BOOST_QVM_STATIC_ASSERT(Row>=0);
0209 BOOST_QVM_STATIC_ASSERT(Row<rows);
0210 BOOST_QVM_STATIC_ASSERT(Col>=0);
0211 BOOST_QVM_STATIC_ASSERT(Col<cols);
0212 return x[Row][Col];
0213 }
0214
0215 static
0216 BOOST_QVM_CONSTEXPR BOOST_QVM_INLINE_CRITICAL
0217 scalar_type
0218 read_element_idx( int row, int col, this_matrix const & x )
0219 {
0220 BOOST_QVM_ASSERT(row>=0);
0221 BOOST_QVM_ASSERT(row<Rows);
0222 BOOST_QVM_ASSERT(col>=0);
0223 BOOST_QVM_ASSERT(col<Cols);
0224 return x[row][col];
0225 }
0226
0227 static
0228 BOOST_QVM_CONSTEXPR BOOST_QVM_INLINE_CRITICAL
0229 scalar_type &
0230 write_element_idx( int row, int col, this_matrix & x )
0231 {
0232 BOOST_QVM_ASSERT(row>=0);
0233 BOOST_QVM_ASSERT(row<Rows);
0234 BOOST_QVM_ASSERT(col>=0);
0235 BOOST_QVM_ASSERT(col<Cols);
0236 return x[row][col];
0237 }
0238 };
0239
0240 template <class T,int Rows,int Cols,int R,int C>
0241 struct
0242 deduce_mat<T[Rows][Cols],R,C>
0243 {
0244 typedef mat<T,R,C> type;
0245 };
0246
0247 template <class T,int Rows,int Cols,int R,int C>
0248 struct
0249 deduce_mat<T const[Rows][Cols],R,C>
0250 {
0251 typedef mat<T,R,C> type;
0252 };
0253
0254 template <class T1,class T2,int Rows,int Cols,int R,int C>
0255 struct
0256 deduce_mat2<T1[Rows][Cols],T2[Rows][Cols],R,C>
0257 {
0258 typedef mat<typename deduce_scalar<T1,T2>::type,R,C> type;
0259 };
0260
0261 template <int Rows,int Cols,class T>
0262 T (&ptr_mref( T * ptr ))[Rows][Cols]
0263 {
0264 return *reinterpret_cast<T (*)[Rows][Cols]>(ptr);
0265 }
0266
0267 } }
0268
0269 #endif