scaled_base_unit.hpp 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  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/units/config.hpp>
  17. #include <boost/units/dimension.hpp>
  18. #include <boost/units/static_rational.hpp>
  19. #include <boost/units/units_fwd.hpp>
  20. namespace boost {
  21. namespace units {
  22. template<class T>
  23. struct heterogeneous_system;
  24. template<class T, class D, class Scale>
  25. struct heterogeneous_system_impl;
  26. template<class T, class E>
  27. struct heterogeneous_system_dim;
  28. template<class T>
  29. struct base_unit_info;
  30. /// INTERNAL ONLY
  31. struct scaled_base_unit_tag {};
  32. template<class S, class Scale>
  33. struct scaled_base_unit
  34. {
  35. /// INTERNAL ONLY
  36. typedef void boost_units_is_base_unit_type;
  37. typedef scaled_base_unit type;
  38. typedef scaled_base_unit_tag tag;
  39. typedef S system_type;
  40. typedef Scale scale_type;
  41. typedef typename S::dimension_type dimension_type;
  42. #ifdef BOOST_UNITS_DOXYGEN
  43. typedef detail::unspecified unit_type;
  44. #else
  45. typedef unit<
  46. dimension_type,
  47. heterogeneous_system<
  48. heterogeneous_system_impl<
  49. list<
  50. heterogeneous_system_dim<scaled_base_unit,static_rational<1> >,
  51. dimensionless_type
  52. >,
  53. dimension_type,
  54. dimensionless_type
  55. >
  56. >
  57. > unit_type;
  58. #endif
  59. static std::string symbol()
  60. {
  61. return(Scale::symbol() + base_unit_info<S>::symbol());
  62. }
  63. static std::string name()
  64. {
  65. return(Scale::name() + base_unit_info<S>::name());
  66. }
  67. };
  68. } // namespace units
  69. } // namespace boost
  70. #if BOOST_UNITS_HAS_BOOST_TYPEOF
  71. #include BOOST_TYPEOF_INCREMENT_REGISTRATION_GROUP()
  72. BOOST_TYPEOF_REGISTER_TEMPLATE(boost::units::scaled_base_unit, (class)(class))
  73. #endif
  74. namespace boost {
  75. #ifndef BOOST_UNITS_DOXYGEN
  76. namespace mpl {
  77. /// INTERNAL ONLY
  78. template<class Tag>
  79. struct less_impl<boost::units::scaled_base_unit_tag, Tag>
  80. {
  81. template<class T0, class T1>
  82. struct apply : mpl::bool_<
  83. mpl::less<typename T0::system_type, T1>::value ||
  84. (boost::is_same<typename T0::system_type, T1>::value && ((T0::scale_type::exponent::Numerator) < 0)) > {};
  85. };
  86. /// INTERNAL ONLY
  87. template<class Tag>
  88. struct less_impl<Tag, boost::units::scaled_base_unit_tag>
  89. {
  90. template<class T0, class T1>
  91. struct apply : mpl::bool_<
  92. mpl::less<T0, typename T1::system_type>::value ||
  93. (boost::is_same<T0, typename T1::system_type>::value && ((T1::scale_type::exponent::Numerator) > 0)) > {};
  94. };
  95. /// INTERNAL ONLY
  96. template<>
  97. struct less_impl<boost::units::scaled_base_unit_tag, boost::units::scaled_base_unit_tag>
  98. {
  99. template<class T0, class T1>
  100. struct apply : mpl::bool_<
  101. mpl::less<typename T0::system_type, typename T1::system_type>::value ||
  102. ((boost::is_same<typename T0::system_type, typename T1::system_type>::value) &&
  103. ((T0::scale_type::base) < (T1::scale_type::base) ||
  104. ((T0::scale_type::base) == (T1::scale_type::base) &&
  105. mpl::less<typename T0::scale_type::exponent, typename T1::scale_type::exponent>::value))) > {};
  106. };
  107. } // namespace mpl
  108. #endif
  109. } // namespace boost
  110. #endif