File indexing completed on 2025-01-18 09:30:37
0001 #ifndef DATE_ITERATOR_HPP___
0002 #define DATE_ITERATOR_HPP___
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012 #include <iterator>
0013
0014 namespace boost {
0015 namespace date_time {
0016
0017 enum date_resolutions {day, week, months, year, decade, century, NumDateResolutions};
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030
0031
0032 template<class date_type>
0033 class date_itr_base {
0034
0035
0036
0037 public:
0038 typedef typename date_type::duration_type duration_type;
0039 typedef date_type value_type;
0040 typedef std::input_iterator_tag iterator_category;
0041
0042 date_itr_base(date_type d) : current_(d) {}
0043 virtual ~date_itr_base() {}
0044 date_itr_base& operator++()
0045 {
0046 current_ = current_ + get_offset(current_);
0047 return *this;
0048 }
0049 date_itr_base& operator--()
0050 {
0051 current_ = current_ + get_neg_offset(current_);
0052 return *this;
0053 }
0054 virtual duration_type get_offset(const date_type& current) const=0;
0055 virtual duration_type get_neg_offset(const date_type& current) const=0;
0056 const date_type& operator*() const {return current_;}
0057 const date_type* operator->() const {return ¤t_;}
0058 bool operator< (const date_type& d) const {return current_ < d;}
0059 bool operator<= (const date_type& d) const {return current_ <= d;}
0060 bool operator> (const date_type& d) const {return current_ > d;}
0061 bool operator>= (const date_type& d) const {return current_ >= d;}
0062 bool operator== (const date_type& d) const {return current_ == d;}
0063 bool operator!= (const date_type& d) const {return current_ != d;}
0064 private:
0065 date_type current_;
0066 };
0067
0068
0069
0070
0071
0072
0073
0074
0075
0076 template<class offset_functor, class date_type>
0077 class date_itr : public date_itr_base<date_type> {
0078 public:
0079 typedef typename date_type::duration_type duration_type;
0080 date_itr(date_type d, int factor=1) :
0081 date_itr_base<date_type>(d),
0082 of_(factor)
0083 {}
0084 private:
0085 virtual duration_type get_offset(const date_type& current) const
0086 {
0087 return of_.get_offset(current);
0088 }
0089 virtual duration_type get_neg_offset(const date_type& current) const
0090 {
0091 return of_.get_neg_offset(current);
0092 }
0093 offset_functor of_;
0094 };
0095
0096
0097
0098 } }
0099
0100
0101 #endif