Stride Reference Manual  1.0
Calendar.h
Go to the documentation of this file.
1 #pragma once
2 /*
3  * This is free software: you can redistribute it and/or modify it
4  * under the terms of the GNU General Public License as published by
5  * the Free Software Foundation, either version 3 of the License, or
6  * any later version.
7  * The software is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10  * GNU General Public License for more details.
11  * You should have received a copy of the GNU General Public License
12  * along with the software. If not, see <http://www.gnu.org/licenses/>.
13  *
14  * Copyright 2017, Willem L, Kuylen E, Stijven S & Broeckhove J
15  */
16 
22 #include "boost/date_time/gregorian/gregorian.hpp"
23 #include <boost/property_tree/ptree.hpp>
24 
25 #include <algorithm>
26 #include <cstdlib>
27 #include <memory>
28 #include <vector>
29 
30 namespace stride {
31 
36 class Calendar {
37 public:
39  Calendar(const boost::property_tree::ptree& pt_config);
40 
42  void advanceDay();
43 
45  std::size_t getDay() const { return m_date.day(); }
46 
48  std::size_t getDayOfTheWeek() const { return m_date.day_of_week(); }
49 
51  std::size_t getMonth() const { return m_date.month(); }
52 
54  std::size_t getSimulationDay() const { return m_day; }
55 
57  std::size_t getYear() const { return m_date.year(); }
58 
60  bool isHoliday() const { return (std::find(m_holidays.begin(), m_holidays.end(), m_date) != m_holidays.end()); }
61 
63  bool isSchoolHoliday() const {
64  return (std::find(m_school_holidays.begin(), m_school_holidays.end(), m_date) != m_school_holidays.end());
65  }
66 
68  bool isWeekend() const { return (getDayOfTheWeek() == 6 || getDayOfTheWeek() == 0); }
69 
70 private:
72  void initializeHolidays(const boost::property_tree::ptree& pt_config);
73 
74 private:
75  std::size_t m_day;
76  boost::gregorian::date m_date;
77  std::vector<boost::gregorian::date> m_holidays;
78  std::vector<boost::gregorian::date> m_school_holidays;
79 
80 private:
81  friend class Hdf5Loader;
82 };
83 
84 }
85 
std::size_t getMonth() const
Get the current month.
Definition: Calendar.h:51
std::vector< boost::gregorian::date > m_school_holidays
Vector of school holidays.
Definition: Calendar.h:78
std::vector< boost::gregorian::date > m_holidays
Vector of general holidays.
Definition: Calendar.h:77
std::size_t getDay() const
Get the current day of the month.
Definition: Calendar.h:45
Time Dependent Person DataType.
Definition: NoBehaviour.h:17
void initializeHolidays(const boost::property_tree::ptree &pt_config)
Definition: Calendar.cpp:48
Class that keeps track of the &#39;state&#39; of simulated world.
Definition: Calendar.h:36
void advanceDay()
Advance the internal calendar by one day.
Definition: Calendar.cpp:43
bool isSchoolHoliday() const
Check if it&#39;s a school holiday.
Definition: Calendar.h:63
Calendar(const boost::property_tree::ptree &pt_config)
Constructor.
Definition: Calendar.cpp:33
bool isWeekend() const
Check if it&#39;s the weekend.
Definition: Calendar.h:68
std::size_t getDayOfTheWeek() const
Get the current day of the week (0 (Sunday), ..., 6 (Saturday))
Definition: Calendar.h:48
std::size_t m_day
The current simulation day.
Definition: Calendar.h:75
std::size_t getYear() const
Get the current year.
Definition: Calendar.h:57
std::size_t getSimulationDay() const
Get the current day of the simulation.
Definition: Calendar.h:54
bool isHoliday() const
Check if it&#39;s a holiday.
Definition: Calendar.h:60
boost::gregorian::date m_date
The current simulated day.
Definition: Calendar.h:76