scalar_traits.hpp 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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_57E1C032B9F311DEB7D9BAFE55D89593
  5. #define UUID_57E1C032B9F311DEB7D9BAFE55D89593
  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
  11. boost
  12. {
  13. namespace
  14. qvm
  15. {
  16. template <class Scalar>
  17. struct
  18. scalar_traits
  19. {
  20. static
  21. BOOST_QVM_INLINE_CRITICAL
  22. Scalar
  23. value( int v )
  24. {
  25. return Scalar(v);
  26. }
  27. };
  28. template <class T>
  29. struct
  30. is_scalar
  31. {
  32. static bool const value=false;
  33. };
  34. template <> struct is_scalar<char> { static bool const value=true; };
  35. template <> struct is_scalar<signed char> { static bool const value=true; };
  36. template <> struct is_scalar<unsigned char> { static bool const value=true; };
  37. template <> struct is_scalar<signed short> { static bool const value=true; };
  38. template <> struct is_scalar<unsigned short> { static bool const value=true; };
  39. template <> struct is_scalar<signed int> { static bool const value=true; };
  40. template <> struct is_scalar<unsigned int> { static bool const value=true; };
  41. template <> struct is_scalar<signed long> { static bool const value=true; };
  42. template <> struct is_scalar<unsigned long> { static bool const value=true; };
  43. template <> struct is_scalar<float> { static bool const value=true; };
  44. template <> struct is_scalar<double> { static bool const value=true; };
  45. template <> struct is_scalar<long double> { static bool const value=true; };
  46. namespace
  47. qvm_detail
  48. {
  49. template <class A,bool M=is_mat<A>::value,bool Q=is_quat<A>::value,bool V=is_vec<A>::value>
  50. struct
  51. scalar_impl
  52. {
  53. };
  54. template <class A>
  55. struct
  56. scalar_impl<A,true,false,false>
  57. {
  58. typedef typename mat_traits<A>::scalar_type type;
  59. };
  60. template <class A>
  61. struct
  62. scalar_impl<A,false,true,false>
  63. {
  64. typedef typename quat_traits<A>::scalar_type type;
  65. };
  66. template <class A>
  67. struct
  68. scalar_impl<A,false,false,true>
  69. {
  70. typedef typename vec_traits<A>::scalar_type type;
  71. };
  72. }
  73. template <class A>
  74. struct
  75. scalar
  76. {
  77. typedef typename qvm_detail::scalar_impl<A>::type type;
  78. };
  79. }
  80. }
  81. #endif