test_system.hpp 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  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 MCS_TEST_SYSTEM_HPP
  11. #define MCS_TEST_SYSTEM_HPP
  12. #include <boost/mpl/list.hpp>
  13. #include <boost/mpl/vector.hpp>
  14. #include <boost/units/base_dimension.hpp>
  15. #include <boost/units/derived_dimension.hpp>
  16. #include <boost/units/io.hpp>
  17. #include <boost/units/quantity.hpp>
  18. #include <boost/units/static_constant.hpp>
  19. #include <boost/units/unit.hpp>
  20. #include <boost/units/base_unit.hpp>
  21. #include <boost/units/make_system.hpp>
  22. namespace boost {
  23. namespace units {
  24. //[test_system_snippet_1
  25. /// base dimension of length
  26. struct length_base_dimension : base_dimension<length_base_dimension,1> { };
  27. /// base dimension of mass
  28. struct mass_base_dimension : base_dimension<mass_base_dimension,2> { };
  29. /// base dimension of time
  30. struct time_base_dimension : base_dimension<time_base_dimension,3> { };
  31. //]
  32. #if 0
  33. //[test_system_snippet_2
  34. typedef make_dimension_list<
  35. boost::mpl::list< dim< length_base_dimension,static_rational<1> > >
  36. >::type length_dimension;
  37. typedef make_dimension_list<
  38. boost::mpl::list< dim< mass_base_dimension,static_rational<1> > >
  39. >::type mass_dimension;
  40. typedef make_dimension_list<
  41. boost::mpl::list< dim< time_base_dimension,static_rational<1> > >
  42. >::type time_dimension;
  43. //]
  44. #endif
  45. //[test_system_snippet_3
  46. typedef length_base_dimension::dimension_type length_dimension;
  47. typedef mass_base_dimension::dimension_type mass_dimension;
  48. typedef time_base_dimension::dimension_type time_dimension;
  49. //]
  50. #if 0
  51. //[test_system_snippet_4
  52. typedef make_dimension_list<
  53. boost::mpl::list< dim< length_base_dimension,static_rational<2> > >
  54. >::type area_dimension;
  55. typedef make_dimension_list<
  56. boost::mpl::list< dim< mass_base_dimension,static_rational<1> >,
  57. dim< length_base_dimension,static_rational<2> >,
  58. dim< time_base_dimension,static_rational<-2> > >
  59. >::type energy_dimension;
  60. //]
  61. #endif
  62. //[test_system_snippet_5
  63. typedef derived_dimension<length_base_dimension,2>::type area_dimension;
  64. typedef derived_dimension<mass_base_dimension,1,
  65. length_base_dimension,2,
  66. time_base_dimension,-2>::type energy_dimension;
  67. //]
  68. namespace test {
  69. //[test_system_snippet_6
  70. struct meter_base_unit : base_unit<meter_base_unit, length_dimension, 1> { };
  71. struct kilogram_base_unit : base_unit<kilogram_base_unit, mass_dimension, 2> { };
  72. struct second_base_unit : base_unit<second_base_unit, time_dimension, 3> { };
  73. typedef make_system<
  74. meter_base_unit,
  75. kilogram_base_unit,
  76. second_base_unit>::type mks_system;
  77. /// unit typedefs
  78. typedef unit<dimensionless_type,mks_system> dimensionless;
  79. typedef unit<length_dimension,mks_system> length;
  80. typedef unit<mass_dimension,mks_system> mass;
  81. typedef unit<time_dimension,mks_system> time;
  82. typedef unit<area_dimension,mks_system> area;
  83. typedef unit<energy_dimension,mks_system> energy;
  84. //]
  85. //[test_system_snippet_7
  86. /// unit constants
  87. BOOST_UNITS_STATIC_CONSTANT(meter,length);
  88. BOOST_UNITS_STATIC_CONSTANT(meters,length);
  89. BOOST_UNITS_STATIC_CONSTANT(kilogram,mass);
  90. BOOST_UNITS_STATIC_CONSTANT(kilograms,mass);
  91. BOOST_UNITS_STATIC_CONSTANT(second,time);
  92. BOOST_UNITS_STATIC_CONSTANT(seconds,time);
  93. BOOST_UNITS_STATIC_CONSTANT(square_meter,area);
  94. BOOST_UNITS_STATIC_CONSTANT(square_meters,area);
  95. BOOST_UNITS_STATIC_CONSTANT(joule,energy);
  96. BOOST_UNITS_STATIC_CONSTANT(joules,energy);
  97. //]
  98. } // namespace test
  99. //[test_system_snippet_8
  100. template<> struct base_unit_info<test::meter_base_unit>
  101. {
  102. static std::string name() { return "meter"; }
  103. static std::string symbol() { return "m"; }
  104. };
  105. //]
  106. template<> struct base_unit_info<test::kilogram_base_unit>
  107. {
  108. static std::string name() { return "kilogram"; }
  109. static std::string symbol() { return "kg"; }
  110. };
  111. template<> struct base_unit_info<test::second_base_unit>
  112. {
  113. static std::string name() { return "second"; }
  114. static std::string symbol() { return "s"; }
  115. };
  116. } // namespace units
  117. } // namespace boost
  118. #endif // MCS_TEST_SYSTEM_HPP