]>
Commit | Line | Data |
---|---|---|
7c673cae FG |
1 | //Copyright (c) 2008-2016 Emil Dotchevski and Reverge Studios, Inc. |
2 | ||
3 | //Distributed under the Boost Software License, Version 1.0. (See accompanying | |
4 | //file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) | |
5 | ||
6 | #ifndef UUID_FA3ED0DCA17911DEA6BBA09955D89593 | |
7 | #define UUID_FA3ED0DCA17911DEA6BBA09955D89593 | |
8 | ||
9 | #include <boost/qvm/inline.hpp> | |
10 | #include <boost/qvm/deduce_mat.hpp> | |
11 | #include <boost/qvm/detail/remove_const.hpp> | |
12 | #include <boost/qvm/assert.hpp> | |
13 | ||
14 | namespace | |
15 | boost | |
16 | { | |
17 | namespace | |
18 | qvm | |
19 | { | |
20 | template <class T,int R,int CR,int C> | |
21 | struct | |
22 | mat_traits<T[R][CR][C]> | |
23 | { | |
24 | static int const rows=0; | |
25 | static int const cols=0; | |
26 | typedef void scalar_type; | |
27 | }; | |
28 | ||
29 | template <class T,int Rows,int Cols> | |
30 | struct | |
31 | mat_traits<T[Rows][Cols]> | |
32 | { | |
33 | typedef T this_matrix[Rows][Cols]; | |
34 | typedef typename qvm_detail::remove_const<T>::type scalar_type; | |
35 | static int const rows=Rows; | |
36 | static int const cols=Cols; | |
37 | ||
38 | template <int Row,int Col> | |
39 | static | |
40 | BOOST_QVM_INLINE_CRITICAL | |
41 | scalar_type | |
42 | read_element( this_matrix const & x ) | |
43 | { | |
44 | BOOST_QVM_STATIC_ASSERT(Row>=0); | |
45 | BOOST_QVM_STATIC_ASSERT(Row<Rows); | |
46 | BOOST_QVM_STATIC_ASSERT(Col>=0); | |
47 | BOOST_QVM_STATIC_ASSERT(Col<Cols); | |
48 | return x[Row][Col]; | |
49 | } | |
50 | ||
51 | template <int Row,int Col> | |
52 | static | |
53 | BOOST_QVM_INLINE_CRITICAL | |
54 | scalar_type & | |
55 | write_element( this_matrix & x ) | |
56 | { | |
57 | BOOST_QVM_STATIC_ASSERT(Row>=0); | |
58 | BOOST_QVM_STATIC_ASSERT(Row<Rows); | |
59 | BOOST_QVM_STATIC_ASSERT(Col>=0); | |
60 | BOOST_QVM_STATIC_ASSERT(Col<Cols); | |
61 | return x[Row][Col]; | |
62 | } | |
63 | ||
64 | static | |
65 | BOOST_QVM_INLINE_CRITICAL | |
66 | scalar_type | |
67 | read_element_idx( int row, int col, this_matrix const & x ) | |
68 | { | |
69 | BOOST_QVM_ASSERT(row>=0); | |
70 | BOOST_QVM_ASSERT(row<Rows); | |
71 | BOOST_QVM_ASSERT(col>=0); | |
72 | BOOST_QVM_ASSERT(col<Cols); | |
73 | return x[row][col]; | |
74 | } | |
75 | ||
76 | static | |
77 | BOOST_QVM_INLINE_CRITICAL | |
78 | scalar_type & | |
79 | write_element_idx( int row, int col, this_matrix & x ) | |
80 | { | |
81 | BOOST_QVM_ASSERT(row>=0); | |
82 | BOOST_QVM_ASSERT(row<Rows); | |
83 | BOOST_QVM_ASSERT(col>=0); | |
84 | BOOST_QVM_ASSERT(col<Cols); | |
85 | return x[row][col]; | |
86 | } | |
87 | }; | |
88 | ||
89 | template <class T,int Rows,int Cols,int R,int C> | |
90 | struct | |
91 | deduce_mat<T[Rows][Cols],R,C> | |
92 | { | |
93 | typedef mat<T,R,C> type; | |
94 | }; | |
95 | ||
96 | template <class T,int Rows,int Cols,int R,int C> | |
97 | struct | |
98 | deduce_mat<T const[Rows][Cols],R,C> | |
99 | { | |
100 | typedef mat<T,R,C> type; | |
101 | }; | |
102 | ||
103 | template <class T1,class T2,int Rows,int Cols,int R,int C> | |
104 | struct | |
105 | deduce_mat2<T1[Rows][Cols],T2[Rows][Cols],R,C> | |
106 | { | |
107 | typedef mat<typename deduce_scalar<T1,T2>::type,R,C> type; | |
108 | }; | |
109 | ||
110 | template <int Rows,int Cols,class T> | |
111 | T (&ptr_mref( T * ptr ))[Rows][Cols] | |
112 | { | |
113 | return *reinterpret_cast<T (*)[Rows][Cols]>(ptr); | |
114 | } | |
115 | } | |
116 | } | |
117 | ||
118 | #endif |