3 boost/numeric/odeint/util/unit_helper.hpp
6 Get and set the value of a unit.
9 Copyright 2012-2013 Karsten Ahnert
10 Copyright 2012-2013 Mario Mulansky
12 Distributed under the Boost Software License, Version 1.0.
13 (See accompanying file LICENSE_1_0.txt or
14 copy at http://www.boost.org/LICENSE_1_0.txt)
18 #ifndef BOOST_NUMERIC_ODEINT_UTIL_UNIT_HELPER_HPP_INCLUDED
19 #define BOOST_NUMERIC_ODEINT_UTIL_UNIT_HELPER_HPP_INCLUDED
23 #include <boost/units/quantity.hpp>
24 #include <boost/units/get_dimension.hpp>
25 #include <boost/units/get_system.hpp>
37 template<class T , class Enabler = void >
38 struct get_unit_value_impl
40 static T value(const T &t)
44 typedef T result_type;
48 template<class Unit , class T>
49 struct get_unit_value_impl< boost::units::quantity< Unit , T> >
51 static T value( const boost::units::quantity< Unit , T> &t )
55 typedef T result_type;
63 template<class T , class V , class Enabler = void >
64 struct set_unit_value_impl
66 static void set_value(T &t , const V &v)
73 template<class Unit , class T , class V>
74 struct set_unit_value_impl<boost::units::quantity<Unit , T> , V>
76 static void set_value(boost::units::quantity<Unit , T> &t , const V &v)
78 t = boost::units::quantity<Unit , T>::from_value(v);
89 typename detail::get_unit_value_impl<T>::result_type get_unit_value(const T &t)
91 return detail::get_unit_value_impl<T>::value(t);
95 template<class T , class V>
96 void set_unit_value(T &t , const V &v)
98 return detail::set_unit_value_impl<T , V>::set_value(t , v);
104 struct unit_value_type
110 template< class Unit , class Y >
111 struct unit_value_type< boost::units::quantity< Unit , Y > >
126 template< typename Time >
133 template< typename Unit , typename Value >
134 struct inverse_time< boost::units::quantity< Unit , Value > >
136 typedef boost::units::quantity< Unit , Value > time_type;
137 typedef typename boost::units::get_dimension< time_type >::type dimension;
138 typedef typename boost::units::get_system< time_type >::type system;
139 typedef typename boost::mpl::divides< boost::units::dimensionless_type , dimension >::type inv_dimension;
140 typedef boost::units::unit< inv_dimension , system > inv_unit;
141 typedef boost::units::quantity< inv_unit , Value > type;
146 } // namespace odeint
147 } // namespace numeric
151 #endif // BOOST_NUMERIC_ODEINT_UTIL_UNIT_HELPER_HPP_INCLUDED