OpenTTD Source 20260512-master-g20b387b91f
station_layout_type.h
Go to the documentation of this file.
1/*
2 * This file is part of OpenTTD.
3 * 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.
4 * 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.
5 * 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 <https://www.gnu.org/licenses/old-licenses/gpl-2.0>.
6 */
7
9
10#ifndef STATION_LAYOUT_TYPE_H
11#define STATION_LAYOUT_TYPE_H
12
13#include "newgrf_station.h"
14#include "station_map.h"
15
16template <StationType T>
17class RailStationTileLayout {
18private:
19 std::span<const StationGfx> layout{};
20 uint platforms;
21 uint length;
22public:
23 RailStationTileLayout(const StationSpec *spec, uint8_t platforms, uint8_t length) : platforms(platforms), length(length)
24 {
25 if (spec == nullptr) return;
26
27 /* Look for a predefined layout for the required size. */
28 auto found = spec->layouts.find(GetStationLayoutKey(platforms, length));
29 if (found != std::end(spec->layouts)) this->layout = found->second;
30 }
31
32 class Iterator {
33 const RailStationTileLayout &stl;
34 uint position = 0;
35 public:
36 using value_type = StationGfx;
37 using difference_type = std::ptrdiff_t;
38 using iterator_category = std::forward_iterator_tag;
39 using pointer = void;
40 using reference = void;
41
42 Iterator(const RailStationTileLayout &stl) : stl(stl) {}
43
44 bool operator==(const Iterator &rhs) const { return this->position == rhs.position; }
45 bool operator==(const std::default_sentinel_t &) const { return this->position == this->stl.platforms * this->stl.length; }
46
52
53 Iterator &operator++()
54 {
55 ++this->position;
56 return *this;
57 }
58
60 {
61 Iterator result = *this;
62 ++*this;
63 return result;
64 }
65 };
66
67 Iterator begin() const { return Iterator(*this); }
68 std::default_sentinel_t end() const { return std::default_sentinel_t(); }
69};
70
71#endif /* STATION_LAYOUT_TYPE_H */
const RailStationTileLayout & stl
Station tile layout being iterated.
uint position
Position within iterator.
StationGfx operator*() const
Dereference operator.
uint length
Length of platforms.
std::span< const StationGfx > layout
Predefined tile layout.
uint platforms
Number of platforms.
constexpr enum_type & operator++(enum_type &e)
Prefix increment.
Definition enum_type.hpp:41
uint8_t StationGfx
Copy from station_map.h.
Header file for NewGRF stations.
uint16_t GetStationLayoutKey(uint8_t platforms, uint8_t length)
Get the station layout key for a given station layout size.
Maps accessors for stations.
Station specification.
std::unordered_map< uint16_t, std::vector< uint8_t > > layouts
Custom platform layouts, keyed by platform and length combined.