OpenTTD Source 20250911-master-gfe9093df96
history_func.hpp File Reference

Functions for storing historical data. More...

Go to the source code of this file.

Functions

void UpdateValidHistory (ValidHistoryMask &valid_history, const HistoryRange &hr, uint cur_month)
 Update mask of valid records for a historical data.
 
bool IsValidHistory (ValidHistoryMask valid_history, const HistoryRange &hr, uint age)
 Test if history data is valid, without extracting data.
 
template<typename T >
SumHistory (typename std::span< const T > history)
 Sum history data elements.
 
template<typename T >
void RotateHistory (HistoryData< T > &history, ValidHistoryMask valid_history, const HistoryRange &hr, uint cur_month)
 Rotate historical data.
 
template<typename T , typename Taccrued >
GetAndResetAccumulatedAverage (Taccrued &total)
 Get an average value for the previous month, as reset for the next month.
 
template<typename T >
bool GetHistory (const HistoryData< T > &history, ValidHistoryMask valid_history, const HistoryRange &hr, uint age, T &result)
 Get historical data.
 
template<uint N, typename T , typename... Tfillers>
void FillFromHistory (const HistoryData< T > &history, ValidHistoryMask valid_history, const HistoryRange &hr, Tfillers &&... fillers)
 Fill some data with historical data.
 
template<uint N, typename T , typename... Tfillers>
void FillFromHistory (const HistoryData< T > *history, ValidHistoryMask valid_history, const HistoryRange &hr, Tfillers &&... fillers)
 Fill some data with optional historical data.
 

Detailed Description

Functions for storing historical data.

Definition in file history_func.hpp.

Function Documentation

◆ FillFromHistory() [1/2]

template<uint N, typename T , typename... Tfillers>
void FillFromHistory ( const HistoryData< T > &  history,
ValidHistoryMask  valid_history,
const HistoryRange hr,
Tfillers &&...  fillers 
)

Fill some data with historical data.

Parameters
historyHistorical data to fill from.
valid_historyMask of valid history records.
hrHistory range to fill with.
fillersFillers to fill with history data.

Definition at line 119 of file history_func.hpp.

References GetHistory().

◆ FillFromHistory() [2/2]

template<uint N, typename T , typename... Tfillers>
void FillFromHistory ( const HistoryData< T > *  history,
ValidHistoryMask  valid_history,
const HistoryRange hr,
Tfillers &&...  fillers 
)

Fill some data with optional historical data.

Parameters
historyHistorical data to fill from, or nullptr if not present.
valid_historyMask of valid history records.
hrHistory range to fill with.
fillersFillers to fill with history data.

Definition at line 139 of file history_func.hpp.

References IsValidHistory().

◆ GetAndResetAccumulatedAverage()

template<typename T , typename Taccrued >
T GetAndResetAccumulatedAverage ( Taccrued &  total)

Get an average value for the previous month, as reset for the next month.

Parameters
totalAccrued total to average. Will be reset to zero.
Returns
Average value for the month.

Definition at line 64 of file history_func.hpp.

References TimerGameEconomy::days_since_last_month.

◆ GetHistory()

template<typename T >
bool GetHistory ( const HistoryData< T > &  history,
ValidHistoryMask  valid_history,
const HistoryRange hr,
uint  age,
T &  result 
)

Get historical data.

Template Parameters
Ttype of history data element.
Parameters
historyHistory data to extract from.
valid_historyMask of valid history records.
hrHistory range to get.
ageAge of data to get.
cur_monthCurrent economy month.
[out]resultExtracted historical data.
Returns
True iff the data for this history range and age is valid.

Definition at line 83 of file history_func.hpp.

References HistoryRange::division, HistoryRange::first, GetHistory(), HasBit(), TimerGameEconomy::month, and HistoryRange::periods.

Referenced by FillFromHistory(), and GetHistory().

◆ IsValidHistory()

bool IsValidHistory ( ValidHistoryMask  valid_history,
const HistoryRange hr,
uint  age 
)

Test if history data is valid, without extracting data.

Parameters
valid_historyMask of valid history records.
hrHistory range to test.
ageAge of data to test.
Returns
True iff the data for history range and age is valid.

Definition at line 47 of file history.cpp.

References HistoryRange::division, HistoryRange::first, HasBit(), IsValidHistory(), TimerGameEconomy::month, and HistoryRange::periods.

Referenced by FillFromHistory(), and IsValidHistory().

◆ RotateHistory()

template<typename T >
void RotateHistory ( HistoryData< T > &  history,
ValidHistoryMask  valid_history,
const HistoryRange hr,
uint  cur_month 
)

Rotate historical data.

Note
Call only for the largest history range sub-division.
Template Parameters
Ttype of history data element.
Parameters
historyHistorical data to rotate.
valid_historyMask of valid history records.
hrHistory range to rotate..
cur_monthCurrent economy month.

Definition at line 41 of file history_func.hpp.

References HistoryRange::division, HistoryRange::first, HasBit(), HistoryRange::last, RotateHistory(), and HistoryRange::total_division.

Referenced by RotateHistory(), and UpdateIndustryStatistics().

◆ SumHistory()

template<typename T >
T SumHistory ( typename std::span< const T >  history)

Sum history data elements.

Note
The summation should prevent overflowing, and perform transformations relevant to the type of data.
Template Parameters
Ttype of history data element.
Parameters
historyHistory elements to sum.
Returns
Sum of history elements.

◆ UpdateValidHistory()

void UpdateValidHistory ( ValidHistoryMask valid_history,
const HistoryRange hr,
uint  cur_month 
)

Update mask of valid records for a historical data.

Note
Call only for the largest history range sub-division.
Parameters
[in,out]valid_historyValid history records.
hrHistory range to update mask for.
cur_monthCurrent economy month.

Definition at line 25 of file history.cpp.

References HistoryRange::division, HistoryRange::first, GB(), HasBit(), HistoryRange::last, HistoryRange::records, SB(), HistoryRange::total_division, and UpdateValidHistory().

Referenced by DoCreateNewIndustry(), UpdateIndustryStatistics(), and UpdateValidHistory().