Chris@16
|
1 // Boost.Units - A C++ library for zero-overhead dimensional analysis and
|
Chris@16
|
2 // unit/quantity manipulation and conversion
|
Chris@16
|
3 //
|
Chris@16
|
4 // Copyright (C) 2003-2008 Matthias Christian Schabel
|
Chris@16
|
5 // Copyright (C) 2007-2008 Steven Watanabe
|
Chris@16
|
6 //
|
Chris@16
|
7 // Distributed under the Boost Software License, Version 1.0. (See
|
Chris@16
|
8 // accompanying file LICENSE_1_0.txt or copy at
|
Chris@16
|
9 // http://www.boost.org/LICENSE_1_0.txt)
|
Chris@16
|
10
|
Chris@16
|
11 /// \file
|
Chris@16
|
12 /// \brief base unit (meter, kg, sec...).
|
Chris@16
|
13 /// \details base unit definition registration.
|
Chris@16
|
14
|
Chris@16
|
15 #ifndef BOOST_UNITS_BASE_UNIT_HPP
|
Chris@16
|
16 #define BOOST_UNITS_BASE_UNIT_HPP
|
Chris@16
|
17
|
Chris@16
|
18 #include <boost/units/config.hpp>
|
Chris@16
|
19 #include <boost/units/heterogeneous_system.hpp>
|
Chris@16
|
20 #include <boost/units/static_rational.hpp>
|
Chris@16
|
21 #include <boost/units/units_fwd.hpp>
|
Chris@16
|
22 #include <boost/units/unit.hpp>
|
Chris@16
|
23 #include <boost/units/detail/dimension_list.hpp>
|
Chris@16
|
24 #include <boost/units/detail/ordinal.hpp>
|
Chris@16
|
25 #include <boost/units/detail/prevent_redefinition.hpp>
|
Chris@16
|
26
|
Chris@16
|
27 namespace boost {
|
Chris@16
|
28
|
Chris@16
|
29 namespace units {
|
Chris@16
|
30
|
Chris@16
|
31 /// This must be in namespace boost::units so that ADL
|
Chris@16
|
32 /// will work with friend functions defined inline.
|
Chris@16
|
33 /// Base dimensions and base units are independent.
|
Chris@16
|
34 /// INTERNAL ONLY
|
Chris@16
|
35 template<long N> struct base_unit_ordinal { };
|
Chris@16
|
36
|
Chris@16
|
37 /// INTERNAL ONLY
|
Chris@16
|
38 template<class T, long N> struct base_unit_pair { };
|
Chris@16
|
39
|
Chris@16
|
40 /// INTERNAL ONLY
|
Chris@16
|
41 template<class T, long N>
|
Chris@16
|
42 struct check_base_unit {
|
Chris@16
|
43 enum {
|
Chris@16
|
44 value =
|
Chris@16
|
45 sizeof(boost_units_unit_is_registered(units::base_unit_ordinal<N>())) == sizeof(detail::yes) &&
|
Chris@16
|
46 sizeof(boost_units_unit_is_registered(units::base_unit_pair<T, N>())) != sizeof(detail::yes)
|
Chris@16
|
47 };
|
Chris@16
|
48 };
|
Chris@16
|
49
|
Chris@16
|
50 /// Defines a base unit. To define a unit you need to provide
|
Chris@16
|
51 /// the derived class (CRTP), a dimension list and a unique integer.
|
Chris@16
|
52 /// @code
|
Chris@16
|
53 /// struct my_unit : boost::units::base_unit<my_unit, length_dimension, 1> {};
|
Chris@16
|
54 /// @endcode
|
Chris@16
|
55 /// It is designed so that you will get an error message if you try
|
Chris@16
|
56 /// to use the same value in multiple definitions.
|
Chris@16
|
57 template<class Derived,
|
Chris@16
|
58 class Dim,
|
Chris@16
|
59 long N
|
Chris@16
|
60 #if !defined(BOOST_UNITS_DOXYGEN) && !defined(__BORLANDC__)
|
Chris@16
|
61 ,
|
Chris@16
|
62 class = typename detail::ordinal_has_already_been_defined<
|
Chris@16
|
63 check_base_unit<Derived, N>::value
|
Chris@16
|
64 >::type
|
Chris@16
|
65 #endif
|
Chris@16
|
66 >
|
Chris@16
|
67 class base_unit :
|
Chris@16
|
68 public ordinal<N>
|
Chris@16
|
69 {
|
Chris@16
|
70 public:
|
Chris@16
|
71 /// INTERNAL ONLY
|
Chris@16
|
72 typedef void boost_units_is_base_unit_type;
|
Chris@16
|
73 /// INTERNAL ONLY
|
Chris@16
|
74 typedef base_unit this_type;
|
Chris@16
|
75 /// The dimensions of this base unit.
|
Chris@16
|
76 typedef Dim dimension_type;
|
Chris@16
|
77
|
Chris@16
|
78 /// Provided for mpl compatability.
|
Chris@16
|
79 typedef Derived type;
|
Chris@16
|
80
|
Chris@16
|
81 /// The unit corresponding to this base unit.
|
Chris@16
|
82 #ifndef BOOST_UNITS_DOXYGEN
|
Chris@16
|
83 typedef unit<
|
Chris@16
|
84 Dim,
|
Chris@16
|
85 heterogeneous_system<
|
Chris@16
|
86 heterogeneous_system_impl<
|
Chris@16
|
87 list<
|
Chris@16
|
88 heterogeneous_system_dim<Derived,static_rational<1> >,
|
Chris@16
|
89 dimensionless_type
|
Chris@16
|
90 >,
|
Chris@16
|
91 Dim,
|
Chris@16
|
92 no_scale
|
Chris@16
|
93 >
|
Chris@16
|
94 >
|
Chris@16
|
95 > unit_type;
|
Chris@16
|
96 #else
|
Chris@16
|
97 typedef detail::unspecified unit_type;
|
Chris@16
|
98 #endif
|
Chris@16
|
99
|
Chris@16
|
100 private:
|
Chris@16
|
101 /// Check for C++0x. In C++0x, we have to have identical
|
Chris@16
|
102 /// arguments but a different return type to trigger an
|
Chris@16
|
103 /// error. Note that this is only needed for clang as
|
Chris@16
|
104 /// check_base_unit will trigger an error earlier
|
Chris@16
|
105 /// for compilers with less strict name lookup.
|
Chris@16
|
106 /// INTERNAL ONLY
|
Chris@16
|
107 friend Derived*
|
Chris@16
|
108 check_double_register(const units::base_unit_ordinal<N>&)
|
Chris@16
|
109 { return(0); }
|
Chris@16
|
110
|
Chris@16
|
111 /// Register this ordinal
|
Chris@16
|
112 /// INTERNAL ONLY
|
Chris@16
|
113 friend detail::yes
|
Chris@16
|
114 boost_units_unit_is_registered(const units::base_unit_ordinal<N>&)
|
Chris@16
|
115 { detail::yes result; return(result); }
|
Chris@16
|
116
|
Chris@16
|
117 /// But make sure we can identify the current instantiation!
|
Chris@16
|
118 /// INTERNAL ONLY
|
Chris@16
|
119 friend detail::yes
|
Chris@16
|
120 boost_units_unit_is_registered(const units::base_unit_pair<Derived, N>&)
|
Chris@16
|
121 { detail::yes result; return(result); }
|
Chris@16
|
122 };
|
Chris@16
|
123
|
Chris@16
|
124 } // namespace units
|
Chris@16
|
125
|
Chris@16
|
126 } // namespace boost
|
Chris@16
|
127
|
Chris@16
|
128 #endif // BOOST_UNITS_BASE_UNIT_HPP
|