DISPLACE  1.0
A spatial model of fisheries to help sustainable fishing and maritime spatial planning
calendar.h
Go to the documentation of this file.
1 // --------------------------------------------------------------------------
2 // DISPLACE: DYNAMIC INDIVIDUAL VESSEL-BASED SPATIAL PLANNING
3 // AND EFFORT DISPLACEMENT
4 // Copyright (c) 2012-2019 Francois Bastardie <fba@aqua.dtu.dk>
5 
6 // This program is free software; you can redistribute it and/or modify
7 // it under the terms of the GNU General Public License as published by
8 // the Free Software Foundation; either version 2 of the License, or
9 // (at your option) any later version.
10 
11 // This program is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
15 
16 // You should have received a copy of the GNU General Public License along
17 // with this program; if not, write to the Free Software Foundation, Inc.,
18 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19 // --------------------------------------------------------------------------
20 
21 /* --------------------------------------------------------------------------
22  * DISPLACE: DYNAMIC INDIVIDUAL VESSEL-BASED SPATIAL PLANNING
23  * AND EFFORT DISPLACEMENT
24  * Copyright (c) 2012, 2013, 2014 Francois Bastardie <fba@aqua.dtu.dk>
25  *
26  * This program is free software; you can redistribute it and/or modify
27  * it under the terms of the GNU General Public License as published by
28  * the Free Software Foundation; either version 2 of the License, or
29  * (at your option) any later version.
30  *
31  * This program is distributed in the hope that it will be useful,
32  * but WITHOUT ANY WARRANTY; without even the implied warranty of
33  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
34  * GNU General Public License for more details.
35  *
36  * You should have received a copy of the GNU General Public License along
37  * with this program; if not, write to the Free Software Foundation, Inc.,
38  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
39  * --------------------------------------------------------------------------
40  */
41 #ifndef CALENDAR_H
42 #define CALENDAR_H
43 
44 #include <QString>
45 #include <QMap>
46 #include <memory>
47 
48 
50 
51 class Calendar
52 {
53 public:
54  Calendar();
55 
56  bool isMonth(int tstep) const {
57  return mMonths.contains(tstep);
58  }
59  int getMonth (int tstep) const {
60  return mMonths.lowerBound(tstep).value();
61  }
62 
63  bool isSemester(int tstep) const {
64  return mSemesters.contains(tstep);
65  }
66  int getSemester(int tstep) const {
67  return mSemesters.lowerBound(tstep).value();
68  }
69 
70  bool isQuarted(int tstep) const {
71  return mQuarters.contains(tstep);
72  }
73  int getQuarter (int tstep) const {
74  return mQuarters.lowerBound(tstep).value();
75  }
76 
77  bool isYear(int tstep) const {
78  return mYears.contains(tstep);
79  }
80  int getYear(int tstep) const {
81  return mYears.lowerBound(tstep).value();
82  }
83 
84  static Calendar *load(QString basepath, QString name);
85  static Calendar *build (std::shared_ptr<SQLiteOutputStorage> db);
86  static QString dayToString (int day) {
87  if (day < 0 || day > 6)
88  return "?";
89  return days[day];
90  }
91 
92 private:
93  QMap<int, int> mMonths;
94  QMap<int, int> mQuarters;
95  QMap<int, int> mSemesters;
96  QMap<int, int> mYears;
97 
98  static const QString days[];
99  static const QString months[];
100 };
101 
102 #endif // CALENDAR_H
int getMonth(int tstep) const
Definition: calendar.h:59
bool isSemester(int tstep) const
Definition: calendar.h:63
static Calendar * build(std::shared_ptr< SQLiteOutputStorage > db)
Definition: calendar.cpp:69
int tstep
Definition: main.cpp:205
int getYear(int tstep) const
Definition: calendar.h:80
static QString dayToString(int day)
Definition: calendar.h:86
Definition: calendar.h:51
Calendar()
Definition: calendar.cpp:37
bool isYear(int tstep) const
Definition: calendar.h:77
int getSemester(int tstep) const
Definition: calendar.h:66
Definition: sqliteoutputstorage.h:37
static Calendar * load(QString basepath, QString name)
Definition: calendar.cpp:41
bool isMonth(int tstep) const
Definition: calendar.h:56
bool isQuarted(int tstep) const
Definition: calendar.h:70
int getQuarter(int tstep) const
Definition: calendar.h:73