ALMaSS Rabbit ODdox  1.00
The rabbit model description following ODdox protocol
Public Member Functions | Private Attributes | Static Private Attributes | List of all members
Calendar Class Reference

#include <calendar.h>

Public Member Functions

void Reset (void)
 
bool TickMinute (void)
 
bool TickMinute10 (void)
 
bool TickHour (void)
 
void Tick (void)
 
long Date (void)
 
int DayInYear (void)
 
long OldDays (void)
 
long GlobalDate (int a_day, int a_month, int a_year)
 
int DayLength (void)
 
int DayLength (int a_day_in_year)
 
int GetFirstYear (void)
 
int GetLastYear (void)
 
int GetYear (void)
 
int GetYearNumber (void)
 
int GetMonth (void)
 
int GetMinute (void)
 
int GetHour (void)
 
int GetDayInMonth (void)
 
double GetDaylightProportion (void)
 
bool JanFirst (void)
 
bool MarchFirst (void)
 
void SetFirstYear (int a_year)
 
void SetLastYear (int a_year)
 
bool ValidDate (int a_day, int a_month)
 
int DayInYear (int a_day, int a_month)
 
 Calendar (void)
 

Private Attributes

long m_date
 
long m_olddays
 
int m_firstyear
 
int m_lastyear
 
int m_day_in_month
 
int m_day_in_year
 
int m_month
 
int m_year
 
int m_simulationyear
 
int m_todayslength
 
double m_daylightproportion
 
int m_minutes
 
int m_hours
 
bool m_janfirst
 
bool m_marchfirst
 

Static Private Attributes

static int m_daylength []
 The length of the day between sun up and sun down im minutes (DK - Jutland) More...
 

Detailed Description

Definition at line 38 of file calendar.h.

Constructor & Destructor Documentation

Calendar::Calendar ( void  )

Definition at line 55 of file calendar.cpp.

References Reset().

56 {
57  Reset();
58 }
void Reset(void)
Definition: calendar.cpp:40

Member Function Documentation

long Calendar::Date ( void  )
inline
int Calendar::DayInYear ( void  )
inline
int Calendar::DayInYear ( int  a_day,
int  a_month 
)

Definition at line 96 of file calendar.cpp.

97 {
98  const int m_monthsum[12] = {
99  0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334 };
100 
101  return m_monthsum[ a_month - 1 ] + a_day - 1;
102 }
int Calendar::DayLength ( void  )
inline

Definition at line 63 of file calendar.h.

Referenced by Landscape::SupplyDaylength().

63 { return m_todayslength; }
int m_todayslength
Definition: calendar.h:95
int Calendar::DayLength ( int  a_day_in_year)

Definition at line 67 of file calendar.cpp.

References g_msg, m_daylength, MapErrorMsg::Warn(), and WARN_BUG.

68 {
69  if ( a_day_in_year<0 || a_day_in_year>364 ) {
70  g_msg->Warn( WARN_BUG, "Calendar::DayLength(): Day outside a year!",
71  "" );
72  exit(1);
73  }
74  return m_daylength[ a_day_in_year ];
75 }
static int m_daylength[]
The length of the day between sun up and sun down im minutes (DK - Jutland)
Definition: calendar.h:102
class MapErrorMsg * g_msg
Definition: maperrormsg.cpp:38
void Warn(MapErrorState a_level, std::string a_msg1, std::string a_msg2)
Definition: maperrormsg.cpp:56
int Calendar::GetDayInMonth ( void  )
inline

Definition at line 72 of file calendar.h.

Referenced by Landscape::SupplyDayInMonth().

72 { return m_day_in_month; }
int m_day_in_month
Definition: calendar.h:90
double Calendar::GetDaylightProportion ( void  )
inline

Definition at line 73 of file calendar.h.

Referenced by Landscape::SupplyDaylightProp(), and Landscape::SupplyNightProp().

73 { return m_daylightproportion; }
double m_daylightproportion
Definition: calendar.h:96
int Calendar::GetFirstYear ( void  )
inline

Definition at line 65 of file calendar.h.

65 { return m_firstyear; }
int m_firstyear
Definition: calendar.h:88
int Calendar::GetHour ( void  )
inline

Definition at line 71 of file calendar.h.

Referenced by LargeRoad::GetTrafficLoad(), SmallRoad::GetTrafficLoad(), and Landscape::SupplyHour().

71 { return m_hours; }
int m_hours
Definition: calendar.h:98
int Calendar::GetLastYear ( void  )
inline

Definition at line 66 of file calendar.h.

Referenced by Weather::Weather().

66 { return m_lastyear; }
int m_lastyear
Definition: calendar.h:89
int Calendar::GetMinute ( void  )
inline

Definition at line 70 of file calendar.h.

Referenced by Landscape::SupplyMinute().

70 { return m_minutes; }
int m_minutes
Definition: calendar.h:97
int Calendar::GetMonth ( void  )
inline
int Calendar::GetYear ( void  )
inline

Definition at line 67 of file calendar.h.

Referenced by Landscape::SupplyYear().

67 { return m_year; }
int m_year
Definition: calendar.h:93
int Calendar::GetYearNumber ( void  )
inline
long Calendar::GlobalDate ( int  a_day,
int  a_month,
int  a_year 
)

Definition at line 61 of file calendar.cpp.

References DayInYear(), and m_olddays.

62 {
63  return m_olddays + DayInYear( a_day, a_month) + a_year*365;
64 }
long m_olddays
Definition: calendar.h:87
int DayInYear(void)
Definition: calendar.h:58
bool Calendar::JanFirst ( void  )
inline
bool Calendar::MarchFirst ( void  )
inline

Definition at line 75 of file calendar.h.

Referenced by Landscape::Tick().

75 { return m_marchfirst; }
bool m_marchfirst
Definition: calendar.h:100
long Calendar::OldDays ( void  )
inline

Definition at line 60 of file calendar.h.

Referenced by Landscape::DumpMapInfoByArea().

60 { return m_olddays; }
long m_olddays
Definition: calendar.h:87
void Calendar::Reset ( void  )

Definition at line 40 of file calendar.cpp.

References m_date, m_day_in_month, m_day_in_year, m_firstyear, m_hours, m_janfirst, m_marchfirst, m_minutes, m_month, m_olddays, m_simulationyear, and m_year.

Referenced by Calendar(), Landscape::Landscape(), and Weather::Weather().

41 {
42  m_date = 0;
43  m_olddays = 0;
44  m_day_in_month = 1;
45  m_minutes = 0;
46  m_hours = 0;
47  m_day_in_year = 0; // [0..364]
48  m_month = 0; // [0..11]
50  m_simulationyear = 0;
51  m_janfirst = true;
52  m_marchfirst = false;
53 }
int m_hours
Definition: calendar.h:98
long m_olddays
Definition: calendar.h:87
int m_firstyear
Definition: calendar.h:88
int m_day_in_month
Definition: calendar.h:90
long m_date
Definition: calendar.h:86
int m_year
Definition: calendar.h:93
bool m_janfirst
Definition: calendar.h:99
int m_day_in_year
Definition: calendar.h:91
bool m_marchfirst
Definition: calendar.h:100
int m_minutes
Definition: calendar.h:97
int m_month
Definition: calendar.h:92
int m_simulationyear
Definition: calendar.h:94
void Calendar::SetFirstYear ( int  a_year)
inline

Definition at line 76 of file calendar.h.

Referenced by Weather::Weather().

76 { m_firstyear = a_year; }
int m_firstyear
Definition: calendar.h:88
void Calendar::SetLastYear ( int  a_year)
inline

Definition at line 77 of file calendar.h.

Referenced by Weather::Weather().

77 { m_lastyear = a_year; }
int m_lastyear
Definition: calendar.h:89
void Calendar::Tick ( void  )

Definition at line 141 of file calendar.cpp.

References m_date, m_day_in_month, m_day_in_year, m_daylength, m_daylightproportion, m_hours, m_janfirst, m_marchfirst, m_minutes, m_month, m_olddays, m_simulationyear, m_todayslength, and m_year.

Referenced by Landscape::Tick().

142 {
143  const int m_monthlength[12] = {
144  31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
145  const int m_maxmonth = 11;
146 
147  m_minutes = 0;
148  m_hours = 0;
149  m_date++;
150  m_day_in_year++;
151  m_day_in_month++;
152  m_janfirst = false;
153  m_marchfirst = false;
154 
155  if ( m_day_in_month > m_monthlength[ m_month ])
156  {
157  m_day_in_month = 1;
158  m_month++;
159  if ( m_month == 2 )
160  // March 1st.
161  m_marchfirst = true;
162  }
163 
164  if ( m_month > m_maxmonth )
165  {
166  m_month = 0;
167  m_year++;
169  m_olddays += 365;
170  m_janfirst = true;
171  m_day_in_year = 0;
172  }
175 }
int m_hours
Definition: calendar.h:98
static int m_daylength[]
The length of the day between sun up and sun down im minutes (DK - Jutland)
Definition: calendar.h:102
long m_olddays
Definition: calendar.h:87
int m_day_in_month
Definition: calendar.h:90
int m_todayslength
Definition: calendar.h:95
long m_date
Definition: calendar.h:86
double m_daylightproportion
Definition: calendar.h:96
int m_year
Definition: calendar.h:93
bool m_janfirst
Definition: calendar.h:99
int m_day_in_year
Definition: calendar.h:91
bool m_marchfirst
Definition: calendar.h:100
int m_minutes
Definition: calendar.h:97
int m_month
Definition: calendar.h:92
int m_simulationyear
Definition: calendar.h:94
bool Calendar::TickHour ( void  )

Definition at line 128 of file calendar.cpp.

References m_hours, and m_minutes.

129 {
130  bool dotick = false;
131 
132  if ( ++m_hours > 23 ) {
133  m_minutes = 0;
134  m_hours = 0;
135  dotick = true;
136  }
137  return dotick;
138 }
int m_hours
Definition: calendar.h:98
int m_minutes
Definition: calendar.h:97
bool Calendar::TickMinute ( void  )

Definition at line 106 of file calendar.cpp.

References m_minutes.

107 {
108  bool dotick = false;
109 
110  if (m_minutes++ > 59) {
111  m_minutes = 0;
112  dotick = true;
113  }
114  return dotick;
115 }
int m_minutes
Definition: calendar.h:97
bool Calendar::TickMinute10 ( void  )

Definition at line 117 of file calendar.cpp.

References m_minutes.

118 {
119  bool dotick = false;
120  m_minutes += 10;
121  if (m_minutes > 59) {
122  m_minutes = 0;
123  dotick = true;
124  }
125  return dotick;
126 }
int m_minutes
Definition: calendar.h:97
bool Calendar::ValidDate ( int  a_day,
int  a_month 
)

Definition at line 79 of file calendar.cpp.

80 {
81  const int m_monthlength[12] = {
82  31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
83 
84  if ( a_month < 1 ||
85  a_month > 12 ||
86  a_day < 1 ||
87  a_day > m_monthlength[ a_month - 1 ] ) {
88  return false;
89  } else {
90  return true;
91  }
92 }

Member Data Documentation

long Calendar::m_date
private

Definition at line 86 of file calendar.h.

Referenced by Reset(), and Tick().

int Calendar::m_day_in_month
private

Definition at line 90 of file calendar.h.

Referenced by Reset(), and Tick().

int Calendar::m_day_in_year
private

Definition at line 91 of file calendar.h.

Referenced by Reset(), and Tick().

int Calendar::m_daylength
staticprivate

The length of the day between sun up and sun down im minutes (DK - Jutland)

Definition at line 102 of file calendar.h.

Referenced by DayLength(), and Tick().

double Calendar::m_daylightproportion
private

Definition at line 96 of file calendar.h.

Referenced by Tick().

int Calendar::m_firstyear
private

Definition at line 88 of file calendar.h.

Referenced by Reset().

int Calendar::m_hours
private

Definition at line 98 of file calendar.h.

Referenced by Reset(), Tick(), and TickHour().

bool Calendar::m_janfirst
private

Definition at line 99 of file calendar.h.

Referenced by Reset(), and Tick().

int Calendar::m_lastyear
private

Definition at line 89 of file calendar.h.

bool Calendar::m_marchfirst
private

Definition at line 100 of file calendar.h.

Referenced by Reset(), and Tick().

int Calendar::m_minutes
private

Definition at line 97 of file calendar.h.

Referenced by Reset(), Tick(), TickHour(), TickMinute(), and TickMinute10().

int Calendar::m_month
private

Definition at line 92 of file calendar.h.

Referenced by Reset(), and Tick().

long Calendar::m_olddays
private

Definition at line 87 of file calendar.h.

Referenced by GlobalDate(), Reset(), and Tick().

int Calendar::m_simulationyear
private

Definition at line 94 of file calendar.h.

Referenced by Reset(), and Tick().

int Calendar::m_todayslength
private

Definition at line 95 of file calendar.h.

Referenced by Tick().

int Calendar::m_year
private

Definition at line 93 of file calendar.h.

Referenced by Reset(), and Tick().


The documentation for this class was generated from the following files: