vec.hpp 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  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_44EB56F0A33711DEB31B41BB56D89593
  5. #define UUID_44EB56F0A33711DEB31B41BB56D89593
  6. #include <boost/qvm/detail/vec_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 D>
  16. struct
  17. vec
  18. {
  19. T a[D];
  20. template <class R>
  21. operator R() const
  22. {
  23. R r;
  24. assign(r,*this);
  25. return r;
  26. }
  27. };
  28. template <class V>
  29. struct vec_traits;
  30. template <class T,int Dim>
  31. struct
  32. vec_traits< vec<T,Dim> >
  33. {
  34. typedef vec<T,Dim> this_vector;
  35. typedef T scalar_type;
  36. static int const dim=Dim;
  37. template <int I>
  38. static
  39. BOOST_QVM_INLINE_CRITICAL
  40. scalar_type
  41. read_element( this_vector const & x )
  42. {
  43. BOOST_QVM_STATIC_ASSERT(I>=0);
  44. BOOST_QVM_STATIC_ASSERT(I<dim);
  45. return x.a[I];
  46. }
  47. template <int I>
  48. static
  49. BOOST_QVM_INLINE_CRITICAL
  50. scalar_type &
  51. write_element( this_vector & x )
  52. {
  53. BOOST_QVM_STATIC_ASSERT(I>=0);
  54. BOOST_QVM_STATIC_ASSERT(I<dim);
  55. return x.a[I];
  56. }
  57. static
  58. BOOST_QVM_INLINE_CRITICAL
  59. scalar_type
  60. read_element_idx( int i, this_vector const & x )
  61. {
  62. BOOST_QVM_ASSERT(i>=0);
  63. BOOST_QVM_ASSERT(i<dim);
  64. return x.a[i];
  65. }
  66. static
  67. BOOST_QVM_INLINE_CRITICAL
  68. scalar_type &
  69. write_element_idx( int i, this_vector & x )
  70. {
  71. BOOST_QVM_ASSERT(i>=0);
  72. BOOST_QVM_ASSERT(i<dim);
  73. return x.a[i];
  74. }
  75. };
  76. }
  77. }
  78. #endif