OpenTTD Source: TimeoutTimer< TTimerType > Class Template Reference

OpenTTD Source 14.1

Public Types | Public Member Functions | Data Fields | Private Member Functions | Private Attributes
TimeoutTimer< TTimerType > Class Template Reference

A timeout timer will fire once after the interval. More...

`#include <timer.h>`

Inheritance diagram for TimeoutTimer< TTimerType >:

## Public Types
using | TPeriod = typename TTimerType::TPeriod
using | TElapsed = typename TTimerType::TElapsed
Public Types inherited from BaseTimer< TTimerType >
using | TPeriod = typename TTimerType::TPeriod
using | TElapsed = typename TTimerType::TElapsed
using | TStorage = typename TTimerType::TStorage

## Public Member Functions
| TimeoutTimer (const TPeriod timeout, std::function< void()> callback, bool start=false)
| Create a new timeout timer. More...
void | Reset ()
| Reset the timer, so it will fire again after the timeout.
void | Reset (const TPeriod timeout)
| Reset the timer, so it will fire again after the timeout. More...
void | Abort ()
| Abort the timer so it doesn't fire if it hasn't yet.
bool | HasFired () const
| Check whether the timeout occurred. More...
Public Member Functions inherited from BaseTimer< TTimerType >
| BaseTimer (const TPeriod period)
| Create a new timer. More...
virtual | ~BaseTimer ()
| Delete the timer.

## Data Fields
bool | fired
| Whether the timeout has occurred.
Data Fields inherited from BaseTimer< TTimerType >
TPeriod | period
| The period of the timer.
TStorage | storage = {}
| The storage of the timer.

## Private Member Functions
void | Elapsed (TElapsed count) override
| Called by the timer manager to notify the timer that the given amount of time has elapsed. More...
void | Elapsed (TimerGameCalendar::TElapsed trigger)
void | Elapsed (TimerGameEconomy::TElapsed trigger)
void | Elapsed (TimerGameRealtime::TElapsed delta)
void | Elapsed (TimerGameTick::TElapsed delta)

## Private Attributes
std::function< void()> | callback

## Additional Inherited Members

## Detailed Description

### template<typename TTimerType>
class TimeoutTimer< TTimerType >

A timeout timer will fire once after the interval.

You can reset it to fire again. The timer will never fire before the interval has passed, but in times of severe stress it might be late.

Definition at line 116 of file timer.h.

## Constructor & Destructor Documentation

## ◆ TimeoutTimer()

template<typename TTimerType >

TimeoutTimer< TTimerType >::TimeoutTimer | ( | const TPeriod | timeout,
|  | std::function< void()> | callback,
|  | bool | start = `false`
| ) |  |
| inline

Create a new timeout timer.

By default the timeout starts aborted; you will have to call Reset() before it starts.

Parameters

  timeout | The timeout after which the timer will fire.
  callback | The callback to call when the timeout has passed.
  start | Whether to start the timer immediately. If false, you can call Reset() to start it.

Definition at line 130 of file timer.h.

## Member Function Documentation

## ◆ Elapsed()

template<typename TTimerType >

void TimeoutTimer< TTimerType >::Elapsed | ( | TElapsed | delta | ) |
| overrideprivatevirtual

Called by the timer manager to notify the timer that the given amount of time has elapsed.

Parameters

  delta | Depending on the time type, this is either in milliseconds or in ticks.

Implements BaseTimer< TTimerType >.

## ◆ HasFired()

template<typename TTimerType >

bool TimeoutTimer< TTimerType >::HasFired | ( |  | ) | const
| inline

Check whether the timeout occurred.

Returns
  True iff the timeout occurred.

Definition at line 171 of file timer.h.

## ◆ Reset()

template<typename TTimerType >

void TimeoutTimer< TTimerType >::Reset | ( | const TPeriod | timeout | ) |
| inline

Reset the timer, so it will fire again after the timeout.

Parameters

  timeout | Set a new timeout for the next trigger.

Definition at line 151 of file timer.h.

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

- src/timer/timer.h