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

source code of boost/libs/units/test/test_header.hpp