EHM DAL 0.2.5
Data abstraction layer for Eastside Hockey Manager
Loading...
Searching...
No Matches
dates_generator.h
1#pragma once
2
3// Qt headers
4#include <QDate>
5
6// --- Schedule template dates generator --- //
7namespace ehm_dal::tools::schedule_template_generator {
12{
13public:
14 DatesGenerator(const QDate &start_date, const QDate &end_date);
15
16 // Dates
17 QDate date(const qint32 index);
18
19 // Day priorities (Mon -> Sun)
20 void setDayPriorities(const qint32 mon,
21 const qint32 tue,
22 const qint32 wed,
23 const qint32 thu,
24 const qint32 fri,
25 const qint32 sat,
26 const qint32 sun);
27 void setDayPriorities(const std::vector<qint32> &day_priorities);
28
29 // Excluded date range (e.g. Olympics)
30 void setExcludedDateRange(const QDate &excluded_start_date, const QDate &excluded_end_date);
31
32 // Generator
33 bool generate(const qint32 target_dates_count);
34
35 // Get data
36 inline qint32 count() const { return static_cast<qint32>(schedule_dates_.size()); }
37
38private:
39 // Dates
40 std::vector<QDate> schedule_dates_;
41
42 // Date cache
43 std::vector<std::vector<QDate>> date_cache_;
44 void populateCache();
45 void populateCache(std::vector<QDate> &cache, Qt::DayOfWeek day);
46 void tidyUpCache(std::vector<QDate> &cache);
47
48 // Date picking
49 void addDate(std::vector<QDate> &cache, const qint32 index);
50 bool isValidDate(const QDate &date) const;
51 void pickDates(std::vector<QDate> &cache, const qint32 step);
52
53 // Date range
54 qint32 target_dates_count_{0};
55 QDate start_date_;
56 QDate end_date_;
57 QDate excluded_start_date_; // Excluded date period (e.g. during the Olympics)
58 QDate excluded_end_date_;
59
60 inline bool areMoreDatesRequired() const { return count() < target_dates_count_; }
61 inline bool hasSufficientDates() const { return !areMoreDatesRequired(); }
62
63 // Days
64 enum ENUM_DAYS {
65 MONDAY,
66 TUESDAY,
67 WEDNESDAY,
68 THURSDAY,
69 FRIDAY,
70 SATURDAY,
71 SUNDAY,
72 DAY_COUNT,
73 DAYS_IN_A_WEEK = DAY_COUNT
74 };
75
76 inline qint32 dayToIndex(const Qt::DayOfWeek day) const { return static_cast<qint32>(day) - 1; }
77 inline Qt::DayOfWeek indexToDay(const ENUM_DAYS index) const
78 {
79 return static_cast<Qt::DayOfWeek>(index + 1);
80 }
81
82 // Day priorities (Mon -> Sun)
83 std::vector<std::pair<ENUM_DAYS, qint32>> day_priority_list_;
84
85 // Generator
86 bool generateDates(const auto &step_calculation_lambda);
87};
88} // namespace ehm_dal::tools::schedule_template_generator
The DatesGenerator class generates dates for a schedule template.
Definition: dates_generator.h:12