BVB Source Codes

mars Show date_iterator.hpp Source code

Return Download mars: download date_iterator.hpp Source code - Download mars Source code - Type:.hpp
  1. #ifndef DATE_ITERATOR_HPP___
  2. #define DATE_ITERATOR_HPP___
  3.  
  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$
  10.  */
  11.  
  12. #include <iterator>
  13.  
  14. namespace mars_boost {} namespace boost = mars_boost; namespace mars_boost {
  15. namespace date_time {
  16.   //! An iterator over dates with varying resolution (day, week, month, year, etc)
  17.   enum date_resolutions {day, week, months, year, decade, century, NumDateResolutions};
  18.  
  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.
  24.    *
  25.    *  <b>Template Parameters</b>
  26.    *
  27.    *  <b>date_type</b>
  28.    *
  29.    *  The date_type is a concrete date_type. The date_type must
  30.    *  define a duration_type and a calendar_type.
  31.    */
  32.   template<class date_type>
  33.   class date_itr_base {
  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>{
  37.   public:
  38.     typedef typename date_type::duration_type duration_type;
  39.     typedef date_type value_type;
  40.     typedef std::input_iterator_tag iterator_category;
  41.  
  42.     date_itr_base(date_type d) : current_(d) {}
  43.     virtual ~date_itr_base() {}
  44.     date_itr_base& operator++()
  45.     {
  46.       current_ = current_ + get_offset(current_);
  47.       return *this;
  48.     }
  49.     date_itr_base& operator--()
  50.     {
  51.       current_ = current_ + get_neg_offset(current_);
  52.       return *this;
  53.     }
  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 &current_;}
  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;}
  64.   private:
  65.     date_type current_;
  66.   };
  67.  
  68.   //! Overrides the base date iterator providing hook for functors
  69.   /*
  70.    *  <b>offset_functor</b>
  71.    *
  72.    *  The offset functor must define a get_offset function that takes the
  73.    *  current point in time and calculates and offset.
  74.    *
  75.    */
  76.   template<class offset_functor, class date_type>
  77.   class date_itr : public date_itr_base<date_type> {
  78.   public:
  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),
  82.       of_(factor)
  83.     {}
  84.   private:
  85.     virtual duration_type get_offset(const date_type& current) const
  86.     {
  87.       return of_.get_offset(current);
  88.     }
  89.     virtual duration_type get_neg_offset(const date_type& current) const
  90.     {
  91.       return of_.get_neg_offset(current);
  92.     }
  93.     offset_functor of_;
  94.   };
  95.  
  96.  
  97.  
  98. } } //namespace date_time
  99.  
  100.  
  101. #endif
  102.  
downloaddate_iterator.hpp Source code - Download mars Source code
Related Source Codes/Software:
Hero - Elegant transition library for iOS & tvOS 2017-06-09
deep-photo-styletransfer - Code and data for paper "Deep Photo Style Transfer... 2017-06-09
mastodon - A GNU Social-compatible microblogging server ... 2017-06-09
plyr - A simple HTML5, YouTube and Vimeo player ... 2017-06-08
prepack - Prepack is a partial evaluator for JavaScript. Pre... 2017-06-08
Public-APIs - 2017-06-09
lottie-ios - An iOS library to natively render After Effects ve... 2017-06-09
Awesome-Hacking - A collection of various awesome lists for hackers,... 2017-06-09
algorithms - Minimal examples of data structures and algorithms... 2017-06-10
lectures - Oxford Deep NLP 2017 course 2017-06-10
CRYENGINE - CRYENGINE is a powerful real-time game development... 2017-06-11
postal - 2017-06-11
reactide - Reactide is the first dedicated IDE for React web ... 2017-06-11
rkt - rkt is a pod-native container engine for Linux. It... 2017-06-11
uWebSockets - Tiny WebSockets https://for... 2017-06-11
realworld - TodoMVC for the RealWorld - Exemplary fullstack Me... 2017-06-11
goreplay - GoReplay is an open-source tool for capturing and ... 2017-06-10
pyenv - Simple Python version management 2017-06-10
redux-saga - An alternative side effect model for Redux apps ... 2017-06-10
angular-starter - 2017-06-10

 Back to top