scalar_traits.hpp 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. #ifndef BOOST_QVM_SCALAR_TRAITS_HPP_INCLUDED
  2. #define BOOST_QVM_SCALAR_TRAITS_HPP_INCLUDED
  3. /// Copyright (c) 2008-2021 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/quat_traits.hpp>
  7. #include <boost/qvm/vec_traits.hpp>
  8. #include <boost/qvm/mat_traits.hpp>
  9. #include <boost/qvm/inline.hpp>
  10. namespace boost { namespace qvm {
  11. template <class Scalar>
  12. struct
  13. scalar_traits
  14. {
  15. static
  16. BOOST_QVM_INLINE_CRITICAL
  17. Scalar
  18. value( int v )
  19. {
  20. return Scalar(v);
  21. }
  22. };
  23. template <class T>
  24. struct
  25. is_scalar
  26. {
  27. static bool const value=false;
  28. };
  29. template <> struct is_scalar<char> { static bool const value=true; };
  30. template <> struct is_scalar<signed char> { static bool const value=true; };
  31. template <> struct is_scalar<unsigned char> { static bool const value=true; };
  32. template <> struct is_scalar<signed short> { static bool const value=true; };
  33. template <> struct is_scalar<unsigned short> { static bool const value=true; };
  34. template <> struct is_scalar<signed int> { static bool const value=true; };
  35. template <> struct is_scalar<unsigned int> { static bool const value=true; };
  36. template <> struct is_scalar<signed long> { static bool const value=true; };
  37. template <> struct is_scalar<unsigned long> { static bool const value=true; };
  38. template <> struct is_scalar<float> { static bool const value=true; };
  39. template <> struct is_scalar<double> { static bool const value=true; };
  40. template <> struct is_scalar<long double> { static bool const value=true; };
  41. namespace
  42. qvm_detail
  43. {
  44. template <class A,
  45. bool IsQ=is_quat<A>::value,
  46. bool IsV=is_vec<A>::value,
  47. bool IsM=is_mat<A>::value,
  48. bool IsS=is_scalar<A>::value>
  49. struct
  50. scalar_impl
  51. {
  52. typedef void type;
  53. };
  54. template <class A>
  55. struct
  56. scalar_impl<A,false,false,false,true>
  57. {
  58. typedef A type;
  59. };
  60. template <class A>
  61. struct
  62. scalar_impl<A,false,false,true,false>
  63. {
  64. typedef typename mat_traits<A>::scalar_type type;
  65. };
  66. template <class A>
  67. struct
  68. scalar_impl<A,false,true,false,false>
  69. {
  70. typedef typename vec_traits<A>::scalar_type type;
  71. };
  72. template <class A>
  73. struct
  74. scalar_impl<A,true,false,false,false>
  75. {
  76. typedef typename quat_traits<A>::scalar_type type;
  77. };
  78. }
  79. template <class A>
  80. struct
  81. scalar
  82. {
  83. typedef typename qvm_detail::scalar_impl<A>::type type;
  84. };
  85. } }
  86. #endif