| 1 | #ifndef BOOST_QVM_QUAT_TRAITS |
| 2 | #define BOOST_QVM_QUAT_TRAITS |
| 3 | |
| 4 | // Copyright 2008-2022 Emil Dotchevski and Reverge Studios, Inc. |
| 5 | |
| 6 | // Distributed under the Boost Software License, Version 1.0. (See accompanying |
| 7 | // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) |
| 8 | |
| 9 | #include <boost/qvm/is_scalar.hpp> |
| 10 | #include <boost/qvm/enable_if.hpp> |
| 11 | #include <boost/qvm/config.hpp> |
| 12 | |
| 13 | namespace boost { namespace qvm { |
| 14 | |
| 15 | template <class Q> |
| 16 | struct |
| 17 | quat_traits |
| 18 | { |
| 19 | typedef void scalar_type; |
| 20 | }; |
| 21 | |
| 22 | template <class T> |
| 23 | struct |
| 24 | is_quat |
| 25 | { |
| 26 | static bool const value = is_scalar<typename quat_traits<T>::scalar_type>::value; |
| 27 | }; |
| 28 | |
| 29 | namespace |
| 30 | qvm_detail |
| 31 | { |
| 32 | template <class T, T> |
| 33 | struct |
| 34 | qtr_dispatch_yes |
| 35 | { |
| 36 | char x, y; |
| 37 | }; |
| 38 | } |
| 39 | |
| 40 | template <class T> |
| 41 | class |
| 42 | quat_write_element_ref |
| 43 | { |
| 44 | template <class U> |
| 45 | static qvm_detail::qtr_dispatch_yes<typename quat_traits<U>::scalar_type & (*)( U & ), &quat_traits<U>::template write_element<0> > check(int); |
| 46 | |
| 47 | template <class> |
| 48 | static char check(long); |
| 49 | |
| 50 | public: |
| 51 | |
| 52 | static bool const value = sizeof(check<T>(0)) > 1; |
| 53 | }; |
| 54 | |
| 55 | template <int I, class Q> |
| 56 | BOOST_QVM_CONSTEXPR BOOST_QVM_INLINE_CRITICAL |
| 57 | typename enable_if_c< |
| 58 | quat_write_element_ref<Q>::value, |
| 59 | void>::type |
| 60 | write_quat_element( Q & q, typename quat_traits<Q>::scalar_type s ) |
| 61 | { |
| 62 | quat_traits<Q>::template write_element<I>(q) = s; |
| 63 | } |
| 64 | |
| 65 | template <int I, class Q> |
| 66 | BOOST_QVM_CONSTEXPR BOOST_QVM_INLINE_CRITICAL |
| 67 | typename enable_if_c< |
| 68 | !quat_write_element_ref<Q>::value, |
| 69 | void>::type |
| 70 | write_quat_element( Q & q, typename quat_traits<Q>::scalar_type s ) |
| 71 | { |
| 72 | quat_traits<Q>::template write_element<I>(q, s); |
| 73 | } |
| 74 | |
| 75 | template <class Q> |
| 76 | BOOST_QVM_CONSTEXPR BOOST_QVM_INLINE_CRITICAL |
| 77 | typename enable_if_c< |
| 78 | quat_write_element_ref<Q>::value, |
| 79 | void>::type |
| 80 | write_quat_element_idx( int i, Q & q, typename quat_traits<Q>::scalar_type s ) |
| 81 | { |
| 82 | quat_traits<Q>::template write_element_idx(i, q) = s; |
| 83 | } |
| 84 | |
| 85 | template <class Q> |
| 86 | BOOST_QVM_CONSTEXPR BOOST_QVM_INLINE_CRITICAL |
| 87 | typename enable_if_c< |
| 88 | !quat_write_element_ref<Q>::value, |
| 89 | void>::type |
| 90 | write_vec_element_idx( int i, Q & q, typename quat_traits<Q>::scalar_type s ) |
| 91 | { |
| 92 | quat_traits<Q>::template write_element_idx(i, q, s); |
| 93 | } |
| 94 | |
| 95 | } } |
| 96 | |
| 97 | #endif |
| 98 | |