debian: added giffgaff chatscripts
[barry.git] / src / r_recur_base.h
blob62b971e2755bd3dbf2c530a855d80f68c6f757a1
1 ///
2 /// \file r_recur_base.h
3 /// Base class for recurring calendar event data.
4 ///
6 /*
7 Copyright (C) 2005-2013, Net Direct Inc. (http://www.netdirect.ca/)
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 2 of the License, or
12 (at your option) any later version.
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
18 See the GNU General Public License in the COPYING file at the
19 root directory of this project for more details.
22 #ifndef __BARRY_RECORD_RECUR_BASE_H__
23 #define __BARRY_RECORD_RECUR_BASE_H__
25 #include "dll.h"
26 #include "record.h"
27 #include <iosfwd>
28 #include <string>
29 #include <vector>
30 #include <map>
31 #include <stdint.h>
33 namespace Barry {
35 // forward declarations
36 class IConverter;
39 // NOTE: All classes here must be container-safe! Perhaps add sorting
40 // operators in the future.
43 class BXEXPORT RecurBase
45 public:
46 ///
47 /// Recurring data
48 ///
49 /// Note: interval can be used on all of these recurring types to
50 /// make it happen "every other time" or more, etc.
51 ///
52 enum RecurringCodeType {
53 Day = 1, //< eg. every day
54 //< set: nothing
55 MonthByDate = 3, //< eg. every month on the 12th
56 //< set: DayOfMonth
57 MonthByDay = 4, //< eg. every month on 3rd Wed
58 //< set: DayOfWeek and WeekOfMonth
59 YearByDate = 5, //< eg. every year on March 5
60 //< set: DayOfMonth and MonthOfYear
61 YearByDay = 6, //< eg. every year on 3rd Wed of Jan
62 //< set: DayOfWeek, WeekOfMonth, and
63 //< MonthOfYear
64 Week = 12 //< eg. every week on Mon and Fri
65 //< set: WeekDays
69 bool Recurring;
70 RecurringCodeType RecurringType;
71 uint16_t Interval; // must be >= 1
72 Barry::TimeT RecurringEndTime; // only pertains if Recurring is true
73 // sets the date and time when
74 // recurrence of this appointment
75 // should no longer occur
76 // If a perpetual appointment, this
77 // is 0xFFFFFFFF in the low level data
78 // Instead, set the following flag.
79 bool Perpetual; // if true, this will always recur
81 uint16_t // recurring details, depending on type
82 DayOfWeek, // 0-6
83 WeekOfMonth, // 1-5
84 DayOfMonth, // 1-31
85 MonthOfYear; // 1-12
86 uint8_t WeekDays; // bitmask, bit 0 = sunday
88 // FIXME - put these somewhere usable by both C and C++
89 #define CAL_WD_SUN 0x01
90 #define CAL_WD_MON 0x02
91 #define CAL_WD_TUE 0x04
92 #define CAL_WD_WED 0x08
93 #define CAL_WD_THU 0x10
94 #define CAL_WD_FRI 0x20
95 #define CAL_WD_SAT 0x40
97 protected:
98 void ParseRecurrenceData(const void *data);
99 static unsigned char WeekDayProto2Rec(uint8_t raw_field);
100 static uint8_t WeekDayRec2Proto(unsigned char weekdays);
102 protected:
103 RecurBase();
104 virtual ~RecurBase();
106 public:
107 void Validate() const;
109 // return true if parse, false if not (for example, if type not
110 // recognized)
111 bool ParseField(uint8_t type, const unsigned char *data, size_t size,
112 const IConverter *ic = 0);
113 void BuildRecurrenceData(time_t StartTime, void *data) const;
115 uint8_t RecurringFieldType() const;
117 void Clear();
119 void Dump(std::ostream &os) const;
122 BXEXPORT inline std::ostream& operator<<(std::ostream &os, const RecurBase &msg) {
123 msg.Dump(os);
124 return os;
127 } // namespace Barry
129 #endif