• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
26 namespace boost {
27 
28 namespace units {
29 
30 //[test_system_snippet_1
31 
32 /// base dimension of length
33 struct length_base_dimension : base_dimension<length_base_dimension,1> { };
34 /// base dimension of mass
35 struct mass_base_dimension : base_dimension<mass_base_dimension,2> { };
36 /// base dimension of time
37 struct time_base_dimension : base_dimension<time_base_dimension,3> { };
38 
39 //]
40 
41 #if 0
42 //[test_system_snippet_2
43 
44 typedef make_dimension_list<
45     boost::mpl::list< dim< length_base_dimension,static_rational<1> > >
46 >::type   length_dimension;
47 
48 typedef make_dimension_list<
49     boost::mpl::list< dim< mass_base_dimension,static_rational<1> > >
50 >::type     mass_dimension;
51 
52 typedef 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
60 typedef length_base_dimension::dimension_type    length_dimension;
61 typedef mass_base_dimension::dimension_type      mass_dimension;
62 typedef time_base_dimension::dimension_type      time_dimension;
63 //]
64 
65 #if 0
66 //[test_system_snippet_4
67 
68 typedef make_dimension_list<
69     boost::mpl::list< dim< length_base_dimension,static_rational<2> > >
70 >::type   area_dimension;
71 
72 typedef 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
82 typedef derived_dimension<length_base_dimension,2>::type  area_dimension;
83 typedef derived_dimension<mass_base_dimension,1,
84                           length_base_dimension,2,
85                           time_base_dimension,-2>::type   energy_dimension;
86 //]
87 
88 namespace test {
89 
90 //[test_system_snippet_6
91 
92 struct meter_base_unit : base_unit<meter_base_unit, length_dimension, 1> { };
93 struct kilogram_base_unit : base_unit<kilogram_base_unit, mass_dimension, 2> { };
94 struct second_base_unit : base_unit<second_base_unit, time_dimension, 3> { };
95 
96 typedef make_system<
97     meter_base_unit,
98     kilogram_base_unit,
99     second_base_unit>::type mks_system;
100 
101 /// unit typedefs
102 typedef unit<dimensionless_type,mks_system>      dimensionless;
103 
104 typedef unit<length_dimension,mks_system>        length;
105 typedef unit<mass_dimension,mks_system>          mass;
106 typedef unit<time_dimension,mks_system>          time;
107 
108 typedef unit<area_dimension,mks_system>          area;
109 typedef unit<energy_dimension,mks_system>        energy;
110 //]
111 
112 //[test_system_snippet_7
113 /// unit constants
114 BOOST_UNITS_STATIC_CONSTANT(meter,length);
115 BOOST_UNITS_STATIC_CONSTANT(meters,length);
116 BOOST_UNITS_STATIC_CONSTANT(kilogram,mass);
117 BOOST_UNITS_STATIC_CONSTANT(kilograms,mass);
118 BOOST_UNITS_STATIC_CONSTANT(second,time);
119 BOOST_UNITS_STATIC_CONSTANT(seconds,time);
120 
121 BOOST_UNITS_STATIC_CONSTANT(square_meter,area);
122 BOOST_UNITS_STATIC_CONSTANT(square_meters,area);
123 BOOST_UNITS_STATIC_CONSTANT(joule,energy);
124 BOOST_UNITS_STATIC_CONSTANT(joules,energy);
125 //]
126 
127 } // namespace test
128 
129 //[test_system_snippet_8
130 template<> struct base_unit_info<test::meter_base_unit>
131 {
nameboost::units::base_unit_info132     static std::string name()               { return "meter"; }
symbolboost::units::base_unit_info133     static std::string symbol()             { return "m"; }
134 };
135 //]
136 
137 template<> struct base_unit_info<test::kilogram_base_unit>
138 {
nameboost::units::base_unit_info139     static std::string name()               { return "kilogram"; }
symbolboost::units::base_unit_info140     static std::string symbol()             { return "kg"; }
141 };
142 
143 template<> struct base_unit_info<test::second_base_unit>
144 {
nameboost::units::base_unit_info145     static std::string name()               { return "second"; }
symbolboost::units::base_unit_info146     static std::string symbol()             { return "s"; }
147 };
148 
149 } // namespace units
150 
151 } // namespace boost
152 
153 #endif // MCS_TEST_SYSTEM_HPP
154