123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146 |
- #ifndef DATE_TIME_DATE_DURATION__
- #define DATE_TIME_DATE_DURATION__
- #include <boost/operators.hpp>
- #include <boost/date_time/special_defs.hpp>
- #include <boost/date_time/compiler_config.hpp>
- #include <boost/date_time/int_adapter.hpp>
- namespace boost {
- namespace date_time {
-
- template<class duration_rep_traits>
- class BOOST_SYMBOL_VISIBLE date_duration : private
- boost::less_than_comparable1< date_duration< duration_rep_traits >
- , boost::equality_comparable1< date_duration< duration_rep_traits >
- , boost::addable1< date_duration< duration_rep_traits >
- , boost::subtractable1< date_duration< duration_rep_traits >
- , boost::dividable2< date_duration< duration_rep_traits >, int
- > > > > >
- {
- public:
- typedef typename duration_rep_traits::int_type duration_rep_type;
- typedef typename duration_rep_traits::impl_type duration_rep;
-
- BOOST_CXX14_CONSTEXPR explicit date_duration(duration_rep day_count) : days_(day_count) {}
-
- BOOST_CXX14_CONSTEXPR date_duration(special_values sv) :
- days_(duration_rep::from_special(sv))
- {}
-
- BOOST_CXX14_CONSTEXPR duration_rep get_rep()const
- {
- return days_;
- }
- BOOST_CXX14_CONSTEXPR special_values as_special() const
- {
- return days_.as_special();
- }
- BOOST_CXX14_CONSTEXPR bool is_special()const
- {
- return days_.is_special();
- }
-
- BOOST_CXX14_CONSTEXPR duration_rep_type days() const
- {
- return duration_rep_traits::as_number(days_);
- }
-
- static BOOST_CXX14_CONSTEXPR date_duration unit()
- {
- return date_duration<duration_rep_traits>(1);
- }
-
- BOOST_CXX14_CONSTEXPR bool operator==(const date_duration& rhs) const
- {
- return days_ == rhs.days_;
- }
-
- BOOST_CXX14_CONSTEXPR bool operator<(const date_duration& rhs) const
- {
- return days_ < rhs.days_;
- }
-
-
- BOOST_CXX14_CONSTEXPR date_duration& operator-=(const date_duration& rhs)
- {
-
- days_ = days_ - rhs.days_;
- return *this;
- }
-
- BOOST_CXX14_CONSTEXPR date_duration& operator+=(const date_duration& rhs)
- {
- days_ = days_ + rhs.days_;
- return *this;
- }
-
- BOOST_CXX14_CONSTEXPR date_duration operator-() const
- {
- return date_duration<duration_rep_traits>(get_rep() * (-1));
- }
-
- BOOST_CXX14_CONSTEXPR date_duration& operator/=(int divisor)
- {
- days_ = days_ / divisor;
- return *this;
- }
-
- BOOST_CXX14_CONSTEXPR bool is_negative() const
- {
- return days_ < 0;
- }
- private:
- duration_rep days_;
- };
-
- struct BOOST_SYMBOL_VISIBLE duration_traits_long
- {
- typedef long int_type;
- typedef long impl_type;
- static BOOST_CXX14_CONSTEXPR int_type as_number(impl_type i) { return i; }
- };
-
- struct BOOST_SYMBOL_VISIBLE duration_traits_adapted
- {
- typedef long int_type;
- typedef boost::date_time::int_adapter<long> impl_type;
- static BOOST_CXX14_CONSTEXPR int_type as_number(impl_type i) { return i.as_number(); }
- };
- } }
- #endif
|