# r_recur_base.h

Go to the documentation of this file.

    00001 ///
    00002 /// \file       r_recur_base.h
    00003 ///             Base class for recurring calendar event data.
    00004 ///
    00005
    00006 /*
    00007     Copyright (C) 2005-2011, Net Direct Inc. (http://www.netdirect.ca/)
    00008
    00009     This program is free software; you can redistribute it and/or modify
    00010     it under the terms of the GNU General Public License as published by
    00011     the Free Software Foundation; either version 2 of the License, or
    00012     (at your option) any later version.
    00013
    00014     This program is distributed in the hope that it will be useful,
    00015     but WITHOUT ANY WARRANTY; without even the implied warranty of
    00016     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
    00017
    00018     See the GNU General Public License in the COPYING file at the
    00019     root directory of this project for more details.
    00020 */
    00021
    00022 #ifndef __BARRY_RECORD_RECUR_BASE_H__
    00023 #define __BARRY_RECORD_RECUR_BASE_H__
    00024
    00025 #include "dll.h"
    00026 #include "record.h"
    00027 #include <iosfwd>
    00028 #include <string>
    00029 #include <vector>
    00030 #include <map>
    00031 #include <stdint.h>
    00032
    00033 namespace Barry {
    00034
    00035 // forward declarations
    00036 class IConverter;
    00037
    00038 //
    00039 // NOTE:  All classes here must be container-safe!  Perhaps add sorting
    00040 //        operators in the future.
    00041 //
    00042
    00043 class BXEXPORT RecurBase
    00044 {
    00045 public:
    00046         ///
    00047         /// Recurring data
    00048         ///
    00049         /// Note: interval can be used on all of these recurring types to
    00050         ///       make it happen "every other time" or more, etc.
    00051         ///
    00052         enum RecurringCodeType {
    00053                 Day = 1,                //< eg. every day
    00054                                         //< set: nothing
    00055                 MonthByDate = 3,        //< eg. every month on the 12th
    00056                                         //< set: DayOfMonth
    00057                 MonthByDay = 4,         //< eg. every month on 3rd Wed
    00058                                         //< set: DayOfWeek and WeekOfMonth
    00059                 YearByDate = 5,         //< eg. every year on March 5
    00060                                         //< set: DayOfMonth and MonthOfYear
    00061                 YearByDay = 6,          //< eg. every year on 3rd Wed of Jan
    00062                                         //< set: DayOfWeek, WeekOfMonth, and
    00063                                         //<      MonthOfYear
    00064                 Week = 12               //< eg. every week on Mon and Fri
    00065                                         //< set: WeekDays
    00066         };
    00067
    00068
    00069         bool Recurring;
    00070         RecurringCodeType RecurringType;
    00071         unsigned short Interval;        // must be >= 1
    00072         time_t RecurringEndTime;        // only pertains if Recurring is true
    00073                                         // sets the date and time when
    00074                                         // recurrence of this appointment
    00075                                         // should no longer occur
    00076                                         // If a perpetual appointment, this
    00077                                         // is 0xFFFFFFFF in the low level data
    00078                                         // Instead, set the following flag.
    00079         bool Perpetual;                 // if true, this will always recur
    00080
    00081         unsigned short                  // recurring details, depending on type
    00082                 DayOfWeek,              // 0-6
    00083                 WeekOfMonth,            // 1-5
    00084                 DayOfMonth,             // 1-31
    00085                 MonthOfYear;            // 1-12
    00086         unsigned char WeekDays;         // bitmask, bit 0 = sunday
    00087
    00088 // FIXME - put these somewhere usable by both C and C++
    00089                 #define CAL_WD_SUN      0x01
    00090                 #define CAL_WD_MON      0x02
    00091                 #define CAL_WD_TUE      0x04
    00092                 #define CAL_WD_WED      0x08
    00093                 #define CAL_WD_THU      0x10
    00094                 #define CAL_WD_FRI      0x20
    00095                 #define CAL_WD_SAT      0x40
    00096
    00097 protected:
    00098         void ParseRecurrenceData(const void *data);
    00099         static unsigned char WeekDayProto2Rec(uint8_t raw_field);
    00100         static uint8_t WeekDayRec2Proto(unsigned char weekdays);
    00101
    00102 protected:
    00103         RecurBase();
    00104         virtual ~RecurBase();
    00105
    00106 public:
    00107         // return true if parse, false if not (for example, if type not
    00108         // recognized)
    00109         bool ParseField(uint8_t type, const unsigned char *data, size_t size,
    00110                 const IConverter *ic = 0);
    00111         void BuildRecurrenceData(time_t StartTime, void *data) const;
    00112
    00113         uint8_t RecurringFieldType() const;
    00114
    00115         void Clear();
    00116
    00117         void Dump(std::ostream &os) const;
    00118 };
    00119
    00120 BXEXPORT inline std::ostream& operator<<(std::ostream &os, const RecurBase &msg) {
    00121         msg.Dump(os);
    00122         return os;
    00123 }
    00124
    00125 } // namespace Barry
    00126
    00127 #endif
    00128