Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-30 09:35:21

0001 #ifndef DATE_TIME_DATE_DURATION__
0002 #define DATE_TIME_DATE_DURATION__
0003 
0004 /* Copyright (c) 2002,2003 CrystalClear Software, Inc.
0005  * Use, modification and distribution is subject to the
0006  * Boost Software License, Version 1.0. (See accompanying
0007  * file LICENSE_1_0.txt or http://www.boost.org/LICENSE_1_0.txt)
0008  * Author: Jeff Garland, Bart Garst
0009  * $Date$
0010  */
0011 
0012 
0013 #include <boost/operators.hpp>
0014 #include <boost/date_time/special_defs.hpp>
0015 #include <boost/date_time/compiler_config.hpp>
0016 #include <boost/date_time/int_adapter.hpp>
0017 
0018 namespace boost {
0019 namespace date_time {
0020 
0021 
0022   //! Duration type with date level resolution
0023   template<class duration_rep_traits>
0024   class BOOST_SYMBOL_VISIBLE date_duration : private
0025               boost::less_than_comparable1< date_duration< duration_rep_traits >
0026             , boost::equality_comparable1< date_duration< duration_rep_traits >
0027             , boost::addable1< date_duration< duration_rep_traits >
0028             , boost::subtractable1< date_duration< duration_rep_traits >
0029             , boost::dividable2< date_duration< duration_rep_traits >, int
0030             > > > > >
0031   {
0032   public:
0033     typedef typename duration_rep_traits::int_type duration_rep_type;
0034     typedef typename duration_rep_traits::impl_type duration_rep;
0035 
0036     //! Construct from a day count
0037     BOOST_CXX14_CONSTEXPR explicit date_duration(duration_rep day_count) : days_(day_count) {}
0038 
0039     /*! construct from special_values - only works when
0040      * instantiated with duration_traits_adapted */
0041     BOOST_CXX14_CONSTEXPR date_duration(special_values sv) :
0042             days_(duration_rep::from_special(sv))
0043     {}
0044 
0045     //! returns days_ as it's instantiated type - used for streaming
0046     BOOST_CXX14_CONSTEXPR duration_rep get_rep()const
0047     {
0048         return days_;
0049     }
0050     BOOST_CXX14_CONSTEXPR special_values as_special() const
0051     {
0052         return days_.as_special();
0053     }
0054     BOOST_CXX14_CONSTEXPR bool is_special()const
0055     {
0056         return days_.is_special();
0057     }
0058     //! returns days as value, not object.
0059     BOOST_CXX14_CONSTEXPR duration_rep_type days() const
0060     {
0061         return duration_rep_traits::as_number(days_);
0062     }
0063     //! Returns the smallest duration -- used by to calculate 'end'
0064     static BOOST_CXX14_CONSTEXPR date_duration unit()
0065     {
0066         return date_duration<duration_rep_traits>(1);
0067     }
0068     //! Equality
0069     BOOST_CXX14_CONSTEXPR bool operator==(const date_duration& rhs) const
0070     {
0071         return days_ == rhs.days_;
0072     }
0073     //! Less
0074     BOOST_CXX14_CONSTEXPR bool operator<(const date_duration& rhs) const
0075     {
0076         return days_ < rhs.days_;
0077     }
0078 
0079     /* For shortcut operators (+=, -=, etc) simply using
0080      * "days_ += days_" may not work. If instantiated with
0081      * an int_adapter, shortcut operators are not present,
0082      * so this will not compile */
0083 
0084     //! Subtract another duration -- result is signed
0085     BOOST_CXX14_CONSTEXPR date_duration& operator-=(const date_duration& rhs)
0086     {
0087         //days_ -= rhs.days_;
0088         days_ = days_ - rhs.days_;
0089         return *this;
0090     }
0091     //! Add a duration -- result is signed
0092     BOOST_CXX14_CONSTEXPR date_duration& operator+=(const date_duration& rhs)
0093     {
0094         days_ = days_ + rhs.days_;
0095         return *this;
0096     }
0097 
0098     //! unary- Allows for dd = -date_duration(2); -> dd == -2
0099     BOOST_CXX14_CONSTEXPR date_duration operator-() const
0100     {
0101         return date_duration<duration_rep_traits>(get_rep() * (-1));
0102     }
0103     //! Division operations on a duration with an integer.
0104     BOOST_CXX14_CONSTEXPR date_duration& operator/=(int divisor)
0105     {
0106         days_ = days_ / divisor;
0107         return *this;
0108     }
0109 
0110     //! return sign information
0111     BOOST_CXX14_CONSTEXPR bool is_negative() const
0112     {
0113         return days_ < 0;
0114     }
0115 
0116   private:
0117     duration_rep days_;
0118   };
0119 
0120 
0121   /*! Struct for instantiating date_duration with <b>NO</b> special values
0122    * functionality. Allows for transparent implementation of either
0123    * date_duration<long> or date_duration<int_adapter<long> > */
0124   struct BOOST_SYMBOL_VISIBLE duration_traits_long
0125   {
0126     typedef long int_type;
0127     typedef long impl_type;
0128     static BOOST_CXX14_CONSTEXPR int_type as_number(impl_type i) { return i; }
0129   };
0130 
0131   /*! Struct for instantiating date_duration <b>WITH</b> special values
0132    * functionality. Allows for transparent implementation of either
0133    * date_duration<long> or date_duration<int_adapter<long> > */
0134   struct BOOST_SYMBOL_VISIBLE duration_traits_adapted
0135   {
0136     typedef long int_type;
0137     typedef boost::date_time::int_adapter<long> impl_type;
0138     static BOOST_CXX14_CONSTEXPR int_type as_number(impl_type i) { return i.as_number(); }
0139   };
0140 
0141 
0142 } } //namspace date_time
0143 
0144 
0145 #endif
0146