scaled_base_unit.hpp 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. // Boost.Units - A C++ library for zero-overhead dimensional analysis and
  2. // unit/quantity manipulation and conversion
  3. //
  4. // Copyright (C) 2003-2008 Matthias Christian Schabel
  5. // Copyright (C) 2008 Steven Watanabe
  6. //
  7. // Distributed under the Boost Software License, Version 1.0. (See
  8. // accompanying file LICENSE_1_0.txt or copy at
  9. // http://www.boost.org/LICENSE_1_0.txt)
  10. #ifndef BOOST_UNITS_SCALED_BASE_UNIT_HPP_INCLUDED
  11. #define BOOST_UNITS_SCALED_BASE_UNIT_HPP_INCLUDED
  12. #include <string>
  13. #include <boost/mpl/bool.hpp>
  14. #include <boost/mpl/less.hpp>
  15. #include <boost/type_traits/is_same.hpp>
  16. #include <boost/type_traits/detail/ice_and.hpp>
  17. #include <boost/type_traits/detail/ice_or.hpp>
  18. #include <boost/units/config.hpp>
  19. #include <boost/units/dimension.hpp>
  20. #include <boost/units/static_rational.hpp>
  21. #include <boost/units/units_fwd.hpp>
  22. namespace boost {
  23. namespace units {
  24. template<class T>
  25. struct heterogeneous_system;
  26. template<class T, class D, class Scale>
  27. struct heterogeneous_system_impl;
  28. template<class T, class E>
  29. struct heterogeneous_system_dim;
  30. template<class T>
  31. struct base_unit_info;
  32. /// INTERNAL ONLY
  33. struct scaled_base_unit_tag {};
  34. template<class S, class Scale>
  35. struct scaled_base_unit
  36. {
  37. /// INTERNAL ONLY
  38. typedef void boost_units_is_base_unit_type;
  39. typedef scaled_base_unit type;
  40. typedef scaled_base_unit_tag tag;
  41. typedef S system_type;
  42. typedef Scale scale_type;
  43. typedef typename S::dimension_type dimension_type;
  44. #ifdef BOOST_UNITS_DOXYGEN
  45. typedef detail::unspecified unit_type;
  46. #else
  47. typedef unit<
  48. dimension_type,
  49. heterogeneous_system<
  50. heterogeneous_system_impl<
  51. list<
  52. heterogeneous_system_dim<scaled_base_unit,static_rational<1> >,
  53. dimensionless_type
  54. >,
  55. dimension_type,
  56. dimensionless_type
  57. >
  58. >
  59. > unit_type;
  60. #endif
  61. static std::string symbol()
  62. {
  63. return(Scale::symbol() + base_unit_info<S>::symbol());
  64. }
  65. static std::string name()
  66. {
  67. return(Scale::name() + base_unit_info<S>::name());
  68. }
  69. };
  70. } // namespace units
  71. } // namespace boost
  72. #if BOOST_UNITS_HAS_BOOST_TYPEOF
  73. #include BOOST_TYPEOF_INCREMENT_REGISTRATION_GROUP()
  74. BOOST_TYPEOF_REGISTER_TEMPLATE(boost::units::scaled_base_unit, (class)(class))
  75. #endif
  76. namespace boost {
  77. #ifndef BOOST_UNITS_DOXYGEN
  78. namespace mpl {
  79. /// INTERNAL ONLY
  80. template<class Tag>
  81. struct less_impl<boost::units::scaled_base_unit_tag, Tag>
  82. {
  83. template<class T0, class T1>
  84. struct apply : mpl::bool_<
  85. boost::type_traits::ice_or<(mpl::less<typename T0::system_type, T1>::value),
  86. (boost::type_traits::ice_and<boost::is_same<typename T0::system_type, T1>::value, (T0::scale_type::exponent::Numerator) < 0>::value)>::value> {};
  87. };
  88. /// INTERNAL ONLY
  89. template<class Tag>
  90. struct less_impl<Tag, boost::units::scaled_base_unit_tag>
  91. {
  92. template<class T0, class T1>
  93. struct apply : mpl::bool_<
  94. boost::type_traits::ice_or<(mpl::less<T0, typename T1::system_type>::value),
  95. boost::type_traits::ice_and<(boost::is_same<T0, typename T1::system_type>::value), ((T1::scale_type::exponent::Numerator) > 0)>::value>::value> {};
  96. };
  97. /// INTERNAL ONLY
  98. template<>
  99. struct less_impl<boost::units::scaled_base_unit_tag, boost::units::scaled_base_unit_tag>
  100. {
  101. template<class T0, class T1>
  102. struct apply : mpl::bool_<
  103. boost::type_traits::ice_or<(mpl::less<typename T0::system_type, typename T1::system_type>::value),
  104. boost::type_traits::ice_and<(boost::is_same<typename T0::system_type, typename T1::system_type>::value),
  105. boost::type_traits::ice_or<((T0::scale_type::base) < (T1::scale_type::base)),
  106. boost::type_traits::ice_and<((T0::scale_type::base) == (T1::scale_type::base)),
  107. (mpl::less<typename T0::scale_type::exponent,typename T1::scale_type::exponent>::value)>::value>::value>::value>::value> {};
  108. };
  109. } // namespace mpl
  110. #endif
  111. } // namespace boost
  112. #endif