Stride Reference Manual  - generated for commit 9643b11
Calendar.h
Go to the documentation of this file.
1 /*
2  * This is free software: you can redistribute it and/or modify it
3  * under the terms of the GNU General Public License as published by
4  * the Free Software Foundation, either version 3 of the License, or
5  * any later version.
6  * The software is distributed in the hope that it will be useful,
7  * but WITHOUT ANY WARRANTY; without even the implied warranty of
8  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
9  * GNU General Public License for more details.
10  * You should have received a copy of the GNU General Public License
11  * along with the software. If not, see <http://www.gnu.org/licenses/>.
12  *
13  * Copyright 2017, Kuylen E, Willem L, Broeckhove J
14  */
15 
21 #pragma once
22 
23 #include <boost/property_tree/ptree_fwd.hpp>
24 
25 #include <algorithm>
26 #include <cstdlib>
27 #include <memory>
28 #include <vector>
29 
30 #ifdef BOOST_FOUND
31 #include "boost/date_time/gregorian/gregorian.hpp"
32 #else
33 #include <date/date.h>
34 #endif
35 
36 namespace stride {
37 
42 class Calendar
43 {
44 public:
46  explicit Calendar(const boost::property_tree::ptree& configPt);
47 
49  void AdvanceDay();
50 
52  std::size_t GetDay() const;
53 
55  std::size_t GetDayOfTheWeek() const;
56 
58  std::size_t GetMonth() const;
59 
61  unsigned short int GetSimulationDay() const;
62 
64  std::size_t GetYear() const;
65 
67  bool IsHoliday() const { return (std::find(m_holidays.begin(), m_holidays.end(), m_date) != m_holidays.end()); }
68 
70  bool IsSchoolHoliday() const
71  {
72  return (std::find(m_school_holidays.begin(), m_school_holidays.end(), m_date) !=
73  m_school_holidays.end());
74  }
75 
77  bool IsWeekend() const { return (GetDayOfTheWeek() == 6 || GetDayOfTheWeek() == 0); }
78 
79 private:
81  void InitializeHolidays(const boost::property_tree::ptree& configPt);
82 
83 private:
84 #ifdef BOOST_FOUND
85  boost::gregorian::date m_date;
86  std::vector<boost::gregorian::date> m_holidays;
87  std::vector<boost::gregorian::date> m_school_holidays;
88 #else
89  date::year_month_day m_date;
90  std::vector<date::year_month_day> m_holidays;
91  std::vector<date::year_month_day> m_school_holidays;
92 #endif
93  unsigned short int m_day;
94 };
95 
96 } // namespace stride
Calendar(const boost::property_tree::ptree &configPt)
Constructor.
Definition: Calendar.cpp:107
void InitializeHolidays(const boost::property_tree::ptree &configPt)
Definition: Calendar.cpp:123
bool IsHoliday() const
Check if it&#39;s a holiday.
Definition: Calendar.h:67
bool IsWeekend() const
Check if it&#39;s the weekend.
Definition: Calendar.h:77
std::vector< date::year_month_day > m_school_holidays
Vector of school holidays.
Definition: Calendar.h:91
unsigned short int m_day
Current day since start of simulation.
Definition: Calendar.h:93
void AdvanceDay()
Advance the simulated calendar by one day.
Definition: Calendar.cpp:117
std::vector< date::year_month_day > m_holidays
Vector of general holidays.
Definition: Calendar.h:90
date::year_month_day m_date
Current simulated date.
Definition: Calendar.h:89
std::size_t GetDayOfTheWeek() const
Current day of the week (0 (Sunday), ..., 6 (Saturday)) in the simulated calendar.
Definition: Calendar.cpp:163
std::size_t GetYear() const
Current year in the simulated calendar.
Definition: Calendar.cpp:172
std::size_t GetDay() const
Current day of the month in the simulated calendar.
Definition: Calendar.cpp:161
Class that keeps track of the &#39;state&#39; of simulated world.
Definition: Calendar.h:42
bool IsSchoolHoliday() const
Check if it&#39;s a school holiday.
Definition: Calendar.h:70
unsigned short int GetSimulationDay() const
Current simulated day since the start of the simulation.
Definition: Calendar.cpp:170
Namespace for the simulator and related classes.
Definition: Calendar.cpp:28
std::size_t GetMonth() const
Current month in the simulated calendar.
Definition: Calendar.cpp:168