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

source code of boost/libs/units/example/test_system.hpp