• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 BOOST_QVM_67E67D68A32F11DEA56FD18556D89593
7 #define BOOST_QVM_67E67D68A32F11DEA56FD18556D89593
8 
9 #include <boost/qvm/detail/mat_assign.hpp>
10 #include <boost/qvm/assert.hpp>
11 #include <boost/qvm/static_assert.hpp>
12 
13 namespace
14 boost
15     {
16     namespace
17     qvm
18         {
19         template <class T,int Rows,int Cols>
20         struct
21         mat
22             {
23             T a[Rows][Cols];
24             template <class R>
operator Rboost::qvm::mat25             operator R() const
26                 {
27                 R r;
28                 assign(r,*this);
29                 return r;
30                 }
31             };
32 
33         template <class M>
34         struct mat_traits;
35 
36         template <class T,int Rows,int Cols>
37         struct
38         mat_traits< mat<T,Rows,Cols> >
39             {
40             typedef mat<T,Rows,Cols> this_matrix;
41             typedef T scalar_type;
42             static int const rows=Rows;
43             static int const cols=Cols;
44 
45             template <int Row,int Col>
46             static
47             BOOST_QVM_INLINE_CRITICAL
48             scalar_type
read_elementboost::qvm::mat_traits49             read_element( this_matrix const & x )
50                 {
51                 BOOST_QVM_STATIC_ASSERT(Row>=0);
52                 BOOST_QVM_STATIC_ASSERT(Row<Rows);
53                 BOOST_QVM_STATIC_ASSERT(Col>=0);
54                 BOOST_QVM_STATIC_ASSERT(Col<Cols);
55                 return x.a[Row][Col];
56                 }
57 
58             template <int Row,int Col>
59             static
60             BOOST_QVM_INLINE_CRITICAL
61             scalar_type &
write_elementboost::qvm::mat_traits62             write_element( this_matrix & x )
63                 {
64                 BOOST_QVM_STATIC_ASSERT(Row>=0);
65                 BOOST_QVM_STATIC_ASSERT(Row<Rows);
66                 BOOST_QVM_STATIC_ASSERT(Col>=0);
67                 BOOST_QVM_STATIC_ASSERT(Col<Cols);
68                 return x.a[Row][Col];
69                 }
70 
71             static
72             BOOST_QVM_INLINE_CRITICAL
73             scalar_type
read_element_idxboost::qvm::mat_traits74             read_element_idx( int row, int col, this_matrix const & x )
75                 {
76                 BOOST_QVM_ASSERT(row>=0);
77                 BOOST_QVM_ASSERT(row<Rows);
78                 BOOST_QVM_ASSERT(col>=0);
79                 BOOST_QVM_ASSERT(col<Cols);
80                 return x.a[row][col];
81                 }
82 
83             static
84             BOOST_QVM_INLINE_CRITICAL
85             scalar_type &
write_element_idxboost::qvm::mat_traits86             write_element_idx( int row, int col, this_matrix & x )
87                 {
88                 BOOST_QVM_ASSERT(row>=0);
89                 BOOST_QVM_ASSERT(row<Rows);
90                 BOOST_QVM_ASSERT(col>=0);
91                 BOOST_QVM_ASSERT(col<Cols);
92                 return x.a[row][col];
93                 }
94             };
95         }
96     }
97 
98 #endif
99