quat_traits.hpp 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. #ifndef BOOST_QVM_QUAT_TRAITS
  2. #define BOOST_QVM_QUAT_TRAITS
  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/is_scalar.hpp>
  7. #include <boost/qvm/enable_if.hpp>
  8. #include <boost/qvm/config.hpp>
  9. namespace boost { namespace qvm {
  10. template <class Q>
  11. struct
  12. quat_traits
  13. {
  14. typedef void scalar_type;
  15. };
  16. template <class T>
  17. struct
  18. is_quat
  19. {
  20. static bool const value = is_scalar<typename quat_traits<T>::scalar_type>::value;
  21. };
  22. namespace
  23. qvm_detail
  24. {
  25. template <class T, T>
  26. struct
  27. qtr_dispatch_yes
  28. {
  29. char x, y;
  30. };
  31. }
  32. template <class T>
  33. class
  34. quat_write_element_ref
  35. {
  36. template <class U>
  37. static qvm_detail::qtr_dispatch_yes<typename quat_traits<U>::scalar_type & (*)( U & ), &quat_traits<U>::template write_element<0> > check(int);
  38. template <class>
  39. static char check(long);
  40. public:
  41. static bool const value = sizeof(check<T>(0)) > 1;
  42. };
  43. template <int I, class Q>
  44. BOOST_QVM_CONSTEXPR BOOST_QVM_INLINE_CRITICAL
  45. typename enable_if_c<
  46. quat_write_element_ref<Q>::value,
  47. void>::type
  48. write_quat_element( Q & q, typename quat_traits<Q>::scalar_type s )
  49. {
  50. quat_traits<Q>::template write_element<I>(q) = s;
  51. }
  52. template <int I, class Q>
  53. BOOST_QVM_CONSTEXPR BOOST_QVM_INLINE_CRITICAL
  54. typename enable_if_c<
  55. !quat_write_element_ref<Q>::value,
  56. void>::type
  57. write_quat_element( Q & q, typename quat_traits<Q>::scalar_type s )
  58. {
  59. quat_traits<Q>::template write_element<I>(q, s);
  60. }
  61. template <class Q>
  62. BOOST_QVM_CONSTEXPR BOOST_QVM_INLINE_CRITICAL
  63. typename enable_if_c<
  64. quat_write_element_ref<Q>::value,
  65. void>::type
  66. write_quat_element_idx( int i, Q & q, typename quat_traits<Q>::scalar_type s )
  67. {
  68. quat_traits<Q>::template write_element_idx(i, q) = s;
  69. }
  70. template <class Q>
  71. BOOST_QVM_CONSTEXPR BOOST_QVM_INLINE_CRITICAL
  72. typename enable_if_c<
  73. !quat_write_element_ref<Q>::value,
  74. void>::type
  75. write_vec_element_idx( int i, Q & q, typename quat_traits<Q>::scalar_type s )
  76. {
  77. quat_traits<Q>::template write_element_idx(i, q, s);
  78. }
  79. } }
  80. #endif