OpenTTD
Macros | Functions
newgrf_class_func.h File Reference

Implementation of the NewGRF class' functions. More...

#include "newgrf_class.h"
#include "table/strings.h"

Go to the source code of this file.

Macros

#define DEFINE_NEWGRF_CLASS_METHOD(type)
 Helper for defining the class method's signatures. More...
 
#define INSTANTIATE_NEWGRF_CLASS_METHODS(name, Tspec, Tid, Tmax)
 Force instantiation of the methods so we don't get linker errors. More...
 

Functions

 DEFINE_NEWGRF_CLASS_METHOD (void)
 Reset the class, i.e. More...
 
 DEFINE_NEWGRF_CLASS_METHOD (Tid)
 Allocate a class with a given global class ID. More...
 
 DEFINE_NEWGRF_CLASS_METHOD (uint)
 Get the number of allocated classes. More...
 
 DEFINE_NEWGRF_CLASS_METHOD (const Tspec *)
 Get a spec from the class at a given index. More...
 

Detailed Description

Implementation of the NewGRF class' functions.

Definition in file newgrf_class_func.h.

Macro Definition Documentation

◆ DEFINE_NEWGRF_CLASS_METHOD

#define DEFINE_NEWGRF_CLASS_METHOD (   type)
Value:
template <typename Tspec, typename Tid, Tid Tmax> \
Struct containing information relating to NewGRF classes for stations and airports.
Definition: newgrf_class.h:21

Helper for defining the class method's signatures.

Parameters
typeThe type of the class.

Definition at line 20 of file newgrf_class_func.h.

Referenced by DEFINE_NEWGRF_CLASS_METHOD().

◆ INSTANTIATE_NEWGRF_CLASS_METHODS

#define INSTANTIATE_NEWGRF_CLASS_METHODS (   name,
  Tspec,
  Tid,
  Tmax 
)
Value:
template void name::ResetClass(); \
template void name::Reset(); \
template Tid name::Allocate(uint32 global_id); \
template void name::Insert(Tspec *spec); \
template void name::Assign(Tspec *spec); \
template NewGRFClass<Tspec, Tid, Tmax> *name::Get(Tid cls_id); \
template uint name::GetClassCount(); \
template uint name::GetUIClassCount(); \
template Tid name::GetUIClass(uint index); \
template const Tspec *name::GetSpec(uint index) const; \
template int name::GetUIFromIndex(int index) const; \
template int name::GetIndexFromUI(int ui_index) const; \
template const Tspec *name::GetByGrf(uint32 grfid, byte localidx, int *index);
Struct containing information relating to NewGRF classes for stations and airports.
Definition: newgrf_class.h:21

Force instantiation of the methods so we don't get linker errors.

Definition at line 218 of file newgrf_class_func.h.

Referenced by NewGRFClass< Tspec, Tid, Tmax >::IsUIAvailable(), and ResetObjects().

Function Documentation

◆ DEFINE_NEWGRF_CLASS_METHOD() [1/4]

DEFINE_NEWGRF_CLASS_METHOD ( void  )

Reset the class, i.e.

Assign a spec to one of the classes.

Insert a spec into the class.

Reset the classes, i.e.

clear everything.

Parameters
specThe spec to insert.
specThe spec to assign.
Note
The spec must have a valid class id set.

Definition at line 29 of file newgrf_class_func.h.

References DEFINE_NEWGRF_CLASS_METHOD, and free().

◆ DEFINE_NEWGRF_CLASS_METHOD() [2/4]

DEFINE_NEWGRF_CLASS_METHOD ( Tid  )

Allocate a class with a given global class ID.

Get the nth-class with user available specs.

Parameters
cls_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.
Parameters
indexUI index of a class.
Returns
The class ID of the class.

Definition at line 57 of file newgrf_class_func.h.

References DEFINE_NEWGRF_CLASS_METHOD, grfmsg(), and ReallocT().

◆ DEFINE_NEWGRF_CLASS_METHOD() [3/4]

DEFINE_NEWGRF_CLASS_METHOD ( uint  )

Get the number of allocated classes.

Get the number of classes available to the user.

Returns
The number of classes.

Definition at line 115 of file newgrf_class_func.h.

References DEFINE_NEWGRF_CLASS_METHOD.

◆ DEFINE_NEWGRF_CLASS_METHOD() [4/4]

DEFINE_NEWGRF_CLASS_METHOD ( const Tspec *  )

Get a spec from the class at a given index.

Parameters
indexThe index where to find the spec.
Returns
The spec at given location. Translate a UI spec index into a spec index.
Parameters
ui_indexUI index of the spec.
Returns
index of the spec, or -1 if out of range. Translate a spec index into a UI spec index.
Parameters
indexindex of the spec.
Returns
UI index of the spec, or -1 if out of range. 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 NULL then not used.
Returns
The spec.

Definition at line 154 of file newgrf_class_func.h.

References DEFINE_NEWGRF_CLASS_METHOD.