mat.hpp 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  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_67E67D68A32F11DEA56FD18556D89593
  5. #define UUID_67E67D68A32F11DEA56FD18556D89593
  6. #include <boost/qvm/detail/mat_assign.hpp>
  7. #include <boost/qvm/assert.hpp>
  8. #include <boost/qvm/static_assert.hpp>
  9. namespace
  10. boost
  11. {
  12. namespace
  13. qvm
  14. {
  15. template <class T,int Rows,int Cols>
  16. struct
  17. mat
  18. {
  19. T a[Rows][Cols];
  20. template <class R>
  21. operator R() const
  22. {
  23. R r;
  24. assign(r,*this);
  25. return r;
  26. }
  27. };
  28. template <class M>
  29. struct mat_traits;
  30. template <class T,int Rows,int Cols>
  31. struct
  32. mat_traits< mat<T,Rows,Cols> >
  33. {
  34. typedef mat<T,Rows,Cols> this_matrix;
  35. typedef T scalar_type;
  36. static int const rows=Rows;
  37. static int const cols=Cols;
  38. template <int Row,int Col>
  39. static
  40. BOOST_QVM_INLINE_CRITICAL
  41. scalar_type
  42. read_element( this_matrix const & x )
  43. {
  44. BOOST_QVM_STATIC_ASSERT(Row>=0);
  45. BOOST_QVM_STATIC_ASSERT(Row<Rows);
  46. BOOST_QVM_STATIC_ASSERT(Col>=0);
  47. BOOST_QVM_STATIC_ASSERT(Col<Cols);
  48. return x.a[Row][Col];
  49. }
  50. template <int Row,int Col>
  51. static
  52. BOOST_QVM_INLINE_CRITICAL
  53. scalar_type &
  54. write_element( this_matrix & x )
  55. {
  56. BOOST_QVM_STATIC_ASSERT(Row>=0);
  57. BOOST_QVM_STATIC_ASSERT(Row<Rows);
  58. BOOST_QVM_STATIC_ASSERT(Col>=0);
  59. BOOST_QVM_STATIC_ASSERT(Col<Cols);
  60. return x.a[Row][Col];
  61. }
  62. static
  63. BOOST_QVM_INLINE_CRITICAL
  64. scalar_type
  65. read_element_idx( int row, int col, this_matrix const & x )
  66. {
  67. BOOST_QVM_ASSERT(row>=0);
  68. BOOST_QVM_ASSERT(row<Rows);
  69. BOOST_QVM_ASSERT(col>=0);
  70. BOOST_QVM_ASSERT(col<Cols);
  71. return x.a[row][col];
  72. }
  73. static
  74. BOOST_QVM_INLINE_CRITICAL
  75. scalar_type &
  76. write_element_idx( int row, int col, this_matrix & x )
  77. {
  78. BOOST_QVM_ASSERT(row>=0);
  79. BOOST_QVM_ASSERT(row<Rows);
  80. BOOST_QVM_ASSERT(col>=0);
  81. BOOST_QVM_ASSERT(col<Cols);
  82. return x.a[row][col];
  83. }
  84. };
  85. }
  86. }
  87. #endif