Create data structures for a calendar page view.

Dependents:   TimeInterface

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers CalendarPage.h Source File

CalendarPage.h

00001 
00002 
00003 #ifndef CALENDARPAGE_H
00004 #define CALENDARPAGE_H
00005 
00006 #include <mbed.h>
00007 
00008 #define CALENDAR_DATA_MAP_SIZE 37
00009 /// Creates a calendar for a specified Month and Year
00010 ///
00011 /// This class is a simple CalendarPage creator. For a specified
00012 /// Month and Year, it will create a DayMap, which is a
00013 /// simple array of entries that can be easily transformed
00014 /// into a traditional CalendarPage.
00015 ///
00016 /// This code was pieced together with various online code
00017 /// samples, none of which had any evidence of a coyright 
00018 /// statement.
00019 ///
00020 /// @code 
00021 /// CalendarPage c;
00022 /// c.Compute(3, 2018);
00023 /// for (int i=0; i<c.DayMapEntries(); i++) {
00024 ///     if (c.DayMap[i] == 0)
00025 ///         printf("%4s", "");
00026 ///     else
00027 ///         printf("%4d", c.DayMap[i]);
00028 /// }
00029 /// printf("\n");
00030 /// @endcode
00031 ///
00032 class CalendarPage {
00033 public:
00034     /// Constructor for the CalendarPage class
00035     ///
00036     /// For a single instance, the constructor may be provided
00037     /// with a Month and Year. For recurring usage, this is
00038     /// generally not done, and instead the Compute method 
00039     /// is called with the parameters.
00040     ///
00041     /// @code 
00042     /// CalendarPage c(3, 2018);
00043     /// for (int i=0; i<c.DayMapEntries(); i++) {
00044     ///     if (c.DayMap[i] == 0)
00045     ///         printf("%4s", "");
00046     ///     else
00047     ///         printf("%4d", c.DayMap[i]);
00048     /// }
00049     /// printf("\n");
00050     /// @endcode
00051     ///
00052     /// @param[in] Month is optional and defaults to 1 (January).
00053     /// @param[in] Year is optional and defaults to 2018.
00054     ///
00055     CalendarPage(uint8_t Month = 1, uint16_t Year = 2018);
00056 
00057     /// Compute the CalendarPage information, when recurring usage
00058     /// is needed.
00059     ///
00060     /// This API can be used when more than a single CalendarPage is
00061     /// needed. Alternately, if the constructor has no options, 
00062     /// this API is used to select the Month and Year.
00063     ///
00064     /// @note Erroneous parameters may cause unpredictable results.
00065     ///
00066     /// @code 
00067     /// CalendarPage c;
00068     /// c.Compute(3, 2018);
00069     /// for (int i=0; i<c.DayMapEntries(); i++) {
00070     ///     if (c.DayMap[i] == 0)
00071     ///         printf("%4s", "");
00072     ///     else
00073     ///         printf("%4d", c.DayMap[i]);
00074     /// }
00075     /// printf("\n");
00076     /// @endcode
00077     ///
00078     /// @param[in] Month defines the month of interest; e.g. 1 = January, ...
00079     /// @param[in] Year defines the year of interest; e.g. 2018
00080     /// @returns true if it computed the CalendarPage information.
00081     ///
00082     void Compute(uint8_t Month, uint16_t Year);
00083 
00084     /// The CalendarPage information, expressed as an accessible array.
00085     ///
00086     /// - There are DayMapEntries() in the Array index 0 to n-1.
00087     /// - Each entry has either 0, or the day number in it.
00088     ///
00089     /// The information format is best represented in the following
00090     /// visual.
00091     /// @verbatim
00092     ///  DayMap[] array indices   |    DayMap populated
00093     ///   0  1  2  3  4  5  6     |     0  0  0  0  0  0  1
00094     ///   7  8  9 10 11 12 13     |     2  3  4  5  6  7  8
00095     ///  14 15 16 17 18 19 20     |     9 10 11 12 13 14 15
00096     ///  21 22 23 24 25 26 27     |    16 17 18 19 20 21 22
00097     ///  28 29 30 31 32 33 34     |    23 24 25 26 27 28 29
00098     ///  35 36                    |    30 31
00099     /// @endverbatim
00100     ///
00101     uint8_t DayMap[CALENDAR_DATA_MAP_SIZE];
00102 
00103     /// Get the number of entries in the DayMap, to limit iterators.
00104     /// 
00105     int DayMapEntries() {
00106         return CALENDAR_DATA_MAP_SIZE;
00107     }
00108 private:
00109     int firstday;
00110     uint8_t month;
00111     uint16_t year;
00112     bool verbose;
00113 };
00114 
00115 
00116 
00117 
00118 #endif // CALENDARPAGE_H