homogeneous_system.hpp 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  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_HOMOGENEOUS_SYSTEM_HPP_INCLUDED
  11. #define BOOST_UNITS_HOMOGENEOUS_SYSTEM_HPP_INCLUDED
  12. #include <boost/mpl/bool.hpp>
  13. #include <boost/units/config.hpp>
  14. #include <boost/units/static_rational.hpp>
  15. #ifdef BOOST_UNITS_CHECK_HOMOGENEOUS_UNITS
  16. #include <boost/type_traits/is_same.hpp>
  17. #include <boost/mpl/not.hpp>
  18. #include <boost/units/detail/linear_algebra.hpp>
  19. #endif
  20. namespace boost {
  21. namespace units {
  22. /// A system that can uniquely represent any unit
  23. /// which can be composed from a linearly independent set
  24. /// of base units. It is safe to rebind a unit with
  25. /// such a system to different dimensions.
  26. ///
  27. /// Do not construct this template directly. Use
  28. /// make_system instead.
  29. template<class L>
  30. struct homogeneous_system {
  31. /// INTERNAL ONLY
  32. typedef L type;
  33. };
  34. template<class T, class E>
  35. struct static_power;
  36. template<class T, class R>
  37. struct static_root;
  38. /// INTERNAL ONLY
  39. template<class L, long N, long D>
  40. struct static_power<homogeneous_system<L>, static_rational<N,D> >
  41. {
  42. typedef homogeneous_system<L> type;
  43. };
  44. /// INTERNAL ONLY
  45. template<class L, long N, long D>
  46. struct static_root<homogeneous_system<L>, static_rational<N,D> >
  47. {
  48. typedef homogeneous_system<L> type;
  49. };
  50. namespace detail {
  51. template<class System, class Dimensions>
  52. struct check_system;
  53. #ifdef BOOST_UNITS_CHECK_HOMOGENEOUS_UNITS
  54. template<class L, class Dimensions>
  55. struct check_system<homogeneous_system<L>, Dimensions> :
  56. boost::mpl::not_<
  57. boost::is_same<
  58. typename calculate_base_unit_exponents<
  59. L,
  60. Dimensions
  61. >::type,
  62. inconsistent
  63. >
  64. > {};
  65. #else
  66. template<class L, class Dimensions>
  67. struct check_system<homogeneous_system<L>, Dimensions> : mpl::true_ {};
  68. #endif
  69. } // namespace detail
  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::homogeneous_system, (class))
  75. #endif
  76. #endif