| 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_B3B8081A277711E09E007F2DDFD72085
|
| 7 | #define UUID_B3B8081A277711E09E007F2DDFD72085
|
| 8 |
|
| 9 | #include <boost/qvm/deduce_mat.hpp>
|
| 10 | #include <boost/qvm/static_assert.hpp>
|
| 11 | #include <boost/qvm/assert.hpp>
|
| 12 |
|
| 13 | namespace
|
| 14 | boost
|
| 15 | {
|
| 16 | namespace
|
| 17 | qvm
|
| 18 | {
|
| 19 | namespace
|
| 20 | qvm_detail
|
| 21 | {
|
| 22 | template <class OriginalMatrix>
|
| 23 | class
|
| 24 | transposed_
|
| 25 | {
|
| 26 | transposed_( transposed_ const & );
|
| 27 | transposed_ & operator=( transposed_ const & );
|
| 28 | ~transposed_();
|
| 29 |
|
| 30 | public:
|
| 31 |
|
| 32 | template <class T>
|
| 33 | BOOST_QVM_INLINE_TRIVIAL
|
| 34 | transposed_ &
|
| 35 | operator=( T const & x )
|
| 36 | {
|
| 37 | assign(*this,x);
|
| 38 | return *this;
|
| 39 | }
|
| 40 |
|
| 41 | template <class R>
|
| 42 | BOOST_QVM_INLINE_TRIVIAL
|
| 43 | operator R() const
|
| 44 | {
|
| 45 | R r;
|
| 46 | assign(r,*this);
|
| 47 | return r;
|
| 48 | }
|
| 49 | };
|
| 50 | }
|
| 51 |
|
| 52 | template <class OriginalMatrix>
|
| 53 | struct
|
| 54 | mat_traits< qvm_detail::transposed_<OriginalMatrix> >
|
| 55 | {
|
| 56 | typedef typename mat_traits<OriginalMatrix>::scalar_type scalar_type;
|
| 57 | typedef qvm_detail::transposed_<OriginalMatrix> this_matrix;
|
| 58 | static int const rows=mat_traits<OriginalMatrix>::cols;
|
| 59 | static int const cols=mat_traits<OriginalMatrix>::rows;
|
| 60 |
|
| 61 | template <int Row,int Col>
|
| 62 | static
|
| 63 | BOOST_QVM_INLINE_CRITICAL
|
| 64 | scalar_type
|
| 65 | read_element( this_matrix const & x )
|
| 66 | {
|
| 67 | BOOST_QVM_STATIC_ASSERT(Row>=0);
|
| 68 | BOOST_QVM_STATIC_ASSERT(Row<rows);
|
| 69 | BOOST_QVM_STATIC_ASSERT(Col>=0);
|
| 70 | BOOST_QVM_STATIC_ASSERT(Col<cols);
|
| 71 | return mat_traits<OriginalMatrix>::template read_element<Col,Row>(reinterpret_cast<OriginalMatrix const &>(x));
|
| 72 | }
|
| 73 |
|
| 74 | template <int Row,int Col>
|
| 75 | static
|
| 76 | BOOST_QVM_INLINE_CRITICAL
|
| 77 | scalar_type &
|
| 78 | write_element( this_matrix & x )
|
| 79 | {
|
| 80 | BOOST_QVM_STATIC_ASSERT(Row>=0);
|
| 81 | BOOST_QVM_STATIC_ASSERT(Row<rows);
|
| 82 | BOOST_QVM_STATIC_ASSERT(Col>=0);
|
| 83 | BOOST_QVM_STATIC_ASSERT(Col<cols);
|
| 84 | return mat_traits<OriginalMatrix>::template write_element<Col,Row>(reinterpret_cast<OriginalMatrix &>(x));
|
| 85 | }
|
| 86 |
|
| 87 | static
|
| 88 | BOOST_QVM_INLINE_CRITICAL
|
| 89 | scalar_type
|
| 90 | read_element_idx( int row, int col, this_matrix const & x )
|
| 91 | {
|
| 92 | BOOST_QVM_ASSERT(row>=0);
|
| 93 | BOOST_QVM_ASSERT(row<rows);
|
| 94 | BOOST_QVM_ASSERT(col>=0);
|
| 95 | BOOST_QVM_ASSERT(col<cols);
|
| 96 | return mat_traits<OriginalMatrix>::read_element_idx(col,row,reinterpret_cast<OriginalMatrix const &>(x));
|
| 97 | }
|
| 98 |
|
| 99 | static
|
| 100 | BOOST_QVM_INLINE_CRITICAL
|
| 101 | scalar_type &
|
| 102 | write_element_idx( int row, int col, this_matrix & x )
|
| 103 | {
|
| 104 | BOOST_QVM_ASSERT(row>=0);
|
| 105 | BOOST_QVM_ASSERT(row<rows);
|
| 106 | BOOST_QVM_ASSERT(col>=0);
|
| 107 | BOOST_QVM_ASSERT(col<cols);
|
| 108 | return mat_traits<OriginalMatrix>::write_element_idx(col,row,reinterpret_cast<OriginalMatrix &>(x));
|
| 109 | }
|
| 110 | };
|
| 111 |
|
| 112 | template <class OriginalMatrix,int R,int C>
|
| 113 | struct
|
| 114 | deduce_mat<qvm_detail::transposed_<OriginalMatrix>,R,C>
|
| 115 | {
|
| 116 | typedef mat<typename mat_traits<OriginalMatrix>::scalar_type,R,C> type;
|
| 117 | };
|
| 118 |
|
| 119 | template <class OriginalMatrix,int R,int C>
|
| 120 | struct
|
| 121 | deduce_mat2<qvm_detail::transposed_<OriginalMatrix>,qvm_detail::transposed_<OriginalMatrix>,R,C>
|
| 122 | {
|
| 123 | typedef mat<typename mat_traits<OriginalMatrix>::scalar_type,R,C> type;
|
| 124 | };
|
| 125 | }
|
| 126 | }
|
| 127 |
|
| 128 | #endif
|
| 129 | |