1 // Boost.Units - A C++ library for zero-overhead dimensional analysis and
2 // unit/quantity manipulation and conversion
4 // Copyright (C) 2003-2008 Matthias Christian Schabel
5 // Copyright (C) 2007-2008 Steven Watanabe
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)
11 #ifndef BOOST_UNITS_BASE_UNIT_HPP
12 #define BOOST_UNITS_BASE_UNIT_HPP
14 #include <boost/units/config.hpp>
15 #include <boost/units/heterogeneous_system.hpp>
16 #include <boost/units/static_rational.hpp>
17 #include <boost/units/units_fwd.hpp>
18 #include <boost/units/unit.hpp>
19 #include <boost/units/detail/dimension_list.hpp>
20 #include <boost/units/detail/ordinal.hpp>
21 #include <boost/units/detail/prevent_redefinition.hpp>
27 /// This must be in namespace boost::units so that ADL
28 /// will work with friend functions defined inline.
29 /// Base dimensions and base units are independent.
31 template<long N
> struct base_unit_ordinal
{ };
34 template<class T
, long N
> struct base_unit_pair
{ };
37 template<class T
, long N
>
38 struct check_base_unit
{
41 sizeof(boost_units_unit_is_registered(units::base_unit_ordinal
<N
>())) == sizeof(detail::yes
) &&
42 sizeof(boost_units_unit_is_registered(units::base_unit_pair
<T
, N
>())) != sizeof(detail::yes
)
46 /// Defines a base unit. To define a unit you need to provide
47 /// the derived class (CRTP), a dimension list and a unique integer.
49 /// struct my_unit : boost::units::base_unit<my_unit, length_dimension, 1> {};
51 /// It is designed so that you will get an error message if you try
52 /// to use the same value in multiple definitions.
53 template<class Derived
,
56 #if !defined(BOOST_UNITS_DOXYGEN) && !defined(__BORLANDC__)
58 class = typename
detail::ordinal_has_already_been_defined
<
59 check_base_unit
<Derived
, N
>::value
68 typedef void boost_units_is_base_unit_type
;
70 typedef base_unit this_type
;
71 /// The dimensions of this base unit.
72 typedef Dim dimension_type
;
74 /// Provided for mpl compatability.
77 /// The unit corresponding to this base unit.
78 #ifndef BOOST_UNITS_DOXYGEN
82 heterogeneous_system_impl
<
84 heterogeneous_system_dim
<Derived
,static_rational
<1> >,
93 typedef detail::unspecified unit_type
;
97 /// Register this ordinal
100 boost_units_unit_is_registered(const units::base_unit_ordinal
<N
>&)
101 { detail::yes result
; return(result
); }
103 /// But make sure we can identify the current instantiation!
106 boost_units_unit_is_registered(const units::base_unit_pair
<Derived
, N
>&)
107 { detail::yes result
; return(result
); }
114 #endif // BOOST_UNITS_BASE_UNIT_HPP