Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:30:37

0001 #ifndef DATE_ITERATOR_HPP___
0002 #define DATE_ITERATOR_HPP___
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 #include <iterator>
0013 
0014 namespace boost {
0015 namespace date_time {
0016   //! An iterator over dates with varying resolution (day, week, month, year, etc)
0017   enum date_resolutions {day, week, months, year, decade, century, NumDateResolutions};
0018 
0019   //! Base date iterator type
0020   /*! This class provides the skeleton for the creation of iterators.
0021    *  New and interesting interators can be created by plugging in a new
0022    *  function that derives the next value from the current state.
0023    *  generation of various types of -based information.
0024    *
0025    *  <b>Template Parameters</b>
0026    *
0027    *  <b>date_type</b>
0028    *
0029    *  The date_type is a concrete date_type. The date_type must
0030    *  define a duration_type and a calendar_type.
0031    */
0032   template<class date_type>
0033   class date_itr_base {
0034   // works, but benefit unclear at the moment
0035   //   class date_itr_base : public std::iterator<std::input_iterator_tag,
0036   //                                             date_type, void, void, void>{
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 &current_;}
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   //! Overrides the base date iterator providing hook for functors
0069   /*
0070    *  <b>offset_functor</b>
0071    *
0072    *  The offset functor must define a get_offset function that takes the
0073    *  current point in time and calculates and offset.
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 } } //namespace date_time
0099 
0100 
0101 #endif