Back to home page

EIC code displayed by LXR

 
 

    


Warning, file /include/boost/units/absolute.hpp was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).

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) 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 ///
0012 /// \file
0013 /// \brief Absolute units (points rather than vectors).
0014 /// \details Operations between absolute units, and relative units like temperature differences.
0015 ///
0016 
0017 #ifndef BOOST_UNITS_ABSOLUTE_HPP
0018 #define BOOST_UNITS_ABSOLUTE_HPP
0019 
0020 #include <iosfwd>
0021 
0022 #include <boost/units/detail/absolute_impl.hpp>
0023 
0024 namespace boost {
0025 
0026 namespace units {
0027 
0028 /// A wrapper to represent absolute units (points rather than vectors).  Intended
0029 /// originally for temperatures, this class implements operators for absolute units 
0030 /// so that addition of a relative unit to an absolute unit results in another
0031 /// absolute unit : absolute<T> +/- T -> absolute<T> and subtraction of one absolute
0032 /// unit from another results in a relative unit : absolute<T> - absolute<T> -> T.
0033 template<class Y>
0034 class absolute
0035 {
0036     public:
0037         typedef absolute<Y>     this_type;
0038         typedef Y               value_type;
0039         
0040         BOOST_CONSTEXPR absolute() : val_() { }
0041         BOOST_CONSTEXPR absolute(const value_type& val) : val_(val) { }
0042         BOOST_CONSTEXPR absolute(const this_type& source) : val_(source.val_) { }
0043    
0044         BOOST_CXX14_CONSTEXPR this_type& operator=(const this_type& source)           { val_ = source.val_; return *this; }
0045         
0046         BOOST_CONSTEXPR const value_type& value() const                         { return val_; }
0047         
0048         BOOST_CXX14_CONSTEXPR const this_type& operator+=(const value_type& val)      { val_ += val; return *this; }
0049         BOOST_CXX14_CONSTEXPR const this_type& operator-=(const value_type& val)      { val_ -= val; return *this; }
0050         
0051     private:
0052         value_type   val_;
0053 };
0054 
0055 /// add a relative value to an absolute one
0056 template<class Y>
0057 BOOST_CONSTEXPR absolute<Y> operator+(const absolute<Y>& aval,const Y& rval)
0058 {
0059     return absolute<Y>(aval.value()+rval);
0060 }
0061 
0062 /// add a relative value to an absolute one
0063 template<class Y>
0064 BOOST_CONSTEXPR absolute<Y> operator+(const Y& rval,const absolute<Y>& aval)
0065 {
0066     return absolute<Y>(aval.value()+rval);
0067 }
0068 
0069 /// subtract a relative value from an absolute one
0070 template<class Y>
0071 BOOST_CONSTEXPR absolute<Y> operator-(const absolute<Y>& aval,const Y& rval)
0072 {
0073     return absolute<Y>(aval.value()-rval);
0074 }
0075 
0076 /// subtracting two absolutes gives a difference
0077 template<class Y>
0078 BOOST_CONSTEXPR Y operator-(const absolute<Y>& aval1,const absolute<Y>& aval2)
0079 {
0080     return Y(aval1.value()-aval2.value());
0081 }
0082 
0083 /// creates a quantity from an absolute unit and a raw value
0084 template<class D, class S, class T>
0085 BOOST_CONSTEXPR quantity<absolute<unit<D, S> >, T> operator*(const T& t, const absolute<unit<D, S> >&)
0086 {
0087     return(quantity<absolute<unit<D, S> >, T>::from_value(t));
0088 }
0089 
0090 /// creates a quantity from an absolute unit and a raw value
0091 template<class D, class S, class T>
0092 BOOST_CONSTEXPR quantity<absolute<unit<D, S> >, T> operator*(const absolute<unit<D, S> >&, const T& t)
0093 {
0094     return(quantity<absolute<unit<D, S> >, T>::from_value(t));
0095 }
0096 
0097 /// Print an absolute unit
0098 template<class Char, class Traits, class Y>
0099 std::basic_ostream<Char, Traits>& operator<<(std::basic_ostream<Char, Traits>& os,const absolute<Y>& aval)
0100 {
0101 
0102     os << "absolute " << aval.value();
0103     
0104     return os;
0105 }
0106 
0107 } // namespace units
0108 
0109 } // namespace boost
0110 
0111 #if BOOST_UNITS_HAS_BOOST_TYPEOF
0112 
0113 #include BOOST_TYPEOF_INCREMENT_REGISTRATION_GROUP()
0114 
0115 BOOST_TYPEOF_REGISTER_TEMPLATE(boost::units::absolute, (class))
0116 
0117 #endif
0118 
0119 namespace boost {
0120 
0121 namespace units {
0122 
0123 /// Macro to define the offset between two absolute units.
0124 /// Requires the value to be in the destination units e.g
0125 /// @code
0126 /// BOOST_UNITS_DEFINE_CONVERSION_OFFSET(celsius_base_unit, fahrenheit_base_unit, double, 32.0);
0127 /// @endcode
0128 /// @c BOOST_UNITS_DEFINE_CONVERSION_FACTOR is also necessary to
0129 /// specify the conversion factor.  Like @c BOOST_UNITS_DEFINE_CONVERSION_FACTOR
0130 /// this macro defines both forward and reverse conversions so 
0131 /// defining, e.g., the conversion from celsius to fahrenheit as above will also
0132 /// define the inverse conversion from fahrenheit to celsius.
0133 #define BOOST_UNITS_DEFINE_CONVERSION_OFFSET(From, To, type_, value_)   \
0134     namespace boost {                                                   \
0135     namespace units {                                                   \
0136     template<>                                                          \
0137     struct affine_conversion_helper<                                    \
0138         reduce_unit<From::unit_type>::type,                             \
0139         reduce_unit<To::unit_type>::type>                               \
0140     {                                                                   \
0141         BOOST_STATIC_CONSTEXPR bool is_defined = true;                  \
0142         typedef type_ type;                                             \
0143         static BOOST_CONSTEXPR type value() { return(value_); }         \
0144     };                                                                  \
0145     }                                                                   \
0146     }                                                                   \
0147     void boost_units_require_semicolon()
0148 
0149 } // namespace units
0150 
0151 } // namespace boost
0152 
0153 #endif // BOOST_UNITS_ABSOLUTE_HPP