liuxiaolong
2021-07-20 58d904a328c0d849769b483e901a0be9426b8209
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
//Copyright (c) 2008-2016 Emil Dotchevski and Reverge Studios, Inc.
 
//Distributed under the Boost Software License, Version 1.0. (See accompanying
//file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
 
#ifndef BOOST_QVM_FB4D5BEAC71B11E68D0EEF1707624D53
#define BOOST_QVM_FB4D5BEAC71B11E68D0EEF1707624D53
 
#include <boost/qvm/inline.hpp>
#include <boost/qvm/assert.hpp>
 
namespace
boost
    {
    namespace
    qvm
        {
        template <class>
        struct mat_traits;
 
        namespace
        qvm_detail
            {
            template <int I,int N>
            struct
            matrix_w
                {
                template <class A>
                static
                BOOST_QVM_INLINE_CRITICAL
                typename mat_traits<A>::scalar_type &
                write_element_idx( int r, int c, A & a )
                    {
                    return (I/mat_traits<A>::cols)==r && (I%mat_traits<A>::cols)==c?
                        mat_traits<A>::template write_element<I/mat_traits<A>::cols,I%mat_traits<A>::cols>(a) :
                        matrix_w<I+1,N>::write_element_idx(r,c,a);
                    }
                };
 
            template <int N>
            struct
            matrix_w<N,N>
                {
                template <class A>
                static
                BOOST_QVM_INLINE_TRIVIAL
                typename mat_traits<A>::scalar_type &
                write_element_idx( int, int, A & a )
                    {
                    BOOST_QVM_ASSERT(0);
                    return mat_traits<A>::template write_element<0,0>(a);
                    }
                };
            }
 
        template <class MatType,class ScalarType,int Rows,int Cols>
        struct
        mat_traits_defaults
            {
            typedef MatType mat_type;
            typedef ScalarType scalar_type;
            static int const rows=Rows;
            static int const cols=Cols;
 
            template <int Row,int Col>
            static
            BOOST_QVM_INLINE_CRITICAL
            scalar_type
            read_element( mat_type const & x )
                {
                return mat_traits<mat_type>::template write_element<Row,Col>(const_cast<mat_type &>(x));
                }
 
            static
            BOOST_QVM_INLINE_CRITICAL
            scalar_type
            read_element_idx( int r, int c, mat_type const & x )
                {
                return mat_traits<mat_type>::write_element_idx(r,c,const_cast<mat_type &>(x));
                }
 
            protected:
 
            static
            BOOST_QVM_INLINE_TRIVIAL
            scalar_type &
            write_element_idx( int r, int c, mat_type & m )
                {
                return qvm_detail::matrix_w<0,mat_traits<mat_type>::rows*mat_traits<mat_type>::cols>::write_element_idx(r,c,m);
                }
            };
        }
    }
 
#endif