conversion_impl.hpp
来自「Boost provides free peer-reviewed portab」· HPP 代码 · 共 532 行 · 第 1/2 页
HPP
532 行
typename start::type, typename conversion::type >::type, typename impl::type >::type type; static type value() { return(start::value() * conversion::value() / impl::value()); } };};#define BOOST_UNITS_DETAIL_BASE_UNIT_CONVERTER_IS_DEFINED(Source, Dest)\ base_unit_converter<\ typename select_base_unit_converter<typename unscale<Source>::type, typename unscale<Dest>::type>::source_type,\ typename select_base_unit_converter<typename unscale<Source>::type, typename unscale<Dest>::type>::destination_type\ >::is_definedtemplate<class Source, class Dest>struct call_base_unit_converter : call_base_unit_converter_impl<BOOST_UNITS_DETAIL_BASE_UNIT_CONVERTER_IS_DEFINED(Source, Dest)>::template apply<Source, Dest>{};template<class Source, class Dest>struct call_base_unit_converter<Source, BOOST_UNITS_MAKE_HETEROGENEOUS_UNIT(Dest, typename Source::dimension_type)> : call_base_unit_converter_base_unit_impl< BOOST_UNITS_DETAIL_BASE_UNIT_CONVERTER_IS_DEFINED(Source, typename Dest::unit_type), BOOST_UNITS_DETAIL_BASE_UNIT_CONVERTER_IS_DEFINED(Dest, typename Source::unit_type) >::template apply<Source, Dest>{};template<int N>struct conversion_impl{ template<class Begin, class DestinationSystem> struct apply { typedef typename conversion_impl<N-1>::template apply< typename Begin::next, DestinationSystem > next_iteration; typedef typename Begin::item unit_pair; typedef typename unit_pair::tag_type unit; typedef typename unit::dimension_type dimensions; typedef typename reduce_unit<units::unit<dimensions, DestinationSystem> >::type reduced_unit; typedef detail::call_base_unit_converter<unit, reduced_unit> converter; typedef typename multiply_typeof_helper<typename converter::type, typename next_iteration::type>::type type; static type value() { return(static_rational_power<typename unit_pair::value_type>(converter::value()) * next_iteration::value()); } };};template<>struct conversion_impl<0>{ template<class Begin, class DestinationSystem> struct apply { typedef one type; static type value() { return(one()); } };};} // namespace detail/// conversions between homogeneous systems are defined/// INTERNAL ONLYtemplate<class D, class L1, class T1, class L2, class T2>struct conversion_helper<quantity<unit<D, homogeneous_system<L1> >, T1>, quantity<unit<D, homogeneous_system<L2> >, T2> >{ /// INTERNAL ONLY typedef quantity<unit<D, homogeneous_system<L2> >, T2> destination_type; /// INTERNAL ONLY typedef typename reduce_unit<unit<D, homogeneous_system<L1> > >::type source_unit; /// INTERNAL ONLY typedef typename source_unit::system_type::type unit_list; static destination_type convert(const quantity<unit<D, homogeneous_system<L1> >, T1>& source) { return(destination_type::from_value(source.value() * detail::conversion_impl<unit_list::size::value>::template apply< unit_list, homogeneous_system<L2> >::value() )); }};/// conversions between heterogeneous systems and homogeneous systems are defined/// INTERNAL ONLYtemplate<class D, class L1, class T1, class L2, class T2>struct conversion_helper<quantity<unit<D, heterogeneous_system<L1> >, T1>, quantity<unit<D, homogeneous_system<L2> >, T2> >{ /// INTERNAL ONLY typedef quantity<unit<D, homogeneous_system<L2> >, T2> destination_type; static destination_type convert(const quantity<unit<D, heterogeneous_system<L1> >, T1>& source) { return(destination_type::from_value(source.value() * detail::conversion_impl<L1::type::size::value>::template apply< typename L1::type, homogeneous_system<L2> >::value() * eval_scale_list<typename L1::scale>::value() )); }};// There is no simple algorithm for doing this conversion// other than just defining it as the reverse of the// heterogeneous->homogeneous case/// conversions between heterogeneous systems and homogeneous systems are defined/// INTERNAL ONLYtemplate<class D, class L1, class T1, class L2, class T2>struct conversion_helper<quantity<unit<D, homogeneous_system<L1> >, T1>, quantity<unit<D, heterogeneous_system<L2> >, T2> >{ /// INTERNAL ONLY typedef quantity<unit<D, heterogeneous_system<L2> >, T2> destination_type; static destination_type convert(const quantity<unit<D, homogeneous_system<L1> >, T1>& source) { return(destination_type::from_value(source.value() / (detail::conversion_impl<L2::type::size::value>::template apply< typename L2::type, homogeneous_system<L1> >::value() * eval_scale_list<typename L2::scale>::value() ) )); }};/// Requires that all possible conversions/// between base units are defined./// INTERNAL ONLYtemplate<class D, class S1, class T1, class S2, class T2>struct conversion_helper<quantity<unit<D, heterogeneous_system<S1> >, T1>, quantity<unit<D, heterogeneous_system<S2> >, T2> >{ /// INTERNAL ONLY typedef quantity<unit<D, heterogeneous_system<S1> >, T1> source_type; /// INTERNAL ONLY typedef quantity<unit<D, heterogeneous_system<S2> >, T2> destination_type; /// INTERNAL ONLY typedef typename detail::extract_base_units<S1::type::size::value>::template apply< typename S1::type, dimensionless_type >::type from_base_units; /// INTERNAL ONLY typedef typename detail::extract_base_units<S2::type::size::value>::template apply< typename S2::type, from_base_units >::type all_base_units; /// INTERNAL ONLY typedef typename detail::make_homogeneous_system<all_base_units>::type system; /// INTERNAL ONLY typedef typename mpl::divides<typename S1::scale, typename S2::scale>::type result_scale; static destination_type convert(const source_type& source) { return(destination_type::from_value(source.value() * (detail::conversion_impl<S1::type::size::value>::template apply< typename S1::type, system >::value() * eval_scale_list<result_scale>::value() / detail::conversion_impl<S2::type::size::value>::template apply< typename S2::type, system >::value() ) )); }};namespace detail {template<class Source, class Dest>struct conversion_factor_helper;template<class D, class L1, class L2>struct conversion_factor_helper<unit<D, homogeneous_system<L1> >, unit<D, homogeneous_system<L2> > >{ typedef typename reduce_unit<unit<D, homogeneous_system<L1> > >::type source_unit; typedef typename source_unit::system_type::type unit_list; typedef typename detail::conversion_impl<unit_list::size::value>::template apply< unit_list, homogeneous_system<L2> > impl; typedef typename impl::type type; static type value() { return(impl::value()); }};template<class D, class L1, class L2>struct conversion_factor_helper<unit<D, heterogeneous_system<L1> >, unit<D, homogeneous_system<L2> > >{ typedef typename detail::conversion_impl<L1::type::size::value>::template apply< typename L1::type, homogeneous_system<L2> > impl; typedef eval_scale_list<typename L1::scale> scale; typedef typename multiply_typeof_helper<typename impl::type, typename scale::type>::type type; static type value() { return(impl::value() * scale::value()); }};// There is no simple algorithm for doing this conversion// other than just defining it as the reverse of the// heterogeneous->homogeneous casetemplate<class D, class L1, class L2>struct conversion_factor_helper<unit<D, homogeneous_system<L1> >, unit<D, heterogeneous_system<L2> > >{ typedef typename detail::conversion_impl<L2::type::size::value>::template apply< typename L2::type, homogeneous_system<L1> > impl; typedef eval_scale_list<typename L2::scale> scale; typedef typename multiply_typeof_helper<typename impl::type, typename scale::type>::type type; static type value() { return(one() / (impl::value() * scale::value())); }};/// Requires that all possible conversions/// between base units are defined.template<class D, class S1, class S2>struct conversion_factor_helper<unit<D, heterogeneous_system<S1> >, unit<D, heterogeneous_system<S2> > >{ /// INTERNAL ONLY typedef typename detail::extract_base_units<S1::type::size::value>::template apply< typename S1::type, dimensionless_type >::type from_base_units; /// INTERNAL ONLY typedef typename detail::extract_base_units<S2::type::size::value>::template apply< typename S2::type, from_base_units >::type all_base_units; /// INTERNAL ONLY typedef typename detail::make_homogeneous_system<all_base_units>::type system; typedef typename detail::conversion_impl<S1::type::size::value>::template apply< typename S1::type, system > conversion1; typedef typename detail::conversion_impl<S2::type::size::value>::template apply< typename S2::type, system > conversion2; typedef eval_scale_list<typename mpl::divides<typename S1::scale, typename S2::scale>::type> scale; typedef typename multiply_typeof_helper< typename conversion1::type, typename divide_typeof_helper<typename scale::type, typename conversion2::type>::type >::type type; static type value() { return(conversion1::value() * (scale::value() / conversion2::value())); }};} // namespace detail} // namespace units} // namespace boost#endif // BOOST_UNITS_CONVERSION_IMPL_HPP
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?