transp_impl.hpp 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. #ifndef BOOST_QVM_DETAIL_TRANSP_IMPL_HPP_INCLUDED
  2. #define BOOST_QVM_DETAIL_TRANSP_IMPL_HPP_INCLUDED
  3. /// Copyright (c) 2008-2021 Emil Dotchevski and Reverge Studios, Inc.
  4. /// Distributed under the Boost Software License, Version 1.0. (See accompanying
  5. /// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  6. #include <boost/qvm/deduce_mat.hpp>
  7. #include <boost/qvm/static_assert.hpp>
  8. #include <boost/qvm/assert.hpp>
  9. namespace boost { namespace qvm {
  10. namespace
  11. qvm_detail
  12. {
  13. template <class OriginalMatrix>
  14. class
  15. transposed_
  16. {
  17. transposed_( transposed_ const & );
  18. transposed_ & operator=( transposed_ const & );
  19. ~transposed_();
  20. public:
  21. template <class T>
  22. BOOST_QVM_INLINE_TRIVIAL
  23. transposed_ &
  24. operator=( T const & x )
  25. {
  26. assign(*this,x);
  27. return *this;
  28. }
  29. template <class R>
  30. BOOST_QVM_INLINE_TRIVIAL
  31. operator R() const
  32. {
  33. R r;
  34. assign(r,*this);
  35. return r;
  36. }
  37. };
  38. }
  39. template <class OriginalMatrix>
  40. struct
  41. mat_traits< qvm_detail::transposed_<OriginalMatrix> >
  42. {
  43. typedef typename mat_traits<OriginalMatrix>::scalar_type scalar_type;
  44. typedef qvm_detail::transposed_<OriginalMatrix> this_matrix;
  45. static int const rows=mat_traits<OriginalMatrix>::cols;
  46. static int const cols=mat_traits<OriginalMatrix>::rows;
  47. template <int Row,int Col>
  48. static
  49. BOOST_QVM_INLINE_CRITICAL
  50. scalar_type
  51. read_element( this_matrix const & x )
  52. {
  53. BOOST_QVM_STATIC_ASSERT(Row>=0);
  54. BOOST_QVM_STATIC_ASSERT(Row<rows);
  55. BOOST_QVM_STATIC_ASSERT(Col>=0);
  56. BOOST_QVM_STATIC_ASSERT(Col<cols);
  57. return mat_traits<OriginalMatrix>::template read_element<Col,Row>(reinterpret_cast<OriginalMatrix const &>(x));
  58. }
  59. template <int Row,int Col>
  60. static
  61. BOOST_QVM_INLINE_CRITICAL
  62. scalar_type &
  63. write_element( this_matrix & x )
  64. {
  65. BOOST_QVM_STATIC_ASSERT(Row>=0);
  66. BOOST_QVM_STATIC_ASSERT(Row<rows);
  67. BOOST_QVM_STATIC_ASSERT(Col>=0);
  68. BOOST_QVM_STATIC_ASSERT(Col<cols);
  69. return mat_traits<OriginalMatrix>::template write_element<Col,Row>(reinterpret_cast<OriginalMatrix &>(x));
  70. }
  71. static
  72. BOOST_QVM_INLINE_CRITICAL
  73. scalar_type
  74. read_element_idx( int row, int col, this_matrix const & x )
  75. {
  76. BOOST_QVM_ASSERT(row>=0);
  77. BOOST_QVM_ASSERT(row<rows);
  78. BOOST_QVM_ASSERT(col>=0);
  79. BOOST_QVM_ASSERT(col<cols);
  80. return mat_traits<OriginalMatrix>::read_element_idx(col,row,reinterpret_cast<OriginalMatrix const &>(x));
  81. }
  82. static
  83. BOOST_QVM_INLINE_CRITICAL
  84. scalar_type &
  85. write_element_idx( int row, int col, this_matrix & x )
  86. {
  87. BOOST_QVM_ASSERT(row>=0);
  88. BOOST_QVM_ASSERT(row<rows);
  89. BOOST_QVM_ASSERT(col>=0);
  90. BOOST_QVM_ASSERT(col<cols);
  91. return mat_traits<OriginalMatrix>::write_element_idx(col,row,reinterpret_cast<OriginalMatrix &>(x));
  92. }
  93. };
  94. template <class OriginalMatrix,int R,int C>
  95. struct
  96. deduce_mat<qvm_detail::transposed_<OriginalMatrix>,R,C>
  97. {
  98. typedef mat<typename mat_traits<OriginalMatrix>::scalar_type,R,C> type;
  99. };
  100. template <class OriginalMatrix,int R,int C>
  101. struct
  102. deduce_mat2<qvm_detail::transposed_<OriginalMatrix>,qvm_detail::transposed_<OriginalMatrix>,R,C>
  103. {
  104. typedef mat<typename mat_traits<OriginalMatrix>::scalar_type,R,C> type;
  105. };
  106. } }
  107. #endif