mat_traits_defaults.hpp 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. //Copyright (c) 2008-2016 Emil Dotchevski and Reverge Studios, Inc.
  2. //Distributed under the Boost Software License, Version 1.0. (See accompanying
  3. //file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  4. #ifndef UUID_FB4D5BEAC71B11E68D0EEF1707624D53
  5. #define UUID_FB4D5BEAC71B11E68D0EEF1707624D53
  6. #include <boost/qvm/inline.hpp>
  7. #include <boost/qvm/assert.hpp>
  8. namespace
  9. boost
  10. {
  11. namespace
  12. qvm
  13. {
  14. template <class>
  15. struct mat_traits;
  16. namespace
  17. qvm_detail
  18. {
  19. template <int I,int N>
  20. struct
  21. matrix_w
  22. {
  23. template <class A>
  24. static
  25. BOOST_QVM_INLINE_CRITICAL
  26. typename mat_traits<A>::scalar_type &
  27. write_element_idx( int r, int c, A & a )
  28. {
  29. return (I/mat_traits<A>::cols)==r && (I%mat_traits<A>::cols)==c?
  30. mat_traits<A>::template write_element<I/mat_traits<A>::cols,I%mat_traits<A>::cols>(a) :
  31. matrix_w<I+1,N>::write_element_idx(r,c,a);
  32. }
  33. };
  34. template <int N>
  35. struct
  36. matrix_w<N,N>
  37. {
  38. template <class A>
  39. static
  40. BOOST_QVM_INLINE_TRIVIAL
  41. typename mat_traits<A>::scalar_type &
  42. write_element_idx( int, int, A & a )
  43. {
  44. BOOST_QVM_ASSERT(0);
  45. return mat_traits<A>::template write_element<0,0>(a);
  46. }
  47. };
  48. }
  49. template <class MatType,class ScalarType,int Rows,int Cols>
  50. struct
  51. mat_traits_defaults
  52. {
  53. typedef MatType mat_type;
  54. typedef ScalarType scalar_type;
  55. static int const rows=Rows;
  56. static int const cols=Cols;
  57. template <int Row,int Col>
  58. static
  59. BOOST_QVM_INLINE_CRITICAL
  60. scalar_type
  61. read_element( mat_type const & x )
  62. {
  63. return mat_traits<mat_type>::template write_element<Row,Col>(const_cast<mat_type &>(x));
  64. }
  65. static
  66. BOOST_QVM_INLINE_CRITICAL
  67. scalar_type
  68. read_element_idx( int r, int c, mat_type const & x )
  69. {
  70. return mat_traits<mat_type>::write_element_idx(r,c,const_cast<mat_type &>(x));
  71. }
  72. protected:
  73. static
  74. BOOST_QVM_INLINE_TRIVIAL
  75. scalar_type &
  76. write_element_idx( int r, int c, mat_type & m )
  77. {
  78. return qvm_detail::matrix_w<0,mat_traits<mat_type>::rows*mat_traits<mat_type>::cols>::write_element_idx(r,c,m);
  79. }
  80. };
  81. }
  82. }
  83. #endif