test_header.hpp 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  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. /**
  11. \file
  12. \brief test_header.hpp
  13. \details
  14. Unit system for test purposes.
  15. Output:
  16. @verbatim
  17. @endverbatim
  18. **/
  19. #ifndef BOOST_UNITS_TEST_HEADER_HPP
  20. #define BOOST_UNITS_TEST_HEADER_HPP
  21. #include <boost/test/minimal.hpp>
  22. #include <boost/units/base_dimension.hpp>
  23. #include <boost/units/derived_dimension.hpp>
  24. #include <boost/units/static_constant.hpp>
  25. #include <boost/units/quantity.hpp>
  26. #include <boost/units/io.hpp>
  27. #include <boost/units/base_unit.hpp>
  28. #include <boost/units/make_system.hpp>
  29. #include <boost/units/physical_dimensions/length.hpp>
  30. #include <boost/units/physical_dimensions/mass.hpp>
  31. #include <boost/units/physical_dimensions/time.hpp>
  32. #define BOOST_UNITS_CHECK_CLOSE(a, b) (BOOST_CHECK((std::abs((a) - (b)) < .0000001)))
  33. namespace boost {
  34. namespace units {
  35. //struct length_base_dimension : boost::units::base_dimension<length_base_dimension,1> { }; ///> base dimension of length
  36. //struct mass_base_dimension : boost::units::base_dimension<mass_base_dimension,2> { }; ///> base dimension of mass
  37. //struct time_base_dimension : boost::units::base_dimension<time_base_dimension,3> { }; ///> base dimension of time
  38. typedef length_base_dimension::dimension_type length_dimension;
  39. typedef mass_base_dimension::dimension_type mass_dimension;
  40. typedef time_base_dimension::dimension_type time_dimension;
  41. typedef derived_dimension<length_base_dimension,2>::type area_dimension;
  42. typedef derived_dimension<mass_base_dimension,1,
  43. length_base_dimension,2,
  44. time_base_dimension,-2>::type energy_dimension;
  45. typedef derived_dimension<mass_base_dimension,-1,
  46. length_base_dimension,-2,
  47. time_base_dimension,2>::type inverse_energy_dim;
  48. typedef derived_dimension<length_base_dimension,1,
  49. time_base_dimension,-1>::type velocity_dimension;
  50. typedef derived_dimension<length_base_dimension,3>::type volume_dimension;
  51. /// placeholder class defining test unit system
  52. struct length_unit : base_unit<length_unit, length_dimension, 4> {};
  53. struct mass_unit : base_unit<mass_unit, mass_dimension, 5> {};
  54. struct time_unit : base_unit<time_unit, time_dimension, 6> {};
  55. typedef make_system<length_unit, mass_unit, time_unit>::type system;
  56. /// unit typedefs
  57. typedef unit<dimensionless_type,system> dimensionless;
  58. typedef unit<length_dimension,system> length;
  59. typedef unit<mass_dimension,system> mass;
  60. typedef unit<time_dimension,system> time;
  61. typedef unit<area_dimension,system> area;
  62. typedef unit<energy_dimension,system> energy;
  63. typedef unit<inverse_energy_dim,system> inverse_energy;
  64. typedef unit<velocity_dimension,system> velocity;
  65. typedef unit<volume_dimension,system> volume;
  66. /// unit constants
  67. BOOST_UNITS_STATIC_CONSTANT(meter,length);
  68. BOOST_UNITS_STATIC_CONSTANT(meters,length);
  69. BOOST_UNITS_STATIC_CONSTANT(kilogram,mass);
  70. BOOST_UNITS_STATIC_CONSTANT(kilograms,mass);
  71. BOOST_UNITS_STATIC_CONSTANT(second,time);
  72. BOOST_UNITS_STATIC_CONSTANT(seconds,time);
  73. BOOST_UNITS_STATIC_CONSTANT(square_meter,area);
  74. BOOST_UNITS_STATIC_CONSTANT(square_meters,area);
  75. BOOST_UNITS_STATIC_CONSTANT(joule,energy);
  76. BOOST_UNITS_STATIC_CONSTANT(joules,energy);
  77. BOOST_UNITS_STATIC_CONSTANT(meter_per_second,velocity);
  78. BOOST_UNITS_STATIC_CONSTANT(meters_per_second,velocity);
  79. BOOST_UNITS_STATIC_CONSTANT(cubic_meter,volume);
  80. BOOST_UNITS_STATIC_CONSTANT(cubic_meters,volume);
  81. template<> struct base_unit_info<length_unit>
  82. {
  83. static std::string name() { return "meter"; }
  84. static std::string symbol() { return "m"; }
  85. };
  86. //]
  87. template<> struct base_unit_info<mass_unit>
  88. {
  89. static std::string name() { return "kilogram"; }
  90. static std::string symbol() { return "kg"; }
  91. };
  92. template<> struct base_unit_info<time_unit>
  93. {
  94. static std::string name() { return "second"; }
  95. static std::string symbol() { return "s"; }
  96. };
  97. } // namespace units
  98. } // namespace boost
  99. #endif // BOOST_UNITS_TEST_HEADER_HPP