1
#ifndef DATE_ITERATOR_HPP___
2
#define DATE_ITERATOR_HPP___
4
/* Copyright (c) 2002,2003 CrystalClear Software, Inc.
5
* Use, modification and distribution is subject to the
6
* Boost Software License, Version 1.0. (See accompanying
7
* file LICENSE_1_0.txt or http://www.boost.org/LICENSE_1_0.txt)
8
* Author: Jeff Garland, Bart Garst
9
* $Date: 2012-09-22 15:33:33 -0700 (Sat, 22 Sep 2012) $
16
//! An iterator over dates with varying resolution (day, week, month, year, etc)
17
enum date_resolutions {day, week, months, year, decade, century, NumDateResolutions};
19
//! Base date iterator type
20
/*! This class provides the skeleton for the creation of iterators.
21
* New and interesting interators can be created by plugging in a new
22
* function that derives the next value from the current state.
23
* generation of various types of -based information.
25
* <b>Template Parameters</b>
29
* The date_type is a concrete date_type. The date_type must
30
* define a duration_type and a calendar_type.
32
template<class date_type>
34
// works, but benefit unclear at the moment
35
// class date_itr_base : public std::iterator<std::input_iterator_tag,
36
// date_type, void, void, void>{
38
typedef typename date_type::duration_type duration_type;
39
typedef date_type value_type;
40
typedef std::input_iterator_tag iterator_category;
42
date_itr_base(date_type d) : current_(d) {}
43
virtual ~date_itr_base() {}
44
date_itr_base& operator++()
46
current_ = current_ + get_offset(current_);
49
date_itr_base& operator--()
51
current_ = current_ + get_neg_offset(current_);
54
virtual duration_type get_offset(const date_type& current) const=0;
55
virtual duration_type get_neg_offset(const date_type& current) const=0;
56
date_type operator*() {return current_;}
57
date_type* operator->() {return ¤t_;}
58
bool operator< (const date_type& d) {return current_ < d;}
59
bool operator<= (const date_type& d) {return current_ <= d;}
60
bool operator> (const date_type& d) {return current_ > d;}
61
bool operator>= (const date_type& d) {return current_ >= d;}
62
bool operator== (const date_type& d) {return current_ == d;}
63
bool operator!= (const date_type& d) {return current_ != d;}
68
//! Overrides the base date iterator providing hook for functors
70
* <b>offset_functor</b>
72
* The offset functor must define a get_offset function that takes the
73
* current point in time and calculates and offset.
76
template<class offset_functor, class date_type>
77
class date_itr : public date_itr_base<date_type> {
79
typedef typename date_type::duration_type duration_type;
80
date_itr(date_type d, int factor=1) :
81
date_itr_base<date_type>(d),
85
virtual duration_type get_offset(const date_type& current) const
87
return of_.get_offset(current);
89
virtual duration_type get_neg_offset(const date_type& current) const
91
return of_.get_neg_offset(current);
98
} } //namespace date_time