#ifndef BOOST_QVM_MAP_MAT_MAT_HPP_INCLUDED #define BOOST_QVM_MAP_MAT_MAT_HPP_INCLUDED /// Copyright (c) 2008-2021 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) #include #include #include #include #include namespace boost { namespace qvm { namespace qvm_detail { template class del_row_ { del_row_( del_row_ const & ); del_row_ & operator=( del_row_ const & ); ~del_row_(); public: template BOOST_QVM_INLINE_TRIVIAL del_row_ & operator=( T const & x ) { assign(*this,x); return *this; } template BOOST_QVM_INLINE_TRIVIAL operator R() const { R r; assign(r,*this); return r; } }; } template struct mat_traits< qvm_detail::del_row_ > { typedef qvm_detail::del_row_ this_matrix; typedef typename mat_traits::scalar_type scalar_type; static int const rows=mat_traits::rows-1; static int const cols=mat_traits::cols; template static BOOST_QVM_INLINE_CRITICAL scalar_type read_element( this_matrix const & x ) { BOOST_QVM_STATIC_ASSERT(Row>=0); BOOST_QVM_STATIC_ASSERT(Row=0); BOOST_QVM_STATIC_ASSERT(Col::template read_element=I),Col>(reinterpret_cast(x)); } template static BOOST_QVM_INLINE_CRITICAL scalar_type & write_element( this_matrix & x ) { BOOST_QVM_STATIC_ASSERT(Row>=0); BOOST_QVM_STATIC_ASSERT(Row=0); BOOST_QVM_STATIC_ASSERT(Col::template write_element=I),Col>(reinterpret_cast(x)); } static BOOST_QVM_INLINE_CRITICAL scalar_type read_element_idx( int row, int col, this_matrix const & x ) { BOOST_QVM_ASSERT(row>=0); BOOST_QVM_ASSERT(row=0); BOOST_QVM_ASSERT(col::read_element_idx(row+(row>=I),col,reinterpret_cast(x)); } static BOOST_QVM_INLINE_CRITICAL scalar_type & write_element_idx( int row, int col, this_matrix & x ) { BOOST_QVM_ASSERT(row>=0); BOOST_QVM_ASSERT(row=0); BOOST_QVM_ASSERT(col::write_element_idx(row+(row>=I),col,reinterpret_cast(x)); } }; template struct deduce_mat,R,C> { typedef mat::scalar_type,R,C> type; }; template struct deduce_mat2,qvm_detail::del_row_,R,C> { typedef mat::scalar_type,R,C> type; }; template typename enable_if_c< is_mat::value, qvm_detail::del_row_ const &>::type BOOST_QVM_INLINE_TRIVIAL del_row( A const & a ) { return reinterpret_cast const &>(a); } template typename enable_if_c< is_mat::value, qvm_detail::del_row_ &>::type BOOST_QVM_INLINE_TRIVIAL del_row( A & a ) { return reinterpret_cast &>(a); } //////////////////////////////////////////////// namespace qvm_detail { template class del_col_ { del_col_( del_col_ const & ); del_col_ & operator=( del_col_ const & ); ~del_col_(); public: template BOOST_QVM_INLINE_TRIVIAL del_col_ & operator=( T const & x ) { assign(*this,x); return *this; } template BOOST_QVM_INLINE_TRIVIAL operator R() const { R r; assign(r,*this); return r; } }; } template struct mat_traits< qvm_detail::del_col_ > { typedef qvm_detail::del_col_ this_matrix; typedef typename mat_traits::scalar_type scalar_type; static int const rows=mat_traits::rows; static int const cols=mat_traits::cols-1; template static BOOST_QVM_INLINE_CRITICAL scalar_type read_element( this_matrix const & x ) { BOOST_QVM_STATIC_ASSERT(Row>=0); BOOST_QVM_STATIC_ASSERT(Row=0); BOOST_QVM_STATIC_ASSERT(Col::template read_element=J)>(reinterpret_cast(x)); } template static BOOST_QVM_INLINE_CRITICAL scalar_type & write_element( this_matrix & x ) { BOOST_QVM_STATIC_ASSERT(Row>=0); BOOST_QVM_STATIC_ASSERT(Row=0); BOOST_QVM_STATIC_ASSERT(Col::template write_element=J)>(reinterpret_cast(x)); } static BOOST_QVM_INLINE_CRITICAL scalar_type read_element_idx( int row, int col, this_matrix const & x ) { BOOST_QVM_ASSERT(row>=0); BOOST_QVM_ASSERT(row=0); BOOST_QVM_ASSERT(col::read_element_idx(row,col+(col>=J),reinterpret_cast(x)); } static BOOST_QVM_INLINE_CRITICAL scalar_type & write_element_idx( int row, int col, this_matrix & x ) { BOOST_QVM_ASSERT(row>=0); BOOST_QVM_ASSERT(row=0); BOOST_QVM_ASSERT(col::write_element_idx(row,col+(col>=J),reinterpret_cast(x)); } }; template struct deduce_mat,R,C> { typedef mat::scalar_type,R,C> type; }; template struct deduce_mat2,qvm_detail::del_col_,R,C> { typedef mat::scalar_type,R,C> type; }; template typename enable_if_c< is_mat::value, qvm_detail::del_col_ const &>::type BOOST_QVM_INLINE_TRIVIAL del_col( A const & a ) { return reinterpret_cast const &>(a); } template typename enable_if_c< is_mat::value, qvm_detail::del_col_ &>::type BOOST_QVM_INLINE_TRIVIAL del_col( A & a ) { return reinterpret_cast &>(a); } //////////////////////////////////////////////// namespace qvm_detail { template class del_row_col_ { del_row_col_( del_row_col_ const & ); ~del_row_col_(); public: BOOST_QVM_INLINE_TRIVIAL del_row_col_ & operator=( del_row_col_ const & x ) { assign(*this,x); return *this; } template BOOST_QVM_INLINE_TRIVIAL del_row_col_ & operator=( T const & x ) { assign(*this,x); return *this; } template BOOST_QVM_INLINE_TRIVIAL operator R() const { R r; assign(r,*this); return r; } }; } template struct mat_traits< qvm_detail::del_row_col_ > { typedef qvm_detail::del_row_col_ this_matrix; typedef typename mat_traits::scalar_type scalar_type; static int const rows=mat_traits::rows-1; static int const cols=mat_traits::cols-1; template static BOOST_QVM_INLINE_CRITICAL scalar_type read_element( this_matrix const & x ) { BOOST_QVM_STATIC_ASSERT(Row>=0); BOOST_QVM_STATIC_ASSERT(Row=0); BOOST_QVM_STATIC_ASSERT(Col::template read_element=I),Col+(Col>=J)>(reinterpret_cast(x)); } template static BOOST_QVM_INLINE_CRITICAL scalar_type & write_element( this_matrix & x ) { BOOST_QVM_STATIC_ASSERT(Row>=0); BOOST_QVM_STATIC_ASSERT(Row=0); BOOST_QVM_STATIC_ASSERT(Col::template write_element=I),Col+(Col>=J)>(reinterpret_cast(x)); } static BOOST_QVM_INLINE_CRITICAL scalar_type read_element_idx( int row, int col, this_matrix const & x ) { BOOST_QVM_ASSERT(row>=0); BOOST_QVM_ASSERT(row=0); BOOST_QVM_ASSERT(col::read_element_idx(row+(row>=I),col+(col>=J),reinterpret_cast(x)); } static BOOST_QVM_INLINE_CRITICAL scalar_type & write_element_idx( int row, int col, this_matrix & x ) { BOOST_QVM_ASSERT(row>=0); BOOST_QVM_ASSERT(row=0); BOOST_QVM_ASSERT(col::write_element_idx(row+(row>=I),col+(col>=J),reinterpret_cast(x)); } }; template struct deduce_mat,R,C> { typedef mat::scalar_type,R,C> type; }; template struct deduce_mat2,qvm_detail::del_row_col_,R,C> { typedef mat::scalar_type,R,C> type; }; template typename enable_if_c< is_mat::value, qvm_detail::del_row_col_ const &>::type BOOST_QVM_INLINE_TRIVIAL del_row_col( A const & a ) { return reinterpret_cast const &>(a); } template typename enable_if_c< is_mat::value, qvm_detail::del_row_col_ &>::type BOOST_QVM_INLINE_TRIVIAL del_row_col( A & a ) { return reinterpret_cast &>(a); } //////////////////////////////////////////////// namespace qvm_detail { template class neg_row_ { neg_row_( neg_row_ const & ); neg_row_ & operator=( neg_row_ const & ); ~neg_row_(); public: template BOOST_QVM_INLINE_TRIVIAL neg_row_ & operator=( T const & x ) { assign(*this,x); return *this; } template BOOST_QVM_INLINE_TRIVIAL operator R() const { R r; assign(r,*this); return r; } }; } template struct mat_traits< qvm_detail::neg_row_ > { typedef qvm_detail::neg_row_ this_matrix; typedef typename mat_traits::scalar_type scalar_type; static int const rows=mat_traits::rows; static int const cols=mat_traits::cols; template static BOOST_QVM_INLINE_CRITICAL scalar_type read_element( this_matrix const & x ) { BOOST_QVM_STATIC_ASSERT(Row>=0); BOOST_QVM_STATIC_ASSERT(Row=0); BOOST_QVM_STATIC_ASSERT(Col::template read_element(reinterpret_cast(x)) : mat_traits::template read_element(reinterpret_cast(x)); } static BOOST_QVM_INLINE_CRITICAL scalar_type read_element_idx( int row, int col, this_matrix const & x ) { BOOST_QVM_ASSERT(row>=0); BOOST_QVM_ASSERT(row=0); BOOST_QVM_ASSERT(col::read_element_idx(row,col,reinterpret_cast(x)) : mat_traits::read_element_idx(row,col,reinterpret_cast(x)); } }; template struct deduce_mat,R,C> { typedef mat::scalar_type,R,C> type; }; template struct deduce_mat2,qvm_detail::neg_row_,R,C> { typedef mat::scalar_type,R,C> type; }; template typename enable_if_c< is_mat::value, qvm_detail::neg_row_ const &>::type BOOST_QVM_INLINE_TRIVIAL neg_row( A const & a ) { return reinterpret_cast const &>(a); } //////////////////////////////////////////////// namespace qvm_detail { template class neg_col_ { neg_col_( neg_col_ const & ); neg_col_ & operator=( neg_col_ const & ); ~neg_col_(); public: template BOOST_QVM_INLINE_TRIVIAL neg_col_ & operator=( T const & x ) { assign(*this,x); return *this; } template BOOST_QVM_INLINE_TRIVIAL operator R() const { R r; assign(r,*this); return r; } }; } template struct mat_traits< qvm_detail::neg_col_ > { typedef qvm_detail::neg_col_ this_matrix; typedef typename mat_traits::scalar_type scalar_type; static int const rows=mat_traits::rows; static int const cols=mat_traits::cols; template static BOOST_QVM_INLINE_CRITICAL scalar_type read_element( this_matrix const & x ) { BOOST_QVM_STATIC_ASSERT(Row>=0); BOOST_QVM_STATIC_ASSERT(Row=0); BOOST_QVM_STATIC_ASSERT(Col::template read_element(reinterpret_cast(x)) : mat_traits::template read_element(reinterpret_cast(x)); } static BOOST_QVM_INLINE_CRITICAL scalar_type read_element_idx( int row, int col, this_matrix const & x ) { BOOST_QVM_ASSERT(row>=0); BOOST_QVM_ASSERT(row=0); BOOST_QVM_ASSERT(col::read_element_idx(row,col,reinterpret_cast(x)) : mat_traits::read_element_idx(row,col,reinterpret_cast(x)); } }; template struct deduce_mat,R,C> { typedef mat::scalar_type,R,C> type; }; template struct deduce_mat2,qvm_detail::neg_col_,R,C> { typedef mat::scalar_type,R,C> type; }; template typename enable_if_c< is_mat::value, qvm_detail::neg_col_ const &>::type BOOST_QVM_INLINE_TRIVIAL neg_col( A const & a ) { return reinterpret_cast const &>(a); } //////////////////////////////////////////////// template typename enable_if_c< is_mat::value, qvm_detail::transposed_ const &>::type BOOST_QVM_INLINE_TRIVIAL transposed( A const & a ) { return reinterpret_cast const &>(a); } template typename enable_if_c< is_mat::value, qvm_detail::transposed_ &>::type BOOST_QVM_INLINE_TRIVIAL transposed( A & a ) { return reinterpret_cast &>(a); } //////////////////////////////////////////////// namespace qvm_detail { template class swap_rows_ { swap_rows_( swap_rows_ const & ); swap_rows_ & operator=( swap_rows_ const & ); ~swap_rows_(); public: template BOOST_QVM_INLINE_TRIVIAL swap_rows_ & operator=( T const & x ) { assign(*this,x); return *this; } template BOOST_QVM_INLINE_TRIVIAL operator R() const { R r; assign(r,*this); return r; } }; } template struct mat_traits< qvm_detail::swap_rows_ > { typedef qvm_detail::swap_rows_ this_matrix; typedef typename mat_traits::scalar_type scalar_type; static int const rows=mat_traits::rows; static int const cols=mat_traits::cols; template static BOOST_QVM_INLINE_CRITICAL scalar_type read_element( this_matrix const & x ) { BOOST_QVM_STATIC_ASSERT(Row>=0); BOOST_QVM_STATIC_ASSERT(Row=0); BOOST_QVM_STATIC_ASSERT(Col::template read_element<(Row==R1 && R1!=R2)*R2+(Row==R2 && R1!=R2)*R1+((Row!=R1 && Row!=R2) || R1==R2)*Row,Col>(reinterpret_cast(x)); } template static BOOST_QVM_INLINE_CRITICAL scalar_type & write_element( this_matrix & x ) { BOOST_QVM_STATIC_ASSERT(Row>=0); BOOST_QVM_STATIC_ASSERT(Row=0); BOOST_QVM_STATIC_ASSERT(Col::template write_element<(Row==R1 && R1!=R2)*R2+(Row==R2 && R1!=R2)*R1+((Row!=R1 && Row!=R2) || R1==R2)*Row,Col>(reinterpret_cast(x)); } static BOOST_QVM_INLINE_CRITICAL scalar_type read_element_idx( int row, int col, this_matrix const & x ) { BOOST_QVM_ASSERT(row>=0); BOOST_QVM_ASSERT(row=0); BOOST_QVM_ASSERT(col::read_element_idx(row==R1?R2:row==R2?R1:row,col,reinterpret_cast(x)); } static BOOST_QVM_INLINE_CRITICAL scalar_type & write_element_idx( int row, int col, this_matrix & x ) { BOOST_QVM_ASSERT(row>=0); BOOST_QVM_ASSERT(row=0); BOOST_QVM_ASSERT(col::write_element_idx(row==R1?R2:row==R2?R1:row,col,reinterpret_cast(x)); } }; template struct deduce_mat,R,C> { typedef mat::scalar_type,R,C> type; }; template struct deduce_mat2,qvm_detail::swap_rows_,R,C> { typedef mat::scalar_type,R,C> type; }; template typename enable_if_c< is_mat::value, qvm_detail::swap_rows_ const &>::type BOOST_QVM_INLINE_TRIVIAL swap_rows( A const & a ) { return reinterpret_cast const &>(a); } template typename enable_if_c< is_mat::value, qvm_detail::swap_rows_ &>::type BOOST_QVM_INLINE_TRIVIAL swap_rows( A & a ) { return reinterpret_cast &>(a); } //////////////////////////////////////////////// namespace qvm_detail { template class swap_cols_ { swap_cols_( swap_cols_ const & ); swap_cols_ & operator=( swap_cols_ const & ); ~swap_cols_(); public: template BOOST_QVM_INLINE_TRIVIAL swap_cols_ & operator=( T const & x ) { assign(*this,x); return *this; } template BOOST_QVM_INLINE_TRIVIAL operator R() const { R r; assign(r,*this); return r; } }; } template struct mat_traits< qvm_detail::swap_cols_ > { typedef qvm_detail::swap_cols_ this_matrix; typedef typename mat_traits::scalar_type scalar_type; static int const rows=mat_traits::rows; static int const cols=mat_traits::cols; template static BOOST_QVM_INLINE_CRITICAL scalar_type read_element( this_matrix const & x ) { BOOST_QVM_STATIC_ASSERT(Row>=0); BOOST_QVM_STATIC_ASSERT(Row=0); BOOST_QVM_STATIC_ASSERT(Col::template read_element(reinterpret_cast(x)); } template static BOOST_QVM_INLINE_CRITICAL scalar_type & write_element( this_matrix & x ) { BOOST_QVM_STATIC_ASSERT(Row>=0); BOOST_QVM_STATIC_ASSERT(Row=0); BOOST_QVM_STATIC_ASSERT(Col::template write_element(reinterpret_cast(x)); } static BOOST_QVM_INLINE_CRITICAL scalar_type read_element_idx( int row, int col, this_matrix const & x ) { BOOST_QVM_ASSERT(row>=0); BOOST_QVM_ASSERT(row=0); BOOST_QVM_ASSERT(col::read_element_idx(row,col==C1?C2:col==C2?C1:col,reinterpret_cast(x)); } static BOOST_QVM_INLINE_CRITICAL scalar_type & write_element_idx( int row, int col, this_matrix & x ) { BOOST_QVM_ASSERT(row>=0); BOOST_QVM_ASSERT(row=0); BOOST_QVM_ASSERT(col::write_element_idx(row,col==C1?C2:col==C2?C1:col,reinterpret_cast(x)); } }; template struct deduce_mat,R,C> { typedef mat::scalar_type,R,C> type; }; template struct deduce_mat2,qvm_detail::swap_cols_,R,C> { typedef mat::scalar_type,R,C> type; }; template typename enable_if_c< is_mat::value, qvm_detail::swap_cols_ const &>::type BOOST_QVM_INLINE_TRIVIAL swap_cols( A const & a ) { return reinterpret_cast const &>(a); } template typename enable_if_c< is_mat::value, qvm_detail::swap_cols_ &>::type BOOST_QVM_INLINE_TRIVIAL swap_cols( A & a ) { return reinterpret_cast &>(a); } } } #endif