12#include "table/strings.h"
15template <
typename Tspec,
typename Tindex, Tindex Tmax>
31template <
typename Tspec,
typename Tindex, Tindex Tmax>
46 GrfMsg(2,
"ClassAllocate: already allocated {} classes, using default", Tmax);
47 return static_cast<Tindex
>(0);
54template <
typename Tspec,
typename Tindex, Tindex Tmax>
57 auto it = this->spec.insert(std::end(this->spec),
spec);
58 uint16_t
index =
static_cast<uint16_t
>(std::distance(std::begin(this->spec), it));
59 if (
spec !=
nullptr) (*it)->index =
index;
69template <
typename Tspec,
typename Tindex, Tindex Tmax>
81template <
typename Tspec,
typename Tindex, Tindex Tmax>
92template <
typename Tspec,
typename Tindex, Tindex Tmax>
102template <
typename Tspec,
typename Tindex, Tindex Tmax>
105 return std::ranges::count_if(
NewGRFClass::classes, [](
const auto &cls) {
return cls.GetUISpecCount() > 0; });
113template <
typename Tspec,
typename Tindex, Tindex Tmax>
126template <
typename Tspec,
typename Tindex, Tindex Tmax>
130 for (
const auto &
spec : cls.spec) {
131 if (
spec ==
nullptr)
continue;
132 if (
spec->grf_prop.local_id != local_id)
continue;
133 if (
spec->grf_prop.grfid == grfid)
return spec;
Tindex index
Index of class within the list of classes.
static void Assign(Tspec *spec)
Assign a spec to one of the classes.
void Insert(Tspec *spec)
Insert a spec into the class, and update its index.
uint32_t global_id
Global ID for class, e.g. 'DFLT', 'WAYP', etc.
bool IsUIAvailable(uint index) const
Check whether the spec will be available to the user at some point in time.
static NewGRFClass * Get(Tindex class_index)
Get a particular class.
static void InsertDefaults()
Initialise the defaults.
static uint GetUIClassCount()
Get the number of classes available to the user.
static Tindex Allocate(uint32_t global_id)
Allocate a class with a given global class ID.
uint ui_count
Number of specs in this class potentially available to the user.
static const Tspec * GetByGrf(uint32_t grfid, uint16_t local_id)
Retrieve a spec by GRF location.
std::vector< Tspec * > spec
List of specifications.
uint GetSpecCount() const
Get the number of allocated specs within the class.
static uint GetClassCount()
Get the number of allocated classes.
const Tspec * GetSpec(uint index) const
Get a spec from the class at a given index.
static std::vector< NewGRFClass< Tspec, Tindex, Tmax > > classes
The actual classes.
static void Reset()
Reset the classes, i.e.
Header file for classes to be used by for example, NewGRF stations and airports.