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