File indexing completed on 2025-01-18 09:50:42
0001 #ifndef BOOST_QVM_DETAIL_TRANSP_IMPL_HPP_INCLUDED
0002 #define BOOST_QVM_DETAIL_TRANSP_IMPL_HPP_INCLUDED
0003
0004
0005
0006
0007
0008
0009 #include <boost/qvm/deduce_mat.hpp>
0010 #include <boost/qvm/static_assert.hpp>
0011 #include <boost/qvm/assert.hpp>
0012
0013 namespace boost { namespace qvm {
0014
0015 namespace
0016 qvm_detail
0017 {
0018 template <class OriginalMatrix>
0019 class
0020 transposed_
0021 {
0022 transposed_( transposed_ const & );
0023 transposed_ & operator=( transposed_ const & );
0024 ~transposed_();
0025
0026 public:
0027
0028 template <class T>
0029 BOOST_QVM_CONSTEXPR BOOST_QVM_INLINE_TRIVIAL
0030 transposed_ &
0031 operator=( T const & x )
0032 {
0033 assign(*this,x);
0034 return *this;
0035 }
0036
0037 template <class R
0038 #if __cplusplus >= 201103L
0039 , class = typename enable_if<is_mat<R> >::type
0040 #endif
0041 >
0042 BOOST_QVM_CONSTEXPR BOOST_QVM_INLINE_TRIVIAL
0043 operator R() const
0044 {
0045 R r;
0046 assign(r,*this);
0047 return r;
0048 }
0049 };
0050
0051 template <class OriginalMatrix,bool WriteElementRef=mat_write_element_ref<OriginalMatrix>::value>
0052 struct transposed_write_traits;
0053
0054 template <class OriginalMatrix>
0055 struct
0056 transposed_write_traits<OriginalMatrix,true>
0057 {
0058 typedef typename mat_traits<OriginalMatrix>::scalar_type scalar_type;
0059 typedef transposed_<OriginalMatrix> this_matrix;
0060 static int const rows=mat_traits<OriginalMatrix>::cols;
0061 static int const cols=mat_traits<OriginalMatrix>::rows;
0062
0063 template <int Row,int Col>
0064 static
0065 BOOST_QVM_CONSTEXPR BOOST_QVM_INLINE_CRITICAL
0066 scalar_type &
0067 write_element( this_matrix & x )
0068 {
0069 BOOST_QVM_STATIC_ASSERT(Row>=0);
0070 BOOST_QVM_STATIC_ASSERT(Row<rows);
0071 BOOST_QVM_STATIC_ASSERT(Col>=0);
0072 BOOST_QVM_STATIC_ASSERT(Col<cols);
0073 return mat_traits<OriginalMatrix>::template write_element<Col,Row>(reinterpret_cast<OriginalMatrix &>(x));
0074 }
0075
0076 static
0077 BOOST_QVM_CONSTEXPR BOOST_QVM_INLINE_CRITICAL
0078 scalar_type &
0079 write_element_idx( int row, int col, this_matrix & x )
0080 {
0081 BOOST_QVM_ASSERT(row>=0);
0082 BOOST_QVM_ASSERT(row<rows);
0083 BOOST_QVM_ASSERT(col>=0);
0084 BOOST_QVM_ASSERT(col<cols);
0085 return mat_traits<OriginalMatrix>::write_element_idx(col,row,reinterpret_cast<OriginalMatrix &>(x));
0086 }
0087 };
0088
0089 template <class OriginalMatrix>
0090 struct
0091 transposed_write_traits<OriginalMatrix,false>
0092 {
0093 typedef typename mat_traits<OriginalMatrix>::scalar_type scalar_type;
0094 typedef transposed_<OriginalMatrix> this_matrix;
0095 static int const rows=mat_traits<OriginalMatrix>::cols;
0096 static int const cols=mat_traits<OriginalMatrix>::rows;
0097
0098 template <int Row,int Col>
0099 static
0100 BOOST_QVM_CONSTEXPR BOOST_QVM_INLINE_CRITICAL
0101 void
0102 write_element( this_matrix & x, scalar_type s )
0103 {
0104 BOOST_QVM_STATIC_ASSERT(Row>=0);
0105 BOOST_QVM_STATIC_ASSERT(Row<rows);
0106 BOOST_QVM_STATIC_ASSERT(Col>=0);
0107 BOOST_QVM_STATIC_ASSERT(Col<cols);
0108 mat_traits<OriginalMatrix>::template write_element<Col,Row>(reinterpret_cast<OriginalMatrix &>(x), s);
0109 }
0110
0111 static
0112 BOOST_QVM_CONSTEXPR BOOST_QVM_INLINE_CRITICAL
0113 void
0114 write_element_idx( int row, int col, this_matrix & x, scalar_type s )
0115 {
0116 BOOST_QVM_ASSERT(row>=0);
0117 BOOST_QVM_ASSERT(row<rows);
0118 BOOST_QVM_ASSERT(col>=0);
0119 BOOST_QVM_ASSERT(col<cols);
0120 mat_traits<OriginalMatrix>::write_element_idx(col,row,reinterpret_cast<OriginalMatrix &>(x), s);
0121 }
0122 };
0123 }
0124
0125 template <class OriginalMatrix>
0126 struct
0127 mat_traits< qvm_detail::transposed_<OriginalMatrix> >:
0128 qvm_detail::transposed_write_traits<OriginalMatrix>
0129 {
0130 typedef typename mat_traits<OriginalMatrix>::scalar_type scalar_type;
0131 typedef qvm_detail::transposed_<OriginalMatrix> this_matrix;
0132 static int const rows=mat_traits<OriginalMatrix>::cols;
0133 static int const cols=mat_traits<OriginalMatrix>::rows;
0134
0135 template <int Row,int Col>
0136 static
0137 BOOST_QVM_CONSTEXPR BOOST_QVM_INLINE_CRITICAL
0138 scalar_type
0139 read_element( this_matrix const & x )
0140 {
0141 BOOST_QVM_STATIC_ASSERT(Row>=0);
0142 BOOST_QVM_STATIC_ASSERT(Row<rows);
0143 BOOST_QVM_STATIC_ASSERT(Col>=0);
0144 BOOST_QVM_STATIC_ASSERT(Col<cols);
0145 return mat_traits<OriginalMatrix>::template read_element<Col,Row>(reinterpret_cast<OriginalMatrix const &>(x));
0146 }
0147
0148 static
0149 BOOST_QVM_CONSTEXPR BOOST_QVM_INLINE_CRITICAL
0150 scalar_type
0151 read_element_idx( int row, int col, this_matrix const & x )
0152 {
0153 BOOST_QVM_ASSERT(row>=0);
0154 BOOST_QVM_ASSERT(row<rows);
0155 BOOST_QVM_ASSERT(col>=0);
0156 BOOST_QVM_ASSERT(col<cols);
0157 return mat_traits<OriginalMatrix>::read_element_idx(col,row,reinterpret_cast<OriginalMatrix const &>(x));
0158 }
0159 };
0160
0161 template <class OriginalMatrix,int R,int C>
0162 struct
0163 deduce_mat<qvm_detail::transposed_<OriginalMatrix>,R,C>
0164 {
0165 typedef mat<typename mat_traits<OriginalMatrix>::scalar_type,R,C> type;
0166 };
0167
0168 template <class OriginalMatrix,int R,int C>
0169 struct
0170 deduce_mat2<qvm_detail::transposed_<OriginalMatrix>,qvm_detail::transposed_<OriginalMatrix>,R,C>
0171 {
0172 typedef mat<typename mat_traits<OriginalMatrix>::scalar_type,R,C> type;
0173 };
0174
0175 } }
0176
0177 #endif