Make DeleteStaleLinks static
[openttd/fttd.git] / src / newgrf_class.h
blobb156dbe3d8ee7bc41c2a45ff599a41a2e953d137
1 /* $Id$ */
3 /*
4 * This file is part of OpenTTD.
5 * OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
6 * OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
7 * See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>.
8 */
10 /** @file newgrf_class.h Header file for classes to be used by e.g. NewGRF stations and airports */
12 #ifndef NEWGRF_CLASS_H
13 #define NEWGRF_CLASS_H
15 #include "strings_type.h"
17 /**
18 * Struct containing information relating to NewGRF classes for stations and airports.
20 template <typename Tspec, typename Tid, Tid Tmax>
21 struct NewGRFClass {
22 typedef Tspec Spec;
23 typedef Tid Id;
25 private:
26 uint count; ///< Number of specs in this class.
27 uint ui_count; ///< Number of specs in this class potentially available to the user.
28 Tspec **spec; ///< Array of specifications.
30 /**
31 * The actual classes.
32 * @note We store pointers to membes of this array in various places outside this class (e.g. to 'name' for GRF string resolving).
33 * Thus this must be a static array, and cannot be a self-resizing SmallVector or similar.
35 static NewGRFClass<Tspec, Tid, Tmax> classes[Tmax];
37 void ResetClass();
39 /** Initialise the defaults. */
40 static void InsertDefaults();
42 public:
43 uint32 global_id; ///< Global ID for class, e.g. 'DFLT', 'WAYP', etc.
44 StringID name; ///< Name of this class.
46 void Insert(Tspec *spec);
48 /** Get the number of allocated specs within the class. */
49 uint GetSpecCount() const { return this->count; }
50 /** Get the number of potentially user-available specs within the class. */
51 uint GetUISpecCount() const { return this->ui_count; }
52 int GetUIFromIndex(int index) const;
53 int GetIndexFromUI(int ui_index) const;
55 const Tspec *GetSpec(uint index) const;
57 /** Check whether the spec will be available to the user at some point in time. */
58 bool IsUIAvailable(uint index) const;
60 static void Reset();
61 static Tid Allocate(uint32 global_id);
62 static void Assign(Tspec *spec);
63 static uint GetClassCount();
64 static uint GetUIClassCount();
65 static Tid GetUIClass(uint index);
66 static NewGRFClass *Get(Tid cls_id);
68 static const Tspec *GetByGrf(uint32 grfid, byte local_id, int *index);
71 #endif /* NEWGRF_CLASS_H */