OpenTTD Source 20260721-master-g25ec12c62d
label_type.hpp
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 LABEL_TYPE_HPP
11#define LABEL_TYPE_HPP
12
14struct BaseLabel : std::array<uint8_t, 4> {
19 constexpr inline bool Empty() const
20 {
21 return std::ranges::all_of(*this, [](uint8_t b) { return b == 0; });
22 };
23
30 std::string AsString() const;
31};
32
37template <typename Tag>
38struct Label : BaseLabel {
40 constexpr Label()
41 {
42 std::ranges::fill(*this, 0);
43 }
44
50 constexpr Label(const char (&label)[5])
51 {
52 std::copy(label, label + this->size(), this->begin());
53 }
54
59 constexpr Label(const uint8_t (&label)[4])
60 {
61 std::copy(label, label + this->size(), this->begin());
62 }
63
69 constexpr std::strong_ordering operator<=>(const Label<Tag> &other) const = default;
70};
71
72#endif /* LABEL_TYPE_HPP */
Base for a four character label/tag/id.
constexpr bool Empty() const
Check whether the label is empty.
std::string AsString() const
Get the label as a std::string.
Definition label.cpp:22
constexpr Label()
Create an empty label, i.e.
constexpr Label(const uint8_t(&label)[4])
Create a label with the given 4 bytes.
constexpr std::strong_ordering operator<=>(const Label< Tag > &other) const =default
Default spaceship operator.
constexpr Label(const char(&label)[5])
Create a label with the given 4 letter character string.