]>
Commit | Line | Data |
---|---|---|
1e59de90 TL |
1 | #ifndef BOOST_QVM_MAT_HPP_INCLUDED |
2 | #define BOOST_QVM_MAT_HPP_INCLUDED | |
92f5a8d4 | 3 | |
1e59de90 | 4 | // Copyright 2008-2022 Emil Dotchevski and Reverge Studios, Inc. |
92f5a8d4 | 5 | |
1e59de90 TL |
6 | // Distributed under the Boost Software License, Version 1.0. (See accompanying |
7 | // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) | |
92f5a8d4 TL |
8 | |
9 | #include <boost/qvm/detail/mat_assign.hpp> | |
10 | #include <boost/qvm/assert.hpp> | |
11 | #include <boost/qvm/static_assert.hpp> | |
12 | ||
1e59de90 TL |
13 | namespace boost { namespace qvm { |
14 | ||
15 | template <class T,int Rows,int Cols> | |
16 | struct | |
17 | mat | |
92f5a8d4 | 18 | { |
1e59de90 TL |
19 | T a[Rows][Cols]; |
20 | template <class R> | |
21 | operator R() const | |
92f5a8d4 | 22 | { |
1e59de90 TL |
23 | R r; |
24 | assign(r,*this); | |
25 | return r; | |
26 | } | |
27 | }; | |
92f5a8d4 | 28 | |
1e59de90 TL |
29 | template <class M> |
30 | struct mat_traits; | |
92f5a8d4 | 31 | |
1e59de90 TL |
32 | template <class T,int Rows,int Cols> |
33 | struct | |
34 | mat_traits< mat<T,Rows,Cols> > | |
35 | { | |
36 | typedef mat<T,Rows,Cols> this_matrix; | |
37 | typedef T scalar_type; | |
38 | static int const rows=Rows; | |
39 | static int const cols=Cols; | |
92f5a8d4 | 40 | |
1e59de90 TL |
41 | template <int Row,int Col> |
42 | static | |
43 | BOOST_QVM_CONSTEXPR BOOST_QVM_INLINE_CRITICAL | |
44 | scalar_type | |
45 | read_element( this_matrix const & x ) | |
46 | { | |
47 | BOOST_QVM_STATIC_ASSERT(Row>=0); | |
48 | BOOST_QVM_STATIC_ASSERT(Row<Rows); | |
49 | BOOST_QVM_STATIC_ASSERT(Col>=0); | |
50 | BOOST_QVM_STATIC_ASSERT(Col<Cols); | |
51 | return x.a[Row][Col]; | |
52 | } | |
92f5a8d4 | 53 | |
1e59de90 TL |
54 | template <int Row,int Col> |
55 | static | |
56 | BOOST_QVM_CONSTEXPR BOOST_QVM_INLINE_CRITICAL | |
57 | scalar_type & | |
58 | write_element( this_matrix & x ) | |
59 | { | |
60 | BOOST_QVM_STATIC_ASSERT(Row>=0); | |
61 | BOOST_QVM_STATIC_ASSERT(Row<Rows); | |
62 | BOOST_QVM_STATIC_ASSERT(Col>=0); | |
63 | BOOST_QVM_STATIC_ASSERT(Col<Cols); | |
64 | return x.a[Row][Col]; | |
65 | } | |
92f5a8d4 | 66 | |
1e59de90 TL |
67 | static |
68 | BOOST_QVM_CONSTEXPR BOOST_QVM_INLINE_CRITICAL | |
69 | scalar_type | |
70 | read_element_idx( int row, int col, this_matrix const & x ) | |
71 | { | |
72 | BOOST_QVM_ASSERT(row>=0); | |
73 | BOOST_QVM_ASSERT(row<Rows); | |
74 | BOOST_QVM_ASSERT(col>=0); | |
75 | BOOST_QVM_ASSERT(col<Cols); | |
76 | return x.a[row][col]; | |
77 | } | |
92f5a8d4 | 78 | |
1e59de90 TL |
79 | static |
80 | BOOST_QVM_CONSTEXPR BOOST_QVM_INLINE_CRITICAL | |
81 | scalar_type & | |
82 | write_element_idx( int row, int col, this_matrix & x ) | |
83 | { | |
84 | BOOST_QVM_ASSERT(row>=0); | |
85 | BOOST_QVM_ASSERT(row<Rows); | |
86 | BOOST_QVM_ASSERT(col>=0); | |
87 | BOOST_QVM_ASSERT(col<Cols); | |
88 | return x.a[row][col]; | |
92f5a8d4 | 89 | } |
1e59de90 TL |
90 | }; |
91 | ||
92 | } } | |
92f5a8d4 TL |
93 | |
94 | #endif |