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 BOOST_UNITS_SCALED_BASE_UNIT_HPP_INCLUDED |
12 | #define BOOST_UNITS_SCALED_BASE_UNIT_HPP_INCLUDED |
13 | |
14 | #include <string> |
15 | |
16 | #include <boost/mpl/bool.hpp> |
17 | #include <boost/mpl/less.hpp> |
18 | #include <boost/type_traits/is_same.hpp> |
19 | |
20 | #include <boost/units/config.hpp> |
21 | #include <boost/units/dimension.hpp> |
22 | #include <boost/units/static_rational.hpp> |
23 | #include <boost/units/units_fwd.hpp> |
24 | |
25 | namespace boost { |
26 | |
27 | namespace units { |
28 | |
29 | template<class T> |
30 | struct heterogeneous_system; |
31 | |
32 | template<class T, class D, class Scale> |
33 | struct heterogeneous_system_impl; |
34 | |
35 | template<class T, class E> |
36 | struct heterogeneous_system_dim; |
37 | |
38 | template<class T> |
39 | struct base_unit_info; |
40 | |
41 | /// INTERNAL ONLY |
42 | struct scaled_base_unit_tag {}; |
43 | |
44 | template<class S, class Scale> |
45 | struct scaled_base_unit |
46 | { |
47 | /// INTERNAL ONLY |
48 | typedef void boost_units_is_base_unit_type; |
49 | typedef scaled_base_unit type; |
50 | typedef scaled_base_unit_tag tag; |
51 | typedef S system_type; |
52 | typedef Scale scale_type; |
53 | typedef typename S::dimension_type dimension_type; |
54 | |
55 | #ifdef BOOST_UNITS_DOXYGEN |
56 | |
57 | typedef detail::unspecified unit_type; |
58 | |
59 | #else |
60 | |
61 | typedef unit< |
62 | dimension_type, |
63 | heterogeneous_system< |
64 | heterogeneous_system_impl< |
65 | list< |
66 | heterogeneous_system_dim<scaled_base_unit,static_rational<1> >, |
67 | dimensionless_type |
68 | >, |
69 | dimension_type, |
70 | dimensionless_type |
71 | > |
72 | > |
73 | > unit_type; |
74 | |
75 | #endif |
76 | |
77 | static std::string symbol() |
78 | { |
79 | return(Scale::symbol() + base_unit_info<S>::symbol()); |
80 | } |
81 | static std::string name() |
82 | { |
83 | return(Scale::name() + base_unit_info<S>::name()); |
84 | } |
85 | }; |
86 | |
87 | } // namespace units |
88 | |
89 | } // namespace boost |
90 | |
91 | #if BOOST_UNITS_HAS_BOOST_TYPEOF |
92 | |
93 | #include BOOST_TYPEOF_INCREMENT_REGISTRATION_GROUP() |
94 | |
95 | BOOST_TYPEOF_REGISTER_TEMPLATE(boost::units::scaled_base_unit, (class)(class)) |
96 | |
97 | #endif |
98 | |
99 | namespace boost { |
100 | |
101 | #ifndef BOOST_UNITS_DOXYGEN |
102 | |
103 | namespace mpl { |
104 | |
105 | /// INTERNAL ONLY |
106 | template<class Tag> |
107 | struct less_impl<boost::units::scaled_base_unit_tag, Tag> |
108 | { |
109 | template<class T0, class T1> |
110 | struct apply : mpl::bool_< |
111 | mpl::less<typename T0::system_type, T1>::value || |
112 | (boost::is_same<typename T0::system_type, T1>::value && ((T0::scale_type::exponent::Numerator) < 0)) > {}; |
113 | }; |
114 | |
115 | /// INTERNAL ONLY |
116 | template<class Tag> |
117 | struct less_impl<Tag, boost::units::scaled_base_unit_tag> |
118 | { |
119 | template<class T0, class T1> |
120 | struct apply : mpl::bool_< |
121 | mpl::less<T0, typename T1::system_type>::value || |
122 | (boost::is_same<T0, typename T1::system_type>::value && ((T1::scale_type::exponent::Numerator) > 0)) > {}; |
123 | }; |
124 | |
125 | /// INTERNAL ONLY |
126 | template<> |
127 | struct less_impl<boost::units::scaled_base_unit_tag, boost::units::scaled_base_unit_tag> |
128 | { |
129 | template<class T0, class T1> |
130 | struct apply : mpl::bool_< |
131 | mpl::less<typename T0::system_type, typename T1::system_type>::value || |
132 | ((boost::is_same<typename T0::system_type, typename T1::system_type>::value) && |
133 | ((T0::scale_type::base) < (T1::scale_type::base) || |
134 | ((T0::scale_type::base) == (T1::scale_type::base) && |
135 | mpl::less<typename T0::scale_type::exponent, typename T1::scale_type::exponent>::value))) > {}; |
136 | }; |
137 | |
138 | } // namespace mpl |
139 | |
140 | #endif |
141 | |
142 | } // namespace boost |
143 | |
144 | #endif |
145 | |