vec_traits_defaults.hpp 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. #ifndef BOOST_QVM_VEC_TRAITS_DEFAULTS_HPP_INCLUDED
  2. #define BOOST_QVM_VEC_TRAITS_DEFAULTS_HPP_INCLUDED
  3. // Copyright 2008-2022 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/config.hpp>
  7. #include <boost/qvm/assert.hpp>
  8. namespace boost { namespace qvm {
  9. template <class>
  10. struct vec_traits;
  11. namespace
  12. qvm_detail
  13. {
  14. template <int I,int N>
  15. struct
  16. vector_w
  17. {
  18. template <class A>
  19. static
  20. BOOST_QVM_CONSTEXPR BOOST_QVM_INLINE_CRITICAL
  21. typename vec_traits<A>::scalar_type &
  22. write_element_idx( int i, A & a )
  23. {
  24. return I==i?
  25. vec_traits<A>::template write_element<I>(a) :
  26. vector_w<I+1,N>::write_element_idx(i,a);
  27. }
  28. };
  29. template <int N>
  30. struct
  31. vector_w<N,N>
  32. {
  33. template <class A>
  34. static
  35. BOOST_QVM_CONSTEXPR BOOST_QVM_INLINE_TRIVIAL
  36. typename vec_traits<A>::scalar_type &
  37. write_element_idx( int, A & a )
  38. {
  39. BOOST_QVM_ASSERT(0);
  40. return vec_traits<A>::template write_element<0>(a);
  41. }
  42. };
  43. }
  44. template <class VecType,class ScalarType,int Dim>
  45. struct
  46. vec_traits_defaults
  47. {
  48. typedef VecType vec_type;
  49. typedef ScalarType scalar_type;
  50. static int const dim=Dim;
  51. template <int I>
  52. static
  53. BOOST_QVM_CONSTEXPR BOOST_QVM_INLINE_CRITICAL
  54. scalar_type
  55. read_element( vec_type const & x )
  56. {
  57. return vec_traits<vec_type>::template write_element<I>(const_cast<vec_type &>(x));
  58. }
  59. static
  60. BOOST_QVM_CONSTEXPR BOOST_QVM_INLINE_CRITICAL
  61. scalar_type
  62. read_element_idx( int i, vec_type const & x )
  63. {
  64. return vec_traits<vec_type>::write_element_idx(i,const_cast<vec_type &>(x));
  65. }
  66. protected:
  67. static
  68. BOOST_QVM_CONSTEXPR BOOST_QVM_INLINE_TRIVIAL
  69. scalar_type &
  70. write_element_idx( int i, vec_type & m )
  71. {
  72. return qvm_detail::vector_w<0,vec_traits<vec_type>::dim>::write_element_idx(i,m);
  73. }
  74. };
  75. } }
  76. #endif