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_FB4D5BEAC71B11E68D0EEF1707624D53
7 #define UUID_FB4D5BEAC71B11E68D0EEF1707624D53
8 
9 #include <boost/qvm/inline.hpp>
10 #include <boost/qvm/assert.hpp>
11 
12 namespace
13 boost
14     {
15     namespace
16     qvm
17         {
18         template <class>
19         struct mat_traits;
20 
21         namespace
22         qvm_detail
23             {
24             template <int I,int N>
25             struct
26             matrix_w
27                 {
28                 template <class A>
29                 static
30                 BOOST_QVM_INLINE_CRITICAL
31                 typename mat_traits<A>::scalar_type &
write_element_idxboost::qvm::qvm_detail::matrix_w32                 write_element_idx( int r, int c, A & a )
33                     {
34                     return (I/mat_traits<A>::cols)==r && (I%mat_traits<A>::cols)==c?
35                         mat_traits<A>::template write_element<I/mat_traits<A>::cols,I%mat_traits<A>::cols>(a) :
36                         matrix_w<I+1,N>::write_element_idx(r,c,a);
37                     }
38                 };
39 
40             template <int N>
41             struct
42             matrix_w<N,N>
43                 {
44                 template <class A>
45                 static
46                 BOOST_QVM_INLINE_TRIVIAL
47                 typename mat_traits<A>::scalar_type &
write_element_idxboost::qvm::qvm_detail::matrix_w48                 write_element_idx( int, int, A & a )
49                     {
50                     BOOST_QVM_ASSERT(0);
51                     return mat_traits<A>::template write_element<0,0>(a);
52                     }
53                 };
54             }
55 
56         template <class MatType,class ScalarType,int Rows,int Cols>
57         struct
58         mat_traits_defaults
59             {
60             typedef MatType mat_type;
61             typedef ScalarType scalar_type;
62             static int const rows=Rows;
63             static int const cols=Cols;
64 
65             template <int Row,int Col>
66             static
67             BOOST_QVM_INLINE_CRITICAL
68             scalar_type
read_elementboost::qvm::mat_traits_defaults69             read_element( mat_type const & x )
70                 {
71                 return mat_traits<mat_type>::template write_element<Row,Col>(const_cast<mat_type &>(x));
72                 }
73 
74             static
75             BOOST_QVM_INLINE_CRITICAL
76             scalar_type
read_element_idxboost::qvm::mat_traits_defaults77             read_element_idx( int r, int c, mat_type const & x )
78                 {
79                 return mat_traits<mat_type>::write_element_idx(r,c,const_cast<mat_type &>(x));
80                 }
81 
82             protected:
83 
84             static
85             BOOST_QVM_INLINE_TRIVIAL
86             scalar_type &
write_element_idxboost::qvm::mat_traits_defaults87             write_element_idx( int r, int c, mat_type & m )
88                 {
89                 return qvm_detail::matrix_w<0,mat_traits<mat_type>::rows*mat_traits<mat_type>::cols>::write_element_idx(r,c,m);
90                 }
91             };
92         }
93     }
94 
95 #endif
96