OpenTTD Source  20240915-master-g3784a3d3d6
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. More...
 
void Insert (Tspec *spec)
 Insert a spec into the class, and update its index. More...
 
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. More...
 
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. More...
 
static void Reset ()
 Reset the classes, i.e. More...
 
static Tindex Allocate (uint32_t global_id)
 Allocate a class with a given global class ID. More...
 
static void Assign (Tspec *spec)
 Assign a spec to one of the classes. More...
 
static uint GetClassCount ()
 Get the number of allocated classes. More...
 
static uint GetUIClassCount ()
 Get the number of classes available to the user. More...
 
static NewGRFClassGet (Tindex class_index)
 Get a particular class. More...
 
static const Tspec * GetByGrf (uint32_t grfid, uint16_t local_id)
 Retrieve a spec by GRF location. More...
 

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. More...
 

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. More...
 

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 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_idThe 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.

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

◆ 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
specThe 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()

◆ Get()

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

◆ 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
grfidGRF ID of spec.
local_idIndex within GRF file of spec.
indexPointer 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.

◆ 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.

◆ 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
indexThe index where to find the spec.
Returns
The spec at given location.

Definition at line 114 of file newgrf_class_func.h.

Referenced by MoveWaypointsToBaseStations(), BuildObjectWindow::OnInvalidateData(), BuildRailStationWindow::OnInvalidateData(), BuildAirportWindow::OnPaint(), BuildRailStationWindow::OnPaint(), and PlaceAirport().

◆ 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().

◆ 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
specThe 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 27 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().

◆ 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().

◆ 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 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 documentation for this class was generated from the following files: