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) 2007-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 | /// \file |
12 | /// \brief base dimensions (mass, length, time...). |
13 | /// \details base dimension definition registration. |
14 | |
15 | #ifndef BOOST_UNITS_BASE_DIMENSION_HPP |
16 | #define BOOST_UNITS_BASE_DIMENSION_HPP |
17 | |
18 | #include <boost/units/config.hpp> |
19 | #include <boost/units/dim.hpp> |
20 | #include <boost/units/static_rational.hpp> |
21 | #include <boost/units/units_fwd.hpp> |
22 | #include <boost/units/detail/dimension_list.hpp> |
23 | #include <boost/units/detail/ordinal.hpp> |
24 | #include <boost/units/detail/prevent_redefinition.hpp> |
25 | |
26 | namespace boost { |
27 | |
28 | namespace units { |
29 | |
30 | /// This must be in namespace boost::units so that ADL |
31 | /// will work with friend functions defined inline. |
32 | /// INTERNAL ONLY |
33 | template<long N> struct base_dimension_ordinal { }; |
34 | |
35 | /// INTERNAL ONLY |
36 | template<class T, long N> struct base_dimension_pair { }; |
37 | |
38 | /// INTERNAL ONLY |
39 | template<class T, long N> |
40 | struct check_base_dimension { |
41 | enum { |
42 | value = |
43 | sizeof(boost_units_is_registered(units::base_dimension_ordinal<N>())) == sizeof(detail::yes) && |
44 | sizeof(boost_units_is_registered(units::base_dimension_pair<T, N>())) != sizeof(detail::yes) |
45 | }; |
46 | }; |
47 | |
48 | /// Defines a base dimension. To define a dimension you need to provide |
49 | /// the derived class (CRTP) and a unique integer. |
50 | /// @code |
51 | /// struct my_dimension : boost::units::base_dimension<my_dimension, 1> {}; |
52 | /// @endcode |
53 | /// It is designed so that you will get an error message if you try |
54 | /// to use the same value in multiple definitions. |
55 | template<class Derived, |
56 | long N |
57 | #if !defined(BOOST_UNITS_DOXYGEN) && !defined(__BORLANDC__) |
58 | , |
59 | class = typename detail::ordinal_has_already_been_defined< |
60 | check_base_dimension<Derived, N>::value |
61 | >::type |
62 | #endif |
63 | > |
64 | class base_dimension : |
65 | public ordinal<N> |
66 | { |
67 | public: |
68 | /// INTERNAL ONLY |
69 | typedef base_dimension this_type; |
70 | /// A convenience typedef. Equivalent to boost::units::derived_dimension<Derived,1>::type. |
71 | #ifndef BOOST_UNITS_DOXYGEN |
72 | typedef list<dim<Derived,static_rational<1> >, dimensionless_type> dimension_type; |
73 | #else |
74 | typedef detail::unspecified dimension_type; |
75 | #endif |
76 | /// Provided for mpl compatability. |
77 | typedef Derived type; |
78 | |
79 | private: |
80 | /// Check for C++0x. In C++0x, we have to have identical |
81 | /// arguments but a different return type to trigger an |
82 | /// error. Note that this is only needed for clang as |
83 | /// check_base_dimension will trigger an error earlier |
84 | /// for compilers with less strict name lookup. |
85 | /// INTERNAL ONLY |
86 | friend Derived* |
87 | check_double_register(const units::base_dimension_ordinal<N>&) |
88 | { return(0); } |
89 | |
90 | /// Register this ordinal |
91 | /// INTERNAL ONLY |
92 | friend detail::yes |
93 | boost_units_is_registered(const units::base_dimension_ordinal<N>&) |
94 | { detail::yes result; return(result); } |
95 | |
96 | /// But make sure we can identify the current instantiation! |
97 | /// INTERNAL ONLY |
98 | friend detail::yes |
99 | boost_units_is_registered(const units::base_dimension_pair<Derived, N>&) |
100 | { detail::yes result; return(result); } |
101 | }; |
102 | |
103 | } // namespace units |
104 | |
105 | } // namespace boost |
106 | |
107 | #endif // BOOST_UNITS_BASE_DIMENSION_HPP |
108 | |