OpenTTD Source 20241224-master-gf74b0cf984
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 NewGRFClassGet (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_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, 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
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()

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

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

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

◆ 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 36 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(), and MoveWaypointsToBaseStations().

Field Documentation

◆ classes

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

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

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