OpenTTD Source: NewGRFClass< Tspec, Tindex, Tmax > Class Template Reference

OpenTTD Source 15.3

Public Types | Public Member Functions | Static Public Member Functions | Data Fields | Static Private Member Functions | Private Attributes | Static Private Attributes
NewGRFClass< Tspec, Tindex, Tmax > Class Template Reference

Struct containing information relating to NewGRF classes for stations and airports. More...

`#include <newgrf_class.h>`

## Public Types
using | spec_type = Tspec
using | index_type = Tindex

## Public Member Functions
| NewGRFClass (uint32_t global_id, StringID name)
std::span< Tspec *const > | Specs () const
| Get read-only span of specs of this class.
void | Insert (Tspec *spec)
| Insert a spec into the class, and update its index.
Tindex | Index () const
uint | GetSpecCount () const
| Get the number of allocated specs within the class.
uint | GetUISpecCount () const
| Get the number of potentially user-available specs within the class.
const Tspec * | GetSpec (uint index) const
| Get a spec from the class at a given index.
bool | IsUIAvailable (uint index) const
| Check whether the spec will be available to the user at some point in time.

## Static Public Member Functions
static std::span< NewGRFClass< Tspec, Tindex, Tmax > const > | Classes ()
| Get read-only span of all classes of this type.
static void | Reset ()
| Reset the classes, i.e.
static Tindex | Allocate (uint32_t global_id)
| Allocate a class with a given global class ID.
static void | Assign (Tspec *spec)
| Assign a spec to one of the classes.
static uint | GetClassCount ()
| Get the number of allocated classes.
static uint | GetUIClassCount ()
| Get the number of classes available to the user.
static NewGRFClass * | Get (Tindex class_index)
| Get a particular class.
static const Tspec * | GetByGrf (uint32_t grfid, uint16_t local_id)
| Retrieve a spec by GRF location.

## Data Fields
uint32_t | global_id
| Global ID for class, e.g. 'DFLT', 'WAYP', etc.
StringID | name
| Name of this class.

## Static Private Member Functions
static void | InsertDefaults ()
| Initialise the defaults.

## Private Attributes
uint | ui_count = 0
| Number of specs in this class potentially available to the user.
Tindex | index = static_cast<Tindex>(0)
| Index of class within the list of classes.
std::vector< Tspec * > | spec
| List of specifications.

## Static Private Attributes
static std::vector< NewGRFClass< Tspec, Tindex, Tmax > > | classes
| The actual classes.

## Detailed Description

template<typename Tspec, typename Tindex, Tindex Tmax>
class NewGRFClass< Tspec, Tindex, Tmax >

Struct containing information relating to NewGRF classes for stations and airports.

Definition at line 26 of file newgrf_class.h.

## Member Typedef Documentation

## ◆ index_type

template<typename Tspec , typename Tindex , Tindex Tmax>

using NewGRFClass< Tspec, Tindex, Tmax >::index_type = Tindex

Definition at line 46 of file newgrf_class.h.

## ◆ spec_type

template<typename Tspec , typename Tindex , Tindex Tmax>

using NewGRFClass< Tspec, Tindex, Tmax >::spec_type = Tspec

Definition at line 45 of file newgrf_class.h.

## Constructor & Destructor Documentation

## ◆ NewGRFClass()

template<typename Tspec , typename Tindex , Tindex Tmax>

NewGRFClass< Tspec, Tindex, Tmax >::NewGRFClass | ( | uint32_t | global_id,
|  | StringID | name
| ) |  |
| inline

Definition at line 52 of file newgrf_class.h.

## Member Function Documentation

## ◆ Allocate()

template<typename Tspec , typename Tindex , Tindex Tmax>

Tindex NewGRFClass< Tspec, Tindex, Tmax >::Allocate | ( | uint32_t | global_id | ) |
| static

Allocate a class with a given global class ID.

Parameters

  global_id | The global class id, such as 'DFLT'.

Returns
  The (non global!) class ID for the class.

Note
  Upon allocating the same global class ID for a second time, this first allocation will be given.

Definition at line 32 of file newgrf_class_func.h.

References NewGRFClass< Tspec, Tindex, Tmax >::classes, and NewGRFClass< Tspec, Tindex, Tmax >::global_id.

Referenced by NewGRFClass< Tspec, Tindex, Tmax >::InsertDefaults(), ObjectChangeInfo(), ResetObjects(), and StationChangeInfo().

## ◆ Assign()

template<typename Tspec , typename Tindex , Tindex Tmax>

void NewGRFClass< Tspec, Tindex, Tmax >::Assign | ( | Tspec * | spec | ) |
| static

Assign a spec to one of the classes.

Parameters

  spec | The spec to assign.

Note
  The spec must have a valid class index set.

Definition at line 70 of file newgrf_class_func.h.

References NewGRFClass< Tspec, Tindex, Tmax >::classes.

Referenced by BindAirportSpecs(), and ObjectSpec::BindToClasses().

## ◆ Classes()

template<typename Tspec , typename Tindex , Tindex Tmax>

static std::span< NewGRFClass< Tspec, Tindex, Tmax > const > NewGRFClass< Tspec, Tindex, Tmax >::Classes | ( |  | ) |
| inlinestatic

Get read-only span of all classes of this type.

Returns
  Read-only span of classes.

Definition at line 64 of file newgrf_class.h.

References NewGRFClass< Tspec, Tindex, Tmax >::classes.

Referenced by BuildAirportWindow::BuildAirportClassDropDown(), GetIfNewStopsByType(), StationPickerCallbacks::HasClassChoice(), WaypointPickerCallbacks::HasClassChoice(), RoadStopPickerCallbacks< roadstoptype >::HasClassChoice(), RoadWaypointPickerCallbacks::HasClassChoice(), ObjectPickerCallbacks::IsActive(), StationPickerCallbacks::IsActive(), WaypointPickerCallbacks::IsActive(), RoadStopPickerCallbacks< roadstoptype >::IsActive(), RoadWaypointPickerCallbacks::IsActive(), BuildAirportWindow::SelectFirstAvailableAirport(), and BuildAirportWindow::UpdateWidgetSize().

## ◆ Get()

template<typename Tspec , typename Tindex , Tindex Tmax>

NewGRFClass< Tspec, Tindex, Tmax > * NewGRFClass< Tspec, Tindex, Tmax >::Get | ( | Tindex | class_index | ) |
| static

Get a particular class.

Parameters

  class_index | The index of the class.

Precondition
  class_index < Tmax

Definition at line 82 of file newgrf_class_func.h.

References NewGRFClass< Tspec, Tindex, Tmax >::classes.

Referenced by CcRoadStop(), CheckFlatLandRailStation(), CmdBuildRailStation(), CmdBuildRailWaypoint(), CmdBuildRoadStop(), CmdBuildRoadWaypoint(), DrawStationTile(), BuildAirportWindow::DrawWidget(), BuildObjectWindow::DrawWidget(), BuildRoadStationWindow::DrawWidget(), BuildAirportWindow::GetWidgetString(), BuildObjectWindow::GetWidgetString(), NewGRFClass< Tspec, Tindex, Tmax >::InsertDefaults(), MoveWaypointsToBaseStations(), ObjectChangeInfo(), BuildAirportWindow::OnClick(), BuildRailStationWindow::OnClick(), BuildRoadStationWindow::OnClick(), BuildAirportWindow::OnDropdownSelect(), BuildObjectWindow::OnInvalidateData(), BuildRailStationWindow::OnInvalidateData(), BuildAirportWindow::OnPaint(), BuildRailStationWindow::OnPaint(), BuildRoadStationWindow::OnPaint(), BuildObjectWindow::OnPlaceMouseUp(), BuildRoadToolbarWindow::OnPlaceMouseUp(), BuildObjectWindow::OnPlaceObject(), PlaceAirport(), BuildAirportWindow::SelectFirstAvailableAirport(), StationChangeInfo(), and BuildObjectWindow::UpdateWidgetSize().

## ◆ GetByGrf()

template<typename Tspec , typename Tindex , Tindex Tmax>

const Tspec * NewGRFClass< Tspec, Tindex, Tmax >::GetByGrf | ( | uint32_t | grfid,
|  | uint16_t | local_id
| ) |  |
| static

Retrieve a spec by GRF location.

Parameters

  grfid | GRF ID of spec.
  local_id | Index within GRF file of spec.
  index | Pointer to return the index of the spec in its class. If nullptr then not used.

Returns
  The spec.

Definition at line 128 of file newgrf_class_func.h.

References NewGRFClass< Tspec, Tindex, Tmax >::classes.

## ◆ GetClassCount()

template<typename Tspec , typename Tindex , Tindex Tmax>

uint NewGRFClass< Tspec, Tindex, Tmax >::GetClassCount | ( |  | ) |
| static

Get the number of allocated classes.

Returns
  The number of classes.

Definition at line 93 of file newgrf_class_func.h.

References NewGRFClass< Tspec, Tindex, Tmax >::classes.

Referenced by CcRoadStop(), CmdBuildRailStation(), CmdBuildRailWaypoint(), CmdBuildRoadStop(), and CmdBuildRoadWaypoint().

## ◆ GetSpec()

template<typename Tspec , typename Tindex , Tindex Tmax>

const Tspec * NewGRFClass< Tspec, Tindex, Tmax >::GetSpec | ( | uint | index | ) | const

Get a spec from the class at a given index.

Parameters

  index | The index where to find the spec.

Returns
  The spec at given location.

Definition at line 114 of file newgrf_class_func.h.

Referenced by CcRoadStop(), CheckFlatLandRailStation(), CmdBuildRailStation(), CmdBuildRailWaypoint(), CmdBuildRoadStop(), CmdBuildRoadWaypoint(), DrawStationTile(), BuildAirportWindow::DrawWidget(), BuildObjectWindow::DrawWidget(), BuildRoadStationWindow::DrawWidget(), BuildAirportWindow::GetWidgetString(), BuildObjectWindow::GetWidgetString(), MoveWaypointsToBaseStations(), BuildAirportWindow::OnClick(), BuildRailStationWindow::OnClick(), BuildRoadStationWindow::OnClick(), BuildRailStationWindow::OnInvalidateData(), BuildAirportWindow::OnPaint(), BuildRailStationWindow::OnPaint(), BuildRoadStationWindow::OnPaint(), BuildObjectWindow::OnPlaceMouseUp(), BuildObjectWindow::OnPlaceObject(), PlaceAirport(), and BuildObjectWindow::UpdateWidgetSize().

## ◆ GetSpecCount()

template<typename Tspec , typename Tindex , Tindex Tmax>

uint NewGRFClass< Tspec, Tindex, Tmax >::GetSpecCount | ( |  | ) | const
| inline

Get the number of allocated specs within the class.

Definition at line 70 of file newgrf_class.h.

Referenced by CmdBuildRailStation(), CmdBuildRailWaypoint(), CmdBuildRoadStop(), CmdBuildRoadWaypoint(), and BuildAirportWindow::OnDropdownSelect().

## ◆ GetUIClassCount()

template<typename Tspec , typename Tindex , Tindex Tmax>

uint NewGRFClass< Tspec, Tindex, Tmax >::GetUIClassCount | ( |  | ) |
| static

Get the number of classes available to the user.

Returns
  The number of classes.

Definition at line 103 of file newgrf_class_func.h.

References NewGRFClass< Tspec, Tindex, Tmax >::classes.

Referenced by TerraformToolbarWindow::OnInit().

## ◆ GetUISpecCount()

template<typename Tspec , typename Tindex , Tindex Tmax>

uint NewGRFClass< Tspec, Tindex, Tmax >::GetUISpecCount | ( |  | ) | const
| inline

Get the number of potentially user-available specs within the class.

Definition at line 72 of file newgrf_class.h.

References NewGRFClass< Tspec, Tindex, Tmax >::ui_count.

## ◆ Index()

template<typename Tspec , typename Tindex , Tindex Tmax>

Tindex NewGRFClass< Tspec, Tindex, Tmax >::Index | ( |  | ) | const
| inline

Definition at line 68 of file newgrf_class.h.

## ◆ Insert()

template<typename Tspec , typename Tindex , Tindex Tmax>

void NewGRFClass< Tspec, Tindex, Tmax >::Insert | ( | Tspec * | spec | ) |

Insert a spec into the class, and update its index.

Parameters

  spec | The spec to insert.

Definition at line 55 of file newgrf_class_func.h.

## ◆ InsertDefaults()

void StationClass::InsertDefaults | ( |  | ) |
| staticprivate

Initialise the defaults.

Reset airport classes to their default state.

This includes initialising the defaults classes with an empty entry, for standard airports.

Definition at line 31 of file newgrf_airport.cpp.

References NewGRFClass< Tspec, Tindex, Tmax >::Allocate(), NewGRFClass< Tspec, Tindex, Tmax >::Get(), and NewGRFClass< Tspec, Tindex, Tmax >::name.

Referenced by NewGRFClass< Tspec, Tindex, Tmax >::Reset().

## ◆ IsUIAvailable()

bool StationClass::IsUIAvailable | ( | uint | index | ) | const

Check whether the spec will be available to the user at some point in time.

Definition at line 40 of file newgrf_airport.cpp.

## ◆ Reset()

template<typename Tspec , typename Tindex , Tindex Tmax>

void NewGRFClass< Tspec, Tindex, Tmax >::Reset | ( |  | ) |
| static

Reset the classes, i.e.

clear everything.

Definition at line 16 of file newgrf_class_func.h.

References NewGRFClass< Tspec, Tindex, Tmax >::classes, and NewGRFClass< Tspec, Tindex, Tmax >::InsertDefaults().

Referenced by ResetNewGRFData().

## ◆ Specs()

template<typename Tspec , typename Tindex , Tindex Tmax>

std::span< Tspec *const > NewGRFClass< Tspec, Tindex, Tmax >::Specs | ( |  | ) | const
| inline

Get read-only span of specs of this class.

Returns
  Read-only span of specs.

Definition at line 58 of file newgrf_class.h.

References NewGRFClass< Tspec, Tindex, Tmax >::spec.

Referenced by BuildAirportWindow::DrawWidget(), GetIfClassHasNewStopsByType(), MoveWaypointsToBaseStations(), and BuildAirportWindow::SelectFirstAvailableAirport().

## Field Documentation

## ◆ classes

template<typename Tspec , typename Tindex , Tindex Tmax>

std::vector<NewGRFClass<Tspec, Tindex, Tmax> > NewGRFClass< Tspec, Tindex, Tmax >::classes
| inlinestaticprivate

The actual classes.

Note
  This may be reallocated during initialization so pointers may be invalidated.

Definition at line 39 of file newgrf_class.h.

Referenced by NewGRFClass< Tspec, Tindex, Tmax >::Allocate(), NewGRFClass< Tspec, Tindex, Tmax >::Assign(), NewGRFClass< Tspec, Tindex, Tmax >::Classes(), NewGRFClass< Tspec, Tindex, Tmax >::Get(), NewGRFClass< Tspec, Tindex, Tmax >::GetByGrf(), NewGRFClass< Tspec, Tindex, Tmax >::GetClassCount(), NewGRFClass< Tspec, Tindex, Tmax >::GetUIClassCount(), and NewGRFClass< Tspec, Tindex, Tmax >::Reset().

## ◆ global_id

template<typename Tspec , typename Tindex , Tindex Tmax>

uint32_t NewGRFClass< Tspec, Tindex, Tmax >::global_id

Global ID for class, e.g. 'DFLT', 'WAYP', etc.

Definition at line 48 of file newgrf_class.h.

Referenced by NewGRFClass< Tspec, Tindex, Tmax >::Allocate(), IsWaypointClass(), and IsWaypointClass().

## ◆ index

template<typename Tspec , typename Tindex , Tindex Tmax>

Tindex NewGRFClass< Tspec, Tindex, Tmax >::index = static_cast<Tindex>(0)
| private

Index of class within the list of classes.

Definition at line 32 of file newgrf_class.h.

## ◆ name

template<typename Tspec , typename Tindex , Tindex Tmax>

StringID NewGRFClass< Tspec, Tindex, Tmax >::name

Name of this class.

Definition at line 49 of file newgrf_class.h.

Referenced by NewGRFClass< Tspec, Tindex, Tmax >::InsertDefaults(), ObjectChangeInfo(), and StationChangeInfo().

## ◆ spec

template<typename Tspec , typename Tindex , Tindex Tmax>

std::vector<Tspec *> NewGRFClass< Tspec, Tindex, Tmax >::spec
| private

List of specifications.

Definition at line 33 of file newgrf_class.h.

Referenced by NewGRFClass< Tspec, Tindex, Tmax >::Specs().

## ◆ ui_count

template<typename Tspec , typename Tindex , Tindex Tmax>

uint NewGRFClass< Tspec, Tindex, Tmax >::ui_count = 0
| private

Number of specs in this class potentially available to the user.

Definition at line 31 of file newgrf_class.h.

Referenced by NewGRFClass< Tspec, Tindex, Tmax >::GetUISpecCount().

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

- src/newgrf_class.h
- src/newgrf_airport.cpp
- src/newgrf_class_func.h
- src/newgrf_object.cpp
- src/newgrf_roadstop.cpp
- src/newgrf_station.cpp