|
From: Matthias S. <mat...@us...> - 2007-04-18 00:13:00
|
Update of /cvsroot/boost-sandbox/boost-sandbox/boost/units/experimental In directory sc8-pr-cvs3.sourceforge.net:/tmp/cvs-serv18491/experimental Added Files: base_unit.hpp fundamental_units.hpp make_system.hpp scaled_system.hpp Log Message: experimental headers for new system/unit implementation --- NEW FILE: scaled_system.hpp --- // mcs::units - A C++ library for zero-overhead dimensional analysis and // unit/quantity manipulation and conversion // // Copyright (C) 2003-2007 Matthias Christian Schabel // Copyright (C) 2007 Steven Watanabe // // Distributed under the Boost Software License, Version 1.0. (See // accompanying file LICENSE_1_0.txt or copy at // http://www.boost.org/LICENSE_1_0.txt) #ifndef BOOST_UNITS_SCALED_SYSTEM_HPP_INCLUDED #define BOOST_UNITS_SCALED_SYSTEM_HPP_INCLUDED #include <string> #include <boost/units/io.hpp> #include <boost/units/conversion.hpp> namespace boost { namespace units { template<long Base, long Exponent> struct scale; #define BOOST_UNITS_SCALE_SPECIALIZATION(base,exponent,val,name,symbol) \ template<> \ struct scale<base, exponent> \ { \ typedef double value_type; \ static value_type value() { return(val); } \ static std::string name_prefix() { return(#name); } \ static std::string symbol_prefix() { return(#symbol); } \ } #define BOOST_UNITS_SCALE_DEF(exponent,name,symbol) \ BOOST_UNITS_SCALE_SPECIALIZATION(10,exponent,1e ## exponent, name, symbol) \ /* BOOST_UNITS_SCALE_DEF(-24, yocto, y); BOOST_UNITS_SCALE_DEF(-21, zepto, z); BOOST_UNITS_SCALE_DEF(-18, atto, a); BOOST_UNITS_SCALE_DEF(-15, femto, f); BOOST_UNITS_SCALE_DEF(-12, pico, p); BOOST_UNITS_SCALE_DEF(-9, nano, n); BOOST_UNITS_SCALE_DEF(-6, micro, u); BOOST_UNITS_SCALE_DEF(-3, milli, m); BOOST_UNITS_SCALE_DEF(-2, centi, c); BOOST_UNITS_SCALE_DEF(-1, deci, d); BOOST_UNITS_SCALE_DEF(1, deka, da); BOOST_UNITS_SCALE_DEF(2, hecto, h); BOOST_UNITS_SCALE_DEF(3, kilo, k); BOOST_UNITS_SCALE_DEF(6, mega, M); BOOST_UNITS_SCALE_DEF(9, giga, G); BOOST_UNITS_SCALE_DEF(12, tera, T); BOOST_UNITS_SCALE_DEF(15, peta, P); BOOST_UNITS_SCALE_DEF(18, exa, E); BOOST_UNITS_SCALE_DEF(21, zetta, Z); BOOST_UNITS_SCALE_DEF(24, yotta, Y); */ #undef BOOST_UNITS_SCALE_DEF #undef BOOST_UNITS_SCALE_SPECIALIZATION template<class S, class Scale> struct scaled_system { typedef S system_type; typedef Scale scale_type; }; template<class DimensionTag, class System1, class Scale, class System2> struct base_unit_converter<DimensionTag, scaled_system<System1, Scale>, System2> { typedef base_unit_converter<DimensionTag, System1, System2> base; typedef typename divide_typeof_helper<typename base::type, typename Scale::value_type>::type type; static type value() { return(base::value() / Scale::value()); } }; template<class DimensionTag, class System1, class System2, class Scale> struct base_unit_converter<DimensionTag, System1, scaled_system<System2, Scale> > { typedef base_unit_converter<DimensionTag, System1, System2> base; typedef typename multiply_typeof_helper<typename base::type, typename Scale::value_type>::type type; static type value() { return(base::value() * Scale::value()); } }; template<class DimensionTag, class System1, class Scale1, class System2, class Scale2> struct base_unit_converter<DimensionTag, scaled_system<System1, Scale1>, scaled_system<System2, Scale2> > { typedef base_unit_converter<DimensionTag, System1, System2> base; typedef typename multiply_typeof_helper< typename base::type, typename divide_typeof_helper< typename Scale2::value_type, typename Scale1::value_type >::type >::type type; static type value() { return(base::value() * (Scale2::value() / Scale1::value())); } }; template<class DimensionTag, class System, class Scale> struct base_unit_info<DimensionTag, scaled_system<System, Scale> > { typedef base_unit_info<DimensionTag, System> base; static std::string name() { return(Scale::name_prefix() + base::name()); } static std::string symbol() { return(Scale::symbol_prefix() + base::symbol()); } }; } } #endif --- NEW FILE: base_unit.hpp --- // mcs::units - A C++ library for zero-overhead dimensional analysis and // unit/quantity manipulation and conversion // // Copyright (C) 2003-2007 Matthias Christian Schabel // Copyright (C) 2007 Steven Watanabe // // Distributed under the Boost Software License, Version 1.0. (See // accompanying file LICENSE_1_0.txt or copy at // http://www.boost.org/LICENSE_1_0.txt) #ifndef BOOST_UNITS_BASE_UNIT_HPP #define BOOST_UNITS_BASE_UNIT_HPP #include <boost/units/config.hpp> #include <boost/units/dim.hpp> #include <boost/units/dimension_list.hpp> #include <boost/units/static_rational.hpp> #include <boost/units/units_fwd.hpp> #include <boost/units/detail/prevent_ordinal_redefinition_impl.hpp> namespace boost { namespace units { /// INTERNAL ONLY template<class T, long N> struct base_unit_pair { }; /// Defines a base dimension. To define a dimension you need to provide /// the derived class (CRTP) and a unique integer. /// struct my_dimension : boost::units::base_dimension<my_dimension, 1> {}; /// It is designed so that you will get an error message if you try /// to use the same value in multiple definitions. template<class Derived, class Dim, long N, class = typename detail::ordinal_has_already_been_defined< sizeof(prevent_ordinal_redefinition(units::long_<N>())) == sizeof(detail::yes) && sizeof(prevent_ordinal_redefinition(units::base_unit_pair<Derived, N>())) != sizeof(detail::yes) >::type> class base_unit : public mpl::long_<N> { public: typedef base_unit this_type; typedef mpl::long_<N> value; typedef Dim dimension_type; private: /// Register this ordinal /// INTERNAL ONLY friend detail::yes prevent_ordinal_redefinition(const units::long_<N>&) { return(detail::yes()); } /// But make sure we can identify the current instantiation! /// INTERNAL ONLY friend detail::yes prevent_ordinal_redefinition(const units::base_unit_pair<Derived, N>&) { return(detail::yes()); } }; } // namespace units } // namespace boost #endif // BOOST_UNITS_BASE_UNIT_HPP --- NEW FILE: fundamental_units.hpp --- // mcs::units - A C++ library for zero-overhead dimensional analysis and // unit/quantity manipulation and conversion // // Copyright (C) 2003-2007 Matthias Christian Schabel // Copyright (C) 2007 Steven Watanabe // // Distributed under the Boost Software License, Version 1.0. (See // accompanying file LICENSE_1_0.txt or copy at // http://www.boost.org/LICENSE_1_0.txt) #ifndef BOOST_UNITS_OTHER_UNITS_HPP_INCLUDED #define BOOST_UNITS_OTHER_UNITS_HPP_INCLUDED namespace boost { namespace units { struct meter_tag : public ordinal<1> {}; struct foot_tag : public ordinal<2> {}; struct inch_tag : public ordinal<3> {}; struct yard_tag : public ordinal<4> {}; struct mile_tag : public ordinal<5> {}; struct gram_tag : public ordinal<6> {}; struct slug_tag : public ordinal<7> {}; struct second_tag : public ordinal<8> {}; struct minute_tag : public ordinal<9> {}; struct hour_tag : public ordinal<10> {}; struct ampere_tag : public ordinal<11> {}; struct biot_tag : public ordinal<12> {}; struct kelvin_tag : public ordinal<13> {}; struct mole_tag : public ordinal<14> {}; struct candela_tag : public ordinal<15> {}; struct radian_tag : public ordinal<16> {}; struct degree_tag : public ordinal<17> {}; struct gradian_tag : public ordinal<18> {}; struct steradian_tag : public ordinal<19> {}; } } #endif --- NEW FILE: make_system.hpp --- // mcs::units - A C++ library for zero-overhead dimensional analysis and // unit/quantity manipulation and conversion // // Copyright (C) 2003-2007 Matthias Christian Schabel // Copyright (C) 2007 Steven Watanabe // // Distributed under the Boost Software License, Version 1.0. (See // accompanying file LICENSE_1_0.txt or copy at // http://www.boost.org/LICENSE_1_0.txt) #ifndef BOOST_UNITS_COMPOUND_SYSTEM_HPP_INCLUDED #define BOOST_UNITS_COMPOUND_SYSTEM_HPP_INCLUDED #include <boost/mpl/size.hpp> #include <boost/mpl/begin.hpp> #include <boost/mpl/deref.hpp> #include <boost/mpl/next.hpp> #include <boost/mpl/at.hpp> #include <boost/mpl/push_front.hpp> #include <boost/units/experimental/scaled_system.hpp> #include <boost/units/system.hpp> #include <boost/units/io.hpp> #include <boost/units/conversion.hpp> #include <boost/units/dim.hpp> namespace boost { namespace units { template<class M> struct compound_system { typedef M map_type; }; template<class DimensionTag, class M, class System, class Scale> struct base_unit_converter<DimensionTag, compound_system<M>, scaled_system<System, Scale> > : base_unit_converter<DimensionTag, typename mpl::at<M, DimensionTag>::type, scaled_system<System, Scale> > {}; template<class DimensionTag, class System, class Scale, class M> struct base_unit_converter<DimensionTag, scaled_system<System, Scale>, compound_system<M> > : base_unit_converter<DimensionTag, scaled_system<System, Scale>, typename mpl::at<M, DimensionTag>::type> {}; template<class DimensionTag, class M, class System> struct base_unit_converter<DimensionTag, compound_system<M>, System> : base_unit_converter<DimensionTag, typename mpl::at<M, DimensionTag>::type, System> {}; template<class DimensionTag, class System, class M> struct base_unit_converter<DimensionTag, System, compound_system<M> > : base_unit_converter<DimensionTag, System, typename mpl::at<M, DimensionTag>::type> {}; template<class DimensionTag, class M1, class M2> struct base_unit_converter<DimensionTag, compound_system<M1>, compound_system<M2> > : base_unit_converter<DimensionTag, typename mpl::at<M1, DimensionTag>::type, typename mpl::at<M2, DimensionTag>::type> {}; template<class DimensionTag, class M> struct base_unit_info<DimensionTag, compound_system<M> > : base_unit_info<DimensionTag, typename mpl::at<M, DimensionTag>::type> {}; template<int N> struct compound_system_heterogeneous_system_view_impl { template<class Begin, class M> struct apply { typedef typename detail::get_tag<typename mpl::deref<Begin>::type>::type tag_type; typedef typename mpl::at<M,tag_type>::type at_type; typedef typename mpl::push_front<dimensionless_type,heterogeneous_system_element<at_type,typename mpl::deref<Begin>::type> >::type current; typedef typename compound_system_heterogeneous_system_view_impl<N - 1>::template apply<typename mpl::next<Begin>::type, M>::type next; typedef typename detail::merge_dimensions<current, next>::type type; }; }; template<> struct compound_system_heterogeneous_system_view_impl<0> { template<class Begin, class M> struct apply { typedef dimensionless_type type; }; }; template<class M, class Dimensions> struct heterogeneous_system_view<compound_system<M>, Dimensions> { typedef typename compound_system_heterogeneous_system_view_impl<mpl::size<Dimensions>::value>::template apply<typename mpl::begin<Dimensions>::type, M>::type type; typedef Dimensions dimension; }; template<class M> struct make_system { typedef homogeneous_system<compound_system<M> > type; }; } } #endif |