unit_helper.hpp 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. /*
  2. [auto_generated]
  3. boost/numeric/odeint/util/unit_helper.hpp
  4. [begin_description]
  5. Get and set the value of a unit.
  6. [end_description]
  7. Copyright 2012-2013 Karsten Ahnert
  8. Copyright 2012-2013 Mario Mulansky
  9. Distributed under the Boost Software License, Version 1.0.
  10. (See accompanying file LICENSE_1_0.txt or
  11. copy at http://www.boost.org/LICENSE_1_0.txt)
  12. */
  13. #ifndef BOOST_NUMERIC_ODEINT_UTIL_UNIT_HELPER_HPP_INCLUDED
  14. #define BOOST_NUMERIC_ODEINT_UTIL_UNIT_HELPER_HPP_INCLUDED
  15. #ifndef __CUDACC__
  16. #include <boost/units/quantity.hpp>
  17. #include <boost/units/get_dimension.hpp>
  18. #include <boost/units/get_system.hpp>
  19. #endif
  20. namespace boost {
  21. namespace numeric {
  22. namespace odeint {
  23. namespace detail {
  24. template<class T , class Enabler = void >
  25. struct get_unit_value_impl
  26. {
  27. static T value(const T &t)
  28. {
  29. return t;
  30. }
  31. typedef T result_type;
  32. };
  33. #ifndef __CUDACC__
  34. template<class Unit , class T>
  35. struct get_unit_value_impl< boost::units::quantity< Unit , T> >
  36. {
  37. static T value( const boost::units::quantity< Unit , T> &t )
  38. {
  39. return t.value();
  40. }
  41. typedef T result_type;
  42. };
  43. #endif
  44. template<class T , class V , class Enabler = void >
  45. struct set_unit_value_impl
  46. {
  47. static void set_value(T &t , const V &v)
  48. {
  49. t = v;
  50. }
  51. };
  52. #ifndef __CUDACC__
  53. template<class Unit , class T , class V>
  54. struct set_unit_value_impl<boost::units::quantity<Unit , T> , V>
  55. {
  56. static void set_value(boost::units::quantity<Unit , T> &t , const V &v)
  57. {
  58. t = boost::units::quantity<Unit , T>::from_value(v);
  59. }
  60. };
  61. #endif
  62. } // namespace detail
  63. template<class T>
  64. typename detail::get_unit_value_impl<T>::result_type get_unit_value(const T &t)
  65. {
  66. return detail::get_unit_value_impl<T>::value(t);
  67. }
  68. template<class T , class V>
  69. void set_unit_value(T &t , const V &v)
  70. {
  71. return detail::set_unit_value_impl<T , V>::set_value(t , v);
  72. }
  73. template< class T >
  74. struct unit_value_type
  75. {
  76. typedef T type;
  77. };
  78. #ifndef __CUDACC__
  79. template< class Unit , class Y >
  80. struct unit_value_type< boost::units::quantity< Unit , Y > >
  81. {
  82. typedef Y type;
  83. };
  84. #endif
  85. template< typename Time >
  86. struct inverse_time
  87. {
  88. typedef Time type;
  89. };
  90. #ifndef __CUDACC__
  91. template< typename Unit , typename Value >
  92. struct inverse_time< boost::units::quantity< Unit , Value > >
  93. {
  94. typedef boost::units::quantity< Unit , Value > time_type;
  95. typedef typename boost::units::get_dimension< time_type >::type dimension;
  96. typedef typename boost::units::get_system< time_type >::type system;
  97. typedef typename boost::mpl::divides< boost::units::dimensionless_type , dimension >::type inv_dimension;
  98. typedef boost::units::unit< inv_dimension , system > inv_unit;
  99. typedef boost::units::quantity< inv_unit , Value > type;
  100. };
  101. #endif
  102. } // namespace odeint
  103. } // namespace numeric
  104. } // namespace boost
  105. #endif // BOOST_NUMERIC_ODEINT_UTIL_UNIT_HELPER_HPP_INCLUDED