Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:51:04

0001 #ifndef BOOST_QVM_MAT_HPP_INCLUDED
0002 #define BOOST_QVM_MAT_HPP_INCLUDED
0003 
0004 // Copyright 2008-2022 Emil Dotchevski and Reverge Studios, Inc.
0005 
0006 // Distributed under the Boost Software License, Version 1.0. (See accompanying
0007 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
0008 
0009 #include <boost/qvm/detail/mat_assign.hpp>
0010 #include <boost/qvm/assert.hpp>
0011 #include <boost/qvm/static_assert.hpp>
0012 
0013 namespace boost { namespace qvm {
0014 
0015 template <class T,int Rows,int Cols>
0016 struct
0017 mat
0018     {
0019     T a[Rows][Cols];
0020     template <class R
0021 #if __cplusplus >= 201103L
0022         , class = typename enable_if<is_mat<R> >::type
0023 #endif
0024     >
0025     operator R() const
0026         {
0027         R r;
0028         assign(r,*this);
0029         return r;
0030         }
0031     };
0032 
0033 template <class M>
0034 struct mat_traits;
0035 
0036 template <class T,int Rows,int Cols>
0037 struct
0038 mat_traits< mat<T,Rows,Cols> >
0039     {
0040     typedef mat<T,Rows,Cols> this_matrix;
0041     typedef T scalar_type;
0042     static int const rows=Rows;
0043     static int const cols=Cols;
0044 
0045     template <int Row,int Col>
0046     static
0047     BOOST_QVM_CONSTEXPR BOOST_QVM_INLINE_CRITICAL
0048     scalar_type
0049     read_element( this_matrix const & x )
0050         {
0051         BOOST_QVM_STATIC_ASSERT(Row>=0);
0052         BOOST_QVM_STATIC_ASSERT(Row<rows);
0053         BOOST_QVM_STATIC_ASSERT(Col>=0);
0054         BOOST_QVM_STATIC_ASSERT(Col<cols);
0055         return x.a[Row][Col];
0056         }
0057 
0058     template <int Row,int Col>
0059     static
0060     BOOST_QVM_CONSTEXPR BOOST_QVM_INLINE_CRITICAL
0061     scalar_type &
0062     write_element( this_matrix & x )
0063         {
0064         BOOST_QVM_STATIC_ASSERT(Row>=0);
0065         BOOST_QVM_STATIC_ASSERT(Row<rows);
0066         BOOST_QVM_STATIC_ASSERT(Col>=0);
0067         BOOST_QVM_STATIC_ASSERT(Col<cols);
0068         return x.a[Row][Col];
0069         }
0070 
0071     static
0072     BOOST_QVM_CONSTEXPR BOOST_QVM_INLINE_CRITICAL
0073     scalar_type
0074     read_element_idx( int row, int col, this_matrix const & x )
0075         {
0076         BOOST_QVM_ASSERT(row>=0);
0077         BOOST_QVM_ASSERT(row<Rows);
0078         BOOST_QVM_ASSERT(col>=0);
0079         BOOST_QVM_ASSERT(col<Cols);
0080         return x.a[row][col];
0081         }
0082 
0083     static
0084     BOOST_QVM_CONSTEXPR BOOST_QVM_INLINE_CRITICAL
0085     scalar_type &
0086     write_element_idx( int row, int col, this_matrix & x )
0087         {
0088         BOOST_QVM_ASSERT(row>=0);
0089         BOOST_QVM_ASSERT(row<Rows);
0090         BOOST_QVM_ASSERT(col>=0);
0091         BOOST_QVM_ASSERT(col<Cols);
0092         return x.a[row][col];
0093         }
0094     };
0095 
0096 } }
0097 
0098 #endif