OpenTTD Source 20250905-master-g122023be8d
history_type.hpp
Go to the documentation of this file.
1/*
2 * This file is part of OpenTTD.
3 * OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
4 * OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
5 * See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>.
6 */
7
10#ifndef HISTORY_TYPE_HPP
11#define HISTORY_TYPE_HPP
12
14 const HistoryRange *hr;
15 const uint8_t periods;
16 const uint8_t records;
17 const uint8_t first;
18 const uint8_t last;
19 const uint8_t division;
20 const uint8_t total_division;
21
22 explicit constexpr HistoryRange(uint8_t periods) :
23 hr(nullptr), periods(periods), records(this->periods), first(1), last(this->first + this->records), division(1), total_division(1)
24 {
25 }
26
27 constexpr HistoryRange(const HistoryRange &hr, uint8_t division, uint8_t periods) :
28 hr(&hr), periods(periods), records(this->periods - ((hr.periods / division) - 1)), first(hr.last), last(this->first + this->records),
30 {
31 }
32};
33
34static constexpr uint8_t HISTORY_PERIODS = 24;
35static constexpr HistoryRange HISTORY_MONTH{HISTORY_PERIODS};
36static constexpr HistoryRange HISTORY_QUARTER{HISTORY_MONTH, 3, HISTORY_PERIODS};
37static constexpr HistoryRange HISTORY_YEAR{HISTORY_QUARTER, 4, HISTORY_PERIODS};
38
40static constexpr uint8_t HISTORY_MAX_DIVISION = std::max({HISTORY_MONTH.division, HISTORY_QUARTER.division, HISTORY_YEAR.division});
41
43static constexpr uint8_t HISTORY_RECORDS = HISTORY_YEAR.last;
44
45static constexpr uint8_t THIS_MONTH = 0;
46static constexpr uint8_t LAST_MONTH = 1;
47
52template <typename T>
53using HistoryData = std::array<T, HISTORY_RECORDS>;
54
56using ValidHistoryMask = uint64_t;
57
58#endif /* HISTORY_TYPE_HPP */
std::array< T, HISTORY_RECORDS > HistoryData
Container type for storing history data.
static constexpr uint8_t HISTORY_RECORDS
Total number of records require for all history data.
uint64_t ValidHistoryMask
Mask of valid history records.
static constexpr uint8_t HISTORY_MAX_DIVISION
Maximum number of divisions from previous history range.
const uint8_t last
Index of last element in history data.
const uint8_t total_division
Number of divisions of the initial history range.
const uint8_t division
Number of divisions of the previous history range.
const uint8_t records
Number of records needed for this range.
const uint8_t first
Index of first element in history data.
const uint8_t periods
Number of periods for this range.