ClockWork DB CoreAPI 1.0.48
Abstract Time Series and Storage/Management Library
Loading...
Searching...
No Matches
calendar.hpp
1#ifndef HAVE_TOM_CALENDAR_HPP
2#define HAVE_TOM_CALENDAR_HPP
3
4#include <tom-util/defines.hpp>
5
6#include <iostream>
7#include <string>
8#include <memory>
9
10// date stuff from boost
11#include <boost/date_time/gregorian/gregorian.hpp>
12#include <boost/date_time/posix_time/posix_time.hpp>
13
14namespace tom {
15namespace calendars {
16
17typedef boost::gregorian::date::date_int_type date_int_type;
18typedef long wdate_int_type;
19typedef boost::gregorian::date_duration date_duration;
20typedef boost::gregorian::greg_month greg_month;
21typedef boost::gregorian::greg_year greg_year;
22typedef boost::gregorian::greg_day greg_day;
23typedef boost::gregorian::greg_year_month_day greg_year_month_day;
24typedef boost::gregorian::gregorian_calendar gregorian_calendar;
25
26using boost::gregorian::to_simple_string;
27using boost::gregorian::to_iso_extended_string;
28using boost::gregorian::from_string;
29using boost::gregorian::from_undelimited_string;
30using boost::gregorian::day_clock;
31using boost::posix_time::ptime;
32using boost::posix_time::time_duration;
33using boost::posix_time::hours;
34using boost::posix_time::minutes;
35using boost::posix_time::seconds;
36using boost::posix_time::millisec;
37
38
39using boost::posix_time::to_simple_string;
40using boost::posix_time::to_iso_string;
41
42typedef ptime date_time;
43
44// simple wrapper class so we can access the protected
45// date::days_ for calendar calculations
46class TOM_UTIL_API date : public boost::gregorian::date
47{
48public:
49 date( greg_year y, greg_month m, greg_day d);
50
51 date( const date &d ) : boost::gregorian::date(d) { }
52
53 date( const boost::gregorian::date &d ) : boost::gregorian::date(d) { }
54
55 date( boost::gregorian::greg_year_month_day d ) : boost::gregorian::date(d) { }
56
57 date( date_int_type d ) : boost::gregorian::date( 1900,1,1) { days_ = d; }
58
59 date_int_type days() const { return days_; }
60
61};
62
63class TOM_UTIL_API timestamp : public tom::calendars::date
64{
65public:
66
67 timestamp( greg_year y, greg_month m, greg_day d, struct timespec *tspec = nullptr ) : tom::calendars::date(y,m,d)
68 {
69 if ( tspec ) { m_tspec.tv_sec = tspec->tv_sec; m_tspec.tv_nsec = tspec->tv_nsec; }
70 else { m_tspec.tv_sec = m_tspec.tv_nsec = 0; }
71 }
72
73 timestamp( const timestamp &d, struct timespec *tspec = nullptr ) : tom::calendars::date(d.days())
74 {
75 if ( tspec ) { m_tspec.tv_sec = tspec->tv_sec; m_tspec.tv_nsec = tspec->tv_nsec; }
76 }
77
78 timestamp( const boost::gregorian::date &d, struct timespec *tspec = nullptr ) : tom::calendars::date(d)
79 {
80 if ( tspec ) { m_tspec.tv_sec = tspec->tv_sec; m_tspec.tv_nsec = tspec->tv_nsec; }
81 }
82
83 timestamp( boost::gregorian::greg_year_month_day d, struct timespec *tspec = nullptr ) : tom::calendars::date(d)
84 {
85 if ( tspec ) { m_tspec.tv_sec = tspec->tv_sec; m_tspec.tv_nsec = tspec->tv_nsec; }
86 }
87
88 timestamp( date_int_type d, struct timespec *tspec = nullptr ) : tom::calendars::date( 1900,1,1)
89 {
90 if ( tspec ) { m_tspec.tv_sec = tspec->tv_sec; m_tspec.tv_nsec = tspec->tv_nsec; }
91 }
92
93 struct timespec
94 timespec() const {
95 return m_tspec;
96 }
97protected:
98 struct timespec m_tspec {0,0};
99
100};
101
102// simple wrapper for date_period
103// no use other than future expansion
104class TOM_UTIL_API date_period : public boost::gregorian::date_period
105{
106public:
107 date_period( date begin, date end ) : boost::gregorian::date_period(begin, end) { }
108 date_period( boost::gregorian::date begin, boost::gregorian::date end ) :
109 boost::gregorian::date_period(begin, end) { }
110 date_period( date begin, boost::gregorian::date_duration d ) : boost::gregorian::date_period( begin, d) { }
111 date_period( const date_period & rhs ) : boost::gregorian::date_period( rhs ) { }
112 date_period( const boost::gregorian::date_period & rhs) : boost::gregorian::date_period( rhs ) { }
113};
114
119class TOM_UTIL_API calendar
120{
121public:
122 virtual ~calendar(){}
123 virtual date_int_type operator()( const date & ) const = 0;
124 virtual date operator()( date_int_type ) const = 0;
125 virtual date_period get_date_period( const date & ) const = 0;
126 virtual date_period get_date_period( date_int_type ) const = 0;
127 virtual bool operator==( const calendar &rhs ) const = 0;
128 virtual bool operator!=( const calendar &rhs ) const = 0;
129 virtual const date &get_first_date( ) const = 0;
130 virtual const char *name() const = 0;
131};
132
133// class to represent a period of time as tied to a calendar
134// this class will automatically make date corrections so
135// dates fall from the beginning to the end of the intervals
136// as represented by the calendar...
137//
138// e.g.,
139// range r( monthly_calendar::Instance(),
140// Date( 2004,5,22 ), Date( 2004, 7, 23 ))
141// would represent the range from 2004-May-01 thru 2004-July-31
142// because the range adjusts start dates to the 1st date of the
143// interval as determined by the calendar, and the last date to the
144// last date of the interval as determined by the calendar.
145//
146class TOM_UTIL_API range : public date_period
147{
148public:
149 range( calendar &cal, date start, date end) :
150 date_period( cal.get_date_period( start ).begin(), cal.get_date_period( end ).end() ),
151 m_calendar(cal) { }
152 range( calendar &cal, date_int_type i ) :
153 date_period( cal.get_date_period( i ).begin(), cal.get_date_period( i ).end() + date_duration(1) ) ,
154 m_calendar(cal) { }
155 range( const range &rhs ) :
156 date_period( rhs.begin(), rhs.end() ),
157 m_calendar( rhs.m_calendar ) { }
158 range &operator=( const range &rhs )
159 {
160 this->date_period::operator=( rhs );
161 this->m_calendar = rhs.m_calendar;
162 return *this;
163 }
164 ~range() { }
165 const calendar &get_calendar() const { return m_calendar; }
166 date get_first_date( ) const { return begin( ); }
167 date get_last_date( ) const { return last( ); }
168 date get_end_date( ) const { return end( ); }
169 date_int_type get_first_date_int( ) const { return m_calendar( begin() ); }
170 date_int_type get_last_date_int( ) const { return m_calendar( last() ); }
171
172protected:
173 calendar & m_calendar;
174
175private:
176 range();
177};
178// base class for converter objects
179// whose sole purpose handles storing a static
180// first_date for the converter
181template < int FIRST_YEAR, int FIRST_MONTH, int FIRST_DAY>
182struct TOM_UTIL_API converter
183{
184 static const date first_date;
185 inline
186 static int get_first_year() { return FIRST_YEAR; }
187 inline
188 static int get_first_month() { return FIRST_MONTH; }
189 inline
190 static int get_first_day() { return FIRST_DAY; }
191 inline
192 static date get_first_date() { return date( FIRST_YEAR, FIRST_MONTH, FIRST_DAY ); }
193};
194
195template < int FIRST_YEAR, int FIRST_MONTH, int FIRST_DAY>
196const date converter<FIRST_YEAR,FIRST_MONTH,FIRST_DAY>::first_date = date( FIRST_YEAR, FIRST_MONTH, FIRST_DAY );
197
198
199// all the XXX_converters that follow have two basic
200// functions:
201// operator()( date_int_type ) that returns a Date
202// operator()( Date ) that returns a date_int_type
203// each corresponding operator() converts to/from
204// integral points and Date(s) for a given calendar.
205// e.g., '01 Jan 1850' is date_int_type '1' for the monthly converter
206// and '1' converts back to '31 Jan 1850'
207// NOTE: integral intervals convert back to the last day of the
208// interval.
209
210template < int FIRST_YEAR, int FIRST_MONTH, int FIRST_DAY>
211struct TOM_UTIL_API daily_converter : public converter<FIRST_YEAR,FIRST_MONTH,FIRST_DAY>
212{
213 date operator()( date_int_type ) const;
214 date_int_type operator()( const date & ) const;
215
216};
217
218template < int FIRST_YEAR, int FIRST_MONTH, int FIRST_DAY>
219inline
220date_int_type
222{
223 return d.days() - this->first_date.days() + 1;
224}
225
226template < int FIRST_YEAR, int FIRST_MONTH, int FIRST_DAY>
227inline
228date
229daily_converter<FIRST_YEAR,FIRST_MONTH,FIRST_DAY>::operator()( date_int_type di ) const
230{
231 return date( boost::gregorian::gregorian_calendar::from_day_number( di + this->first_date.days() -1 ));
232}
233
234template < int FIRST_YEAR, int FIRST_MONTH, int FIRST_DAY>
235struct TOM_UTIL_API business_converter : public converter<FIRST_YEAR,FIRST_MONTH,FIRST_DAY>
236{
237 date operator()( date_int_type ) const;
238 date_int_type operator()( const date & ) const;
239};
240
241template < int FIRST_YEAR, int FIRST_MONTH, int FIRST_DAY>
242inline
243date_int_type
245{
246 date d(dd);
247 switch (d.day_of_week() )
248 {
249 case boost::gregorian::Saturday:
250 d += date_duration( 2 );
251 break;
252 case boost::gregorian::Sunday:
253 d += date_duration( 1 );
254 }
255 date_int_type corrected = d.days() - this->first_date.days() + 1;
256 int m = corrected % 7;
257 if ( m == 5 || m == 6 )
258 return 0;
259 else
260 return corrected - (( corrected / 7 ) * 2);
261}
262
263template < int FIRST_YEAR, int FIRST_MONTH, int FIRST_DAY>
264inline
265date
266business_converter<FIRST_YEAR,FIRST_MONTH,FIRST_DAY>::operator()( date_int_type di ) const
267{
268 date_int_type corrected = di * 7;
269 date_int_type offset = 1;
270 if ( (corrected % 5) % 2 == 1 )
271 offset = 2;
272 corrected /= 5;
273 return date( this->first_date + date_duration( corrected - offset ) );
274}
275
276
277template < int FIRST_YEAR, int FIRST_MONTH, int FIRST_DAY>
278struct TOM_UTIL_API weekly_converter : public converter<FIRST_YEAR,FIRST_MONTH,FIRST_DAY>
279{
280 static const boost::gregorian::date_duration duration;
281 date operator()( date_int_type ) const;
282 date_int_type operator()( const date & ) const;
283
284};
285
286template < int FIRST_YEAR, int FIRST_MONTH, int FIRST_DAY>
287const date_duration weekly_converter<FIRST_YEAR,FIRST_MONTH,FIRST_DAY>::duration = date_duration(7);
288
289template < int FIRST_YEAR, int FIRST_MONTH, int FIRST_DAY>
290inline
291date_int_type
293{
294 date tmp = d;
295 while ( tmp.day_of_week() != this->first_date.day_of_week() ) { tmp += date_duration(1); }
296 date_duration dd = tmp - this->first_date;
297 date_int_type di = dd.days() / duration.days();
298 return di + 1;
299}
300template < int FIRST_YEAR, int FIRST_MONTH, int FIRST_DAY>
301inline
302date
303weekly_converter<FIRST_YEAR,FIRST_MONTH,FIRST_DAY>::operator()( date_int_type di ) const
304{
305 date_duration reversed = date_duration(date_duration( (di - 1) ).days() * duration.days());
306 date tmp = this->first_date;
307 tmp += reversed;
308 return tmp;
309}
310
311template < int FIRST_YEAR, int FIRST_MONTH, int FIRST_DAY>
312struct TOM_UTIL_API month_converter : public converter<FIRST_YEAR,FIRST_MONTH,FIRST_DAY>
313{
314 date operator()( date_int_type ) const;
315 date_int_type operator()( const date & ) const;
316
317};
318
319template < int FIRST_YEAR, int FIRST_MONTH, int FIRST_DAY>
320inline
321date_int_type
323{
324 return ( d.year() - this->first_date.year() ) * 12 + d.month();
325}
326
327template < int FIRST_YEAR, int FIRST_MONTH, int FIRST_DAY>
328inline
329date
330month_converter<FIRST_YEAR,FIRST_MONTH,FIRST_DAY>::operator()( date_int_type di ) const
331{
332 unsigned short mod = di % 12;
333 greg_month month( mod == 0 ? 12 : mod );
334
335 greg_year year = di / 12 + this->first_date.year() - ( mod == 0 ? 1 : 0 );
336 short int day = gregorian_calendar::end_of_month_day( year, month );
337 return date ( year, month, day );
338}
339
340template < int FIRST_YEAR, int FIRST_MONTH, int FIRST_DAY>
341struct TOM_UTIL_API quarterly_converter : public converter<FIRST_YEAR,FIRST_MONTH,FIRST_DAY>
342{
343 date operator()( date_int_type ) const;
344 date_int_type operator()( const date & ) const;
345 static greg_month first_month;
346};
347
348template < int FIRST_YEAR, int FIRST_MONTH, int FIRST_DAY>
349greg_month
352
353template < int FIRST_YEAR, int FIRST_MONTH, int FIRST_DAY>
354inline
355date_int_type
357{
358 date_int_type qtrs = ( d.year() - this->first_date.year() ) * 4 + 1;
359 signed short d_mon = d.month();
360 signed short first_qtr = ( first_month / 3 + ( first_month % 3 != 0 ? 1 : 0 ) );
361 signed short d_qtr = ( d_mon / 3 + ( d_mon % 3 != 0 ? 1 : 0 ) );
362 return qtrs + ( d_qtr - first_qtr );
363}
364
365template < int FIRST_YEAR, int FIRST_MONTH, int FIRST_DAY>
366inline
367date
368quarterly_converter<FIRST_YEAR,FIRST_MONTH,FIRST_DAY>::operator()( date_int_type di ) const
369{
370 signed short yr_mod = di % 4;
371 signed short mon_mod = yr_mod != 0 ? yr_mod - 1 : 3;
372 unsigned int year = (di / 4) + this->first_date.year();
373 unsigned short month = first_month + (mon_mod * 3);
374 if ( month > 12 ){ month = month - 12; }
375 if ( first_month == 3 && yr_mod == 0 ) year--;
376 short int day = gregorian_calendar::end_of_month_day( year, month );
377 return date ( year, month, day );
378}
379
380template < int FIRST_YEAR, int FIRST_MONTH, int FIRST_DAY>
381struct TOM_UTIL_API semiannual_converter : public converter<FIRST_YEAR,FIRST_MONTH,FIRST_DAY>
382{
383 date operator()( date_int_type ) const;
384 date_int_type operator()( const date & ) const;
385 static greg_month first_month;
386};
387
388template < int FIRST_YEAR, int FIRST_MONTH, int FIRST_DAY>
389greg_month
392
393template < int FIRST_YEAR, int FIRST_MONTH, int FIRST_DAY>
394inline
395date_int_type
397{
398 date_int_type qtrs = ( d.year() - this->first_date.year() ) * 2 + 1;
399 signed short d_mon = d.month();
400 signed short first_qtr = ( first_month / 6 + ( first_month % 6 != 0 ? 1 : 0 ) );
401 signed short d_qtr = ( d_mon / 6 + ( d_mon % 6 != 0 ? 1 : 0 ) );
402 return qtrs + ( d_qtr - first_qtr);
403}
404
405template < int FIRST_YEAR, int FIRST_MONTH, int FIRST_DAY>
406inline
407date
408semiannual_converter<FIRST_YEAR,FIRST_MONTH,FIRST_DAY>::operator()( date_int_type di ) const
409{
410 signed short yr_mod = di % 2;
411 signed short mon_mod = yr_mod != 0 ? yr_mod -1 : 1;
412 unsigned int year = (di / 2) + this->first_date.year();
413 unsigned short month = first_month + ( mon_mod * 6 );
414 if ( month > 12 ){ month = month - 12; }
415 if ( first_month == 6 && yr_mod == 0 ) year--;
416 short int day = gregorian_calendar::end_of_month_day( year, month );
417 return date ( year, month, day );
418}
419
420template < int FIRST_YEAR, int FIRST_MONTH, int FIRST_DAY>
421struct TOM_UTIL_API annual_converter : public converter<FIRST_YEAR,FIRST_MONTH,FIRST_DAY>
422{
423 date operator()( date_int_type ) const;
424 date_int_type operator()( const date & ) const;
425};
426
427template < int FIRST_YEAR, int FIRST_MONTH, int FIRST_DAY>
428inline
429date_int_type
431{
432 return d.year() - this->first_date.year() + 1;
433}
434
435template < int FIRST_YEAR, int FIRST_MONTH, int FIRST_DAY>
436inline
437date
438annual_converter<FIRST_YEAR,FIRST_MONTH,FIRST_DAY>::operator()( date_int_type di ) const
439{
440 greg_year year = di + this->first_date.year() - 1;
441 greg_month month = FIRST_MONTH;
442 short int day = gregorian_calendar::end_of_month_day( year, month );
443 return date ( year, month, day );
444}
445
446// calendar_impl is the implementation of the calendar
447// absttract class, and provides a simple mechanism,
448// joined w/ XXX_converters to provide a rich calendar
449// system.
450template <typename CONVERTER>
451class TOM_UTIL_API calendar_impl : public calendar
452{
453public:
454 typedef date::date_int_type date_int_type;
455 typedef CONVERTER converter_type;
456
457 static calendar_impl &Instance(); // factory method
458
459 virtual date_int_type operator()( const date & ) const; // map Date to interval
460 virtual date operator()( date_int_type ) const; // map interval to Date
461 virtual date_period get_date_period( const date & ) const;
462 virtual date_period get_date_period( date_int_type ) const;
463 virtual bool operator==( const calendar &rhs ) const;
464 virtual bool operator!=( const calendar &rhs ) const;
465 virtual const date &get_first_date( ) const;
466 virtual const char *name() const;
467
468private:
469 CONVERTER converter;
471
472};
473
474template <typename CONVERTER>
476/*
477template <typename CONVERTER>
478inline
479const char *
480calendar_impl<CONVERTER>::name() const
481{
482 // this is a bogus function to lookup
483 // calendar instances and return a name
484 return lookup_name( this );
485}
486*/
487template <typename CONVERTER>
488inline
489bool
490calendar_impl<CONVERTER>::operator==( const calendar &rhs ) const
491{
492 // we are singletons, so if memory address equals
493 // we are the same guy! (or gal)
494 if ( this == & rhs )
495 return true;
496 else
497 return false;
498}
499
500template <typename CONVERTER>
501inline
502bool
503calendar_impl<CONVERTER>::operator!=( const calendar &rhs ) const
504{
505 if ( *this == rhs )
506 return false;
507 else
508 return true;
509}
510template <typename CONVERTER>
511inline
512const date &
513calendar_impl<CONVERTER>::get_first_date( ) const
514{
515 return CONVERTER::first_date;
516}
517
518template <typename CONVERTER>
519inline
520calendar_impl<CONVERTER> &
521calendar_impl<CONVERTER>::Instance()
522{
523 static calendar_impl calendar;
524 return calendar;
525}
526template <typename CONVERTER>
527inline
528date_int_type
529calendar_impl<CONVERTER>::operator()( const date &d ) const
530{
531 return converter (d);
532}
533template <typename CONVERTER>
534inline
535date
536calendar_impl<CONVERTER>::operator()( date_int_type d ) const
537{
538 return converter (d);
539}
540template <typename CONVERTER>
541inline
542date_period
543calendar_impl<CONVERTER>::get_date_period( date_int_type d ) const
544{
545 date end = converter (d);
546 date prev = converter( d -1 );
547 // return date_period( static_cast<tom::calendars::date>(prev + date_duration(1)),
548 // static_cast<tom::calendars::date>(end + date_duration(1)) );
549 return date_period( prev + date_duration(1), end + date_duration(1) );
550}
551template <typename CONVERTER>
552inline
553date_period
554calendar_impl<CONVERTER>::get_date_period( const date &d ) const
555{
556 date_int_type end_date_int = converter (d);
557 date end = converter ( end_date_int );
558 date prev = converter ( end_date_int -1 );
559 return date_period( prev + date_duration(1), end + date_duration(1) );
560}
561// the dates for each calendar were chosen to align
562// our date_ints for the calendar with those of FAME.
563// This was done to aid in migration from FAME.
564// These dates can easily be adjusted back to January
565// 1400, and extend until the year 10,000 without impacting
566// the behavior of the calendars
567//
568// NOTE: However, once data has been indexed to date_ints
569// using these dates, they must be reindexed if the
570// calendar base date is changed. Hence, the calendar
571// first date should be persisted for date_ints, series,
572// or databases, depending on the implementation.
573typedef calendar_impl< daily_converter<1850,1,1> > timestamp_calendar;
574typedef calendar_impl< daily_converter<1401,1,1> > ordinal_calendar;
575typedef calendar_impl< daily_converter<1850,1,1> > daily_calendar;
576typedef calendar_impl< business_converter<1850,1,1> > business_calendar;
577typedef calendar_impl< weekly_converter<1850,1,7> > weekly_monday_calendar;
578typedef calendar_impl< weekly_converter<1850,1,8> > weekly_tuesday_calendar;
579typedef calendar_impl< weekly_converter<1850,1,9> > weekly_wednesday_calendar;
580typedef calendar_impl< weekly_converter<1850,1,10> > weekly_thursday_calendar;
581typedef calendar_impl< weekly_converter<1850,1,11> > weekly_friday_calendar;
582typedef calendar_impl< weekly_converter<1850,1,12> > weekly_saturday_calendar;
583typedef calendar_impl< weekly_converter<1850,1,13> > weekly_sunday_calendar;
584typedef calendar_impl< month_converter<1850,1,31> > monthly_calendar;
585typedef calendar_impl< quarterly_converter<1850,4,30> > quarterly_october_calendar;
586typedef calendar_impl< quarterly_converter<1850,5,31> > quarterly_november_calendar;
587typedef calendar_impl< quarterly_converter<1850,3,31> > quarterly_december_calendar;
588typedef calendar_impl< semiannual_converter<1850,7,31> > semiannual_july_calendar;
589typedef calendar_impl< semiannual_converter<1850,8,31> > semiannual_august_calendar;
590typedef calendar_impl< semiannual_converter<1850,9,30> > semiannual_september_calendar;
591typedef calendar_impl< semiannual_converter<1850,10,31> > semiannual_october_calendar;
592typedef calendar_impl< semiannual_converter<1850,11,30> > semiannual_november_calendar;
593typedef calendar_impl< semiannual_converter<1850,6,30> > semiannual_december_calendar;
594typedef calendar_impl< annual_converter<1851,1,31> > annual_january_calendar;
595typedef calendar_impl< annual_converter<1851,2,28> > annual_february_calendar;
596typedef calendar_impl< annual_converter<1851,3,31> > annual_march_calendar;
597typedef calendar_impl< annual_converter<1851,4,30> > annual_april_calendar;
598typedef calendar_impl< annual_converter<1851,5,31> > annual_may_calendar;
599typedef calendar_impl< annual_converter<1851,6,30> > annual_june_calendar;
600typedef calendar_impl< annual_converter<1851,7,31> > annual_july_calendar;
601typedef calendar_impl< annual_converter<1851,8,31> > annual_august_calendar;
602typedef calendar_impl< annual_converter<1851,9,30> > annual_september_calendar;
603typedef calendar_impl< annual_converter<1851,10,31> > annual_october_calendar;
604typedef calendar_impl< annual_converter<1851,11,30> > annual_november_calendar;
605typedef calendar_impl< annual_converter<1850,12,31> > annual_december_calendar;
606
607// aliases for common DateIntervals
608typedef weekly_friday_calendar weekly_calendar;
609typedef quarterly_december_calendar quarterly_calendar;
610typedef semiannual_december_calendar semiannual_calendar;
611typedef annual_december_calendar annual_calendar;
612
613namespace { // anonymous namespace for helpers
614
615 // The following are helpers to map string names to calendar instances
616 // this is good for all kind of human interaction :)
617 template <typename COLLECTION_T>
618 COLLECTION_T *
619 populate_calendar_map( );
620
621 inline
622 const char *
623 lookup_name( const tom::calendars::calendar *cal )
624 {
625 typedef std::map< const tom::calendars::calendar *, const char *> map_t;
626 static std::unique_ptr<map_t> map( populate_calendar_map<map_t>() );
627 map_t::const_iterator it = map->find( cal );
628 if ( it != map->end() )
629 return it->second;
630 else
631 return "Unknown";
632 }
633 template <typename COLLECTION_T>
634 inline
635 COLLECTION_T *
636 populate_calendar_map( )
637 {
638 typedef typename COLLECTION_T::value_type value_type;
639 static value_type items[] = {
640 value_type( &ordinal_calendar::Instance(), "Ordinal" ),
641 value_type( &daily_calendar::Instance(), "Daily" ),
642 value_type( &business_calendar::Instance(), "Business" ),
643 value_type( &weekly_monday_calendar::Instance(), "Weekly(Mon)" ),
644 value_type( &weekly_tuesday_calendar::Instance(), "Weekly(Tue)" ),
645 value_type( &weekly_wednesday_calendar::Instance(), "Weekly(Wed)" ),
646 value_type( &weekly_thursday_calendar::Instance(), "Weekly(Thu)" ),
647 value_type( &weekly_friday_calendar::Instance(), "Weekly(Fri)" ),
648 value_type( &weekly_saturday_calendar::Instance(), "Weekly(Sat)" ),
649 value_type( &weekly_sunday_calendar::Instance(), "Weekly(Sun)" ),
650 value_type( &monthly_calendar::Instance(), "Monthly" ),
651 value_type( &quarterly_october_calendar::Instance(), "Quarterly(Oct)" ),
652 value_type( &quarterly_november_calendar::Instance(), "Quarterly(Nov)" ),
653 value_type( &quarterly_december_calendar::Instance(), "Quarterly(Dec)" ),
654 value_type( &semiannual_july_calendar::Instance(), "Semiannual(Jul)" ),
655 value_type( &semiannual_august_calendar::Instance(), "Semiannual(Aug)" ),
656 value_type( &semiannual_september_calendar::Instance(), "Semiannual(Sep)" ),
657 value_type( &semiannual_october_calendar::Instance(), "Semiannual(Oct)" ),
658 value_type( &semiannual_november_calendar::Instance(), "Semiannual(Nov)" ),
659 value_type( &semiannual_december_calendar::Instance(), "Semiannual(Dec)" ),
660 value_type( &annual_january_calendar::Instance(), "Annual(Jan)" ),
661 value_type( &annual_february_calendar::Instance(), "Annual(Feb)" ),
662 value_type( &annual_march_calendar::Instance(), "Annual(Mar)" ),
663 value_type( &annual_april_calendar::Instance(), "Annual(Apr)" ),
664 value_type( &annual_may_calendar::Instance(), "Annual(May)" ),
665 value_type( &annual_june_calendar::Instance(), "Annual(Jun)" ),
666 value_type( &annual_july_calendar::Instance(), "Annual(Jul)" ),
667 value_type( &annual_august_calendar::Instance(), "Annual(Aug)" ),
668 value_type( &annual_september_calendar::Instance(), "Annual(Sep)" ),
669 value_type( &annual_october_calendar::Instance(), "Annual(Oct)" ),
670 value_type( &annual_november_calendar::Instance(), "Annual(Nov)" ),
671 value_type( &annual_december_calendar::Instance(), "Annual(Dec)" )
672 };
673 COLLECTION_T *result = new COLLECTION_T( items, items +
674 ( sizeof(items) / sizeof( value_type ) ) );
675 return result;
676 }
677 } // end anonymous namespace
678
679 template <typename CONVERTER>
680 inline
681 const char *
682 calendar_impl<CONVERTER>::name() const
683 {
684 // this is a bogus function to lookup
685 // calendar instances and return a name
686 return lookup_name( this );
687 }
688
689 } // end calendars namespace
690} // end tom namespace
691
692#endif
693
Definition calendar.hpp:452
Definition calendar.hpp:120
Definition calendar.hpp:105
Definition calendar.hpp:47
Definition calendar.hpp:147
Definition calendar.hpp:64
Definition calendar.hpp:422
Definition calendar.hpp:236
Definition calendar.hpp:183
Definition calendar.hpp:212
Definition calendar.hpp:313
Definition calendar.hpp:342
Definition calendar.hpp:382
Definition calendar.hpp:98
Definition calendar.hpp:279