| 1 | #ifndef BOOST_QVM_DETAIL_TRANSP_IMPL_HPP_INCLUDED |
| 2 | #define BOOST_QVM_DETAIL_TRANSP_IMPL_HPP_INCLUDED |
| 3 | |
| 4 | // Copyright 2008-2022 Emil Dotchevski and Reverge Studios, Inc. |
| 5 | |
| 6 | // Distributed under the Boost Software License, Version 1.0. (See accompanying |
| 7 | // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) |
| 8 | |
| 9 | #include <boost/qvm/deduce_mat.hpp> |
| 10 | #include <boost/qvm/static_assert.hpp> |
| 11 | #include <boost/qvm/assert.hpp> |
| 12 | |
| 13 | namespace boost { namespace qvm { |
| 14 | |
| 15 | namespace |
| 16 | qvm_detail |
| 17 | { |
| 18 | template <class OriginalMatrix> |
| 19 | class |
| 20 | transposed_ |
| 21 | { |
| 22 | transposed_( transposed_ const & ); |
| 23 | transposed_ & operator=( transposed_ const & ); |
| 24 | ~transposed_(); |
| 25 | |
| 26 | public: |
| 27 | |
| 28 | template <class T> |
| 29 | BOOST_QVM_CONSTEXPR BOOST_QVM_INLINE_TRIVIAL |
| 30 | transposed_ & |
| 31 | operator=( T const & x ) |
| 32 | { |
| 33 | assign(*this,x); |
| 34 | return *this; |
| 35 | } |
| 36 | |
| 37 | template <class R |
| 38 | #if __cplusplus >= 201103L |
| 39 | , class = typename enable_if<is_mat<R> >::type |
| 40 | #endif |
| 41 | > |
| 42 | BOOST_QVM_CONSTEXPR BOOST_QVM_INLINE_TRIVIAL |
| 43 | operator R() const |
| 44 | { |
| 45 | R r; |
| 46 | assign(r,*this); |
| 47 | return r; |
| 48 | } |
| 49 | }; |
| 50 | |
| 51 | template <class OriginalMatrix,bool WriteElementRef=mat_write_element_ref<OriginalMatrix>::value> |
| 52 | struct transposed_write_traits; |
| 53 | |
| 54 | template <class OriginalMatrix> |
| 55 | struct |
| 56 | transposed_write_traits<OriginalMatrix,true> |
| 57 | { |
| 58 | typedef typename mat_traits<OriginalMatrix>::scalar_type scalar_type; |
| 59 | typedef transposed_<OriginalMatrix> this_matrix; |
| 60 | static int const rows=mat_traits<OriginalMatrix>::cols; |
| 61 | static int const cols=mat_traits<OriginalMatrix>::rows; |
| 62 | |
| 63 | template <int Row,int Col> |
| 64 | static |
| 65 | BOOST_QVM_CONSTEXPR BOOST_QVM_INLINE_CRITICAL |
| 66 | scalar_type & |
| 67 | write_element( this_matrix & x ) |
| 68 | { |
| 69 | BOOST_QVM_STATIC_ASSERT(Row>=0); |
| 70 | BOOST_QVM_STATIC_ASSERT(Row<rows); |
| 71 | BOOST_QVM_STATIC_ASSERT(Col>=0); |
| 72 | BOOST_QVM_STATIC_ASSERT(Col<cols); |
| 73 | return mat_traits<OriginalMatrix>::template write_element<Col,Row>(reinterpret_cast<OriginalMatrix &>(x)); |
| 74 | } |
| 75 | |
| 76 | static |
| 77 | BOOST_QVM_CONSTEXPR 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 mat_traits<OriginalMatrix>::write_element_idx(col,row,reinterpret_cast<OriginalMatrix &>(x)); |
| 86 | } |
| 87 | }; |
| 88 | |
| 89 | template <class OriginalMatrix> |
| 90 | struct |
| 91 | transposed_write_traits<OriginalMatrix,false> |
| 92 | { |
| 93 | typedef typename mat_traits<OriginalMatrix>::scalar_type scalar_type; |
| 94 | typedef transposed_<OriginalMatrix> this_matrix; |
| 95 | static int const rows=mat_traits<OriginalMatrix>::cols; |
| 96 | static int const cols=mat_traits<OriginalMatrix>::rows; |
| 97 | |
| 98 | template <int Row,int Col> |
| 99 | static |
| 100 | BOOST_QVM_CONSTEXPR BOOST_QVM_INLINE_CRITICAL |
| 101 | void |
| 102 | write_element( this_matrix & x, scalar_type s ) |
| 103 | { |
| 104 | BOOST_QVM_STATIC_ASSERT(Row>=0); |
| 105 | BOOST_QVM_STATIC_ASSERT(Row<rows); |
| 106 | BOOST_QVM_STATIC_ASSERT(Col>=0); |
| 107 | BOOST_QVM_STATIC_ASSERT(Col<cols); |
| 108 | mat_traits<OriginalMatrix>::template write_element<Col,Row>(reinterpret_cast<OriginalMatrix &>(x), s); |
| 109 | } |
| 110 | |
| 111 | static |
| 112 | BOOST_QVM_CONSTEXPR BOOST_QVM_INLINE_CRITICAL |
| 113 | void |
| 114 | write_element_idx( int row, int col, this_matrix & x, scalar_type s ) |
| 115 | { |
| 116 | BOOST_QVM_ASSERT(row>=0); |
| 117 | BOOST_QVM_ASSERT(row<rows); |
| 118 | BOOST_QVM_ASSERT(col>=0); |
| 119 | BOOST_QVM_ASSERT(col<cols); |
| 120 | mat_traits<OriginalMatrix>::write_element_idx(col,row,reinterpret_cast<OriginalMatrix &>(x), s); |
| 121 | } |
| 122 | }; |
| 123 | } |
| 124 | |
| 125 | template <class OriginalMatrix> |
| 126 | struct |
| 127 | mat_traits< qvm_detail::transposed_<OriginalMatrix> >: |
| 128 | qvm_detail::transposed_write_traits<OriginalMatrix> |
| 129 | { |
| 130 | typedef typename mat_traits<OriginalMatrix>::scalar_type scalar_type; |
| 131 | typedef qvm_detail::transposed_<OriginalMatrix> this_matrix; |
| 132 | static int const rows=mat_traits<OriginalMatrix>::cols; |
| 133 | static int const cols=mat_traits<OriginalMatrix>::rows; |
| 134 | |
| 135 | template <int Row,int Col> |
| 136 | static |
| 137 | BOOST_QVM_CONSTEXPR BOOST_QVM_INLINE_CRITICAL |
| 138 | scalar_type |
| 139 | read_element( this_matrix const & x ) |
| 140 | { |
| 141 | BOOST_QVM_STATIC_ASSERT(Row>=0); |
| 142 | BOOST_QVM_STATIC_ASSERT(Row<rows); |
| 143 | BOOST_QVM_STATIC_ASSERT(Col>=0); |
| 144 | BOOST_QVM_STATIC_ASSERT(Col<cols); |
| 145 | return mat_traits<OriginalMatrix>::template read_element<Col,Row>(reinterpret_cast<OriginalMatrix const &>(x)); |
| 146 | } |
| 147 | |
| 148 | static |
| 149 | BOOST_QVM_CONSTEXPR BOOST_QVM_INLINE_CRITICAL |
| 150 | scalar_type |
| 151 | read_element_idx( int row, int col, this_matrix const & x ) |
| 152 | { |
| 153 | BOOST_QVM_ASSERT(row>=0); |
| 154 | BOOST_QVM_ASSERT(row<rows); |
| 155 | BOOST_QVM_ASSERT(col>=0); |
| 156 | BOOST_QVM_ASSERT(col<cols); |
| 157 | return mat_traits<OriginalMatrix>::read_element_idx(col,row,reinterpret_cast<OriginalMatrix const &>(x)); |
| 158 | } |
| 159 | }; |
| 160 | |
| 161 | template <class OriginalMatrix,int R,int C> |
| 162 | struct |
| 163 | deduce_mat<qvm_detail::transposed_<OriginalMatrix>,R,C> |
| 164 | { |
| 165 | typedef mat<typename mat_traits<OriginalMatrix>::scalar_type,R,C> type; |
| 166 | }; |
| 167 | |
| 168 | template <class OriginalMatrix,int R,int C> |
| 169 | struct |
| 170 | deduce_mat2<qvm_detail::transposed_<OriginalMatrix>,qvm_detail::transposed_<OriginalMatrix>,R,C> |
| 171 | { |
| 172 | typedef mat<typename mat_traits<OriginalMatrix>::scalar_type,R,C> type; |
| 173 | }; |
| 174 | |
| 175 | } } |
| 176 | |
| 177 | #endif |
| 178 | |