Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-12-15 10:09:54

0001 // Boost.Units - A C++ library for zero-overhead dimensional analysis and 
0002 // unit/quantity manipulation and conversion
0003 //
0004 // Copyright (C) 2003-2008 Matthias Christian Schabel
0005 // Copyright (C) 2007-2008 Steven Watanabe
0006 //
0007 // Distributed under the Boost Software License, Version 1.0. (See
0008 // accompanying file LICENSE_1_0.txt or copy at
0009 // http://www.boost.org/LICENSE_1_0.txt)
0010 
0011 /// \file
0012 /// \brief base unit (meter, kg, sec...).
0013 /// \details base unit definition registration.
0014 
0015 #ifndef BOOST_UNITS_BASE_UNIT_HPP
0016 #define BOOST_UNITS_BASE_UNIT_HPP
0017 
0018 #include <boost/units/config.hpp>
0019 #include <boost/units/heterogeneous_system.hpp>
0020 #include <boost/units/static_rational.hpp>
0021 #include <boost/units/units_fwd.hpp>
0022 #include <boost/units/unit.hpp>
0023 #include <boost/units/detail/dimension_list.hpp>
0024 #include <boost/units/detail/ordinal.hpp>
0025 #include <boost/units/detail/prevent_redefinition.hpp>
0026 
0027 namespace boost {
0028 
0029 namespace units {
0030 
0031 /// This must be in namespace boost::units so that ADL
0032 /// will work with friend functions defined inline.
0033 /// Base dimensions and base units are independent.
0034 /// INTERNAL ONLY
0035 template<long N> struct base_unit_ordinal { };
0036 
0037 /// INTERNAL ONLY
0038 template<class T, long N> struct base_unit_pair { };
0039 
0040 /// INTERNAL ONLY
0041 template<class T, long N>
0042 struct check_base_unit {
0043     enum {
0044         value =
0045             sizeof(boost_units_unit_is_registered(units::base_unit_ordinal<N>())) == sizeof(detail::yes) &&
0046             sizeof(boost_units_unit_is_registered(units::base_unit_pair<T, N>())) != sizeof(detail::yes)
0047     };
0048 };
0049 
0050 /// Defines a base unit.  To define a unit you need to provide
0051 /// the derived class (CRTP), a dimension list and a unique integer.
0052 /// @code
0053 /// struct my_unit : boost::units::base_unit<my_unit, length_dimension, 1> {};
0054 /// @endcode
0055 /// It is designed so that you will get an error message if you try
0056 /// to use the same value in multiple definitions.
0057 template<class Derived,
0058          class Dim,
0059          long N
0060 #if !defined(BOOST_UNITS_DOXYGEN) && !defined(BOOST_BORLANDC)
0061          ,
0062          class = typename detail::ordinal_has_already_been_defined<
0063              check_base_unit<Derived, N>::value
0064          >::type
0065 #endif
0066 >
0067 class base_unit : 
0068     public ordinal<N> 
0069 {
0070     public:
0071         /// INTERNAL ONLY
0072         typedef void boost_units_is_base_unit_type;
0073         /// INTERNAL ONLY
0074         typedef base_unit           this_type;
0075         /// The dimensions of this base unit.
0076         typedef Dim                 dimension_type;
0077 
0078         /// Provided for mpl compatability.
0079         typedef Derived type;
0080 
0081         /// The unit corresponding to this base unit.
0082 #ifndef BOOST_UNITS_DOXYGEN
0083         typedef unit<
0084             Dim,
0085             heterogeneous_system<
0086                 heterogeneous_system_impl<
0087                     list<
0088                         heterogeneous_system_dim<Derived,static_rational<1> >,
0089                         dimensionless_type
0090                     >,
0091                     Dim,
0092                     no_scale
0093                 >
0094             >
0095         > unit_type;
0096 #else
0097         typedef detail::unspecified unit_type;
0098 #endif
0099 
0100     private:
0101         /// Check for C++0x.  In C++0x, we have to have identical
0102         /// arguments but a different return type to trigger an
0103         /// error.  Note that this is only needed for clang as
0104         /// check_base_unit will trigger an error earlier
0105         /// for compilers with less strict name lookup.
0106         /// INTERNAL ONLY
0107         friend BOOST_CONSTEXPR Derived* 
0108         check_double_register(const units::base_unit_ordinal<N>&) 
0109         { return(0); }
0110 
0111         /// Register this ordinal
0112         /// INTERNAL ONLY
0113         friend BOOST_CONSTEXPR detail::yes 
0114         boost_units_unit_is_registered(const units::base_unit_ordinal<N>&) 
0115         { return(detail::yes()); }
0116         
0117         /// But make sure we can identify the current instantiation!
0118         /// INTERNAL ONLY
0119         friend BOOST_CONSTEXPR detail::yes 
0120         boost_units_unit_is_registered(const units::base_unit_pair<Derived, N>&) 
0121         { return(detail::yes()); }
0122 };
0123 
0124 } // namespace units
0125 
0126 } // namespace boost
0127 
0128 #endif // BOOST_UNITS_BASE_UNIT_HPP