annotate DEPENDENCIES/generic/include/boost/date_time/date_iterator.hpp @ 133:4acb5d8d80b6 tip

Don't fail environmental check if README.md exists (but .txt and no-suffix don't)
author Chris Cannam
date Tue, 30 Jul 2019 12:25:44 +0100
parents c530137014c0
children
rev   line source
Chris@16 1 #ifndef DATE_ITERATOR_HPP___
Chris@16 2 #define DATE_ITERATOR_HPP___
Chris@16 3
Chris@16 4 /* Copyright (c) 2002,2003 CrystalClear Software, Inc.
Chris@16 5 * Use, modification and distribution is subject to the
Chris@16 6 * Boost Software License, Version 1.0. (See accompanying
Chris@16 7 * file LICENSE_1_0.txt or http://www.boost.org/LICENSE_1_0.txt)
Chris@16 8 * Author: Jeff Garland, Bart Garst
Chris@101 9 * $Date$
Chris@16 10 */
Chris@16 11
Chris@16 12 #include <iterator>
Chris@16 13
Chris@16 14 namespace boost {
Chris@16 15 namespace date_time {
Chris@16 16 //! An iterator over dates with varying resolution (day, week, month, year, etc)
Chris@16 17 enum date_resolutions {day, week, months, year, decade, century, NumDateResolutions};
Chris@16 18
Chris@16 19 //! Base date iterator type
Chris@16 20 /*! This class provides the skeleton for the creation of iterators.
Chris@16 21 * New and interesting interators can be created by plugging in a new
Chris@16 22 * function that derives the next value from the current state.
Chris@16 23 * generation of various types of -based information.
Chris@16 24 *
Chris@16 25 * <b>Template Parameters</b>
Chris@16 26 *
Chris@16 27 * <b>date_type</b>
Chris@16 28 *
Chris@16 29 * The date_type is a concrete date_type. The date_type must
Chris@16 30 * define a duration_type and a calendar_type.
Chris@16 31 */
Chris@16 32 template<class date_type>
Chris@16 33 class date_itr_base {
Chris@16 34 // works, but benefit unclear at the moment
Chris@16 35 // class date_itr_base : public std::iterator<std::input_iterator_tag,
Chris@16 36 // date_type, void, void, void>{
Chris@16 37 public:
Chris@16 38 typedef typename date_type::duration_type duration_type;
Chris@16 39 typedef date_type value_type;
Chris@16 40 typedef std::input_iterator_tag iterator_category;
Chris@16 41
Chris@16 42 date_itr_base(date_type d) : current_(d) {}
Chris@16 43 virtual ~date_itr_base() {}
Chris@16 44 date_itr_base& operator++()
Chris@16 45 {
Chris@16 46 current_ = current_ + get_offset(current_);
Chris@16 47 return *this;
Chris@16 48 }
Chris@16 49 date_itr_base& operator--()
Chris@16 50 {
Chris@16 51 current_ = current_ + get_neg_offset(current_);
Chris@16 52 return *this;
Chris@16 53 }
Chris@16 54 virtual duration_type get_offset(const date_type& current) const=0;
Chris@16 55 virtual duration_type get_neg_offset(const date_type& current) const=0;
Chris@16 56 date_type operator*() {return current_;}
Chris@16 57 date_type* operator->() {return &current_;}
Chris@16 58 bool operator< (const date_type& d) {return current_ < d;}
Chris@16 59 bool operator<= (const date_type& d) {return current_ <= d;}
Chris@16 60 bool operator> (const date_type& d) {return current_ > d;}
Chris@16 61 bool operator>= (const date_type& d) {return current_ >= d;}
Chris@16 62 bool operator== (const date_type& d) {return current_ == d;}
Chris@16 63 bool operator!= (const date_type& d) {return current_ != d;}
Chris@16 64 private:
Chris@16 65 date_type current_;
Chris@16 66 };
Chris@16 67
Chris@16 68 //! Overrides the base date iterator providing hook for functors
Chris@16 69 /*
Chris@16 70 * <b>offset_functor</b>
Chris@16 71 *
Chris@16 72 * The offset functor must define a get_offset function that takes the
Chris@16 73 * current point in time and calculates and offset.
Chris@16 74 *
Chris@16 75 */
Chris@16 76 template<class offset_functor, class date_type>
Chris@16 77 class date_itr : public date_itr_base<date_type> {
Chris@16 78 public:
Chris@16 79 typedef typename date_type::duration_type duration_type;
Chris@16 80 date_itr(date_type d, int factor=1) :
Chris@16 81 date_itr_base<date_type>(d),
Chris@16 82 of_(factor)
Chris@16 83 {}
Chris@16 84 private:
Chris@16 85 virtual duration_type get_offset(const date_type& current) const
Chris@16 86 {
Chris@16 87 return of_.get_offset(current);
Chris@16 88 }
Chris@16 89 virtual duration_type get_neg_offset(const date_type& current) const
Chris@16 90 {
Chris@16 91 return of_.get_neg_offset(current);
Chris@16 92 }
Chris@16 93 offset_functor of_;
Chris@16 94 };
Chris@16 95
Chris@16 96
Chris@16 97
Chris@16 98 } } //namespace date_time
Chris@16 99
Chris@16 100
Chris@16 101 #endif