30inline std::string_view
ItemAt(E idx, std::span<const std::string_view> names, std::string_view unknown_name)
32 if (
static_cast<size_t>(idx) >= std::size(names)) {
50inline std::string_view
ItemAt(E idx, std::span<const std::string_view> names, std::string_view unknown_name, E invalid_index, std::string_view invalid_name)
52 if (idx == invalid_index) {
55 return ItemAt(idx, names, unknown_name);
67template <
typename Tbitset>
68inline std::string
ComposeName(Tbitset value, std::span<const std::string_view> names, std::string_view unknown_name)
70 if (value.None())
return "<none>";
73 for (
auto index : value) {
74 if (!out.empty()) out +=
"+";
92template <
typename Tbitset>
93inline std::string
ComposeName(Tbitset value, std::span<const std::string_view> names, std::string_view unknown_name, Tbitset invalid_value, std::string_view invalid_name)
95 if (value == invalid_value)
return std::string{invalid_name};
120 if (
reinterpret_cast<size_t>(this->ptr) <
reinterpret_cast<size_t>(other.
ptr))
return true;
121 if (
reinterpret_cast<size_t>(this->ptr) >
reinterpret_cast<size_t>(other.
ptr))
return false;
122 if (this->type_id < other.
type_id)
return true;
137 std::optional<std::string>
FindKnownAsName(
size_t type_id,
const void *ptr);
149 format_append(this->output_buffer,
"{} = {}\n", name, value);
159 template <
typename E>
void WriteEnumT(std::string_view name, E e)
164 void BeginStruct(
size_t type_id, std::string_view name,
const void *ptr);
174 static const size_t type_id = this->
NewTypeId();
181 if (
auto known_as = this->
FindKnownAsName(type_id, s); known_as.has_value()) {
197 template <
typename S>
void WriteStructT(std::string_view name,
const std::deque<S> *s)
199 static const size_t type_id = this->
NewTypeId();
206 if (
auto known_as = this->
FindKnownAsName(type_id, s); known_as.has_value()) {
212 size_t num_items = s->size();
214 for (
size_t i = 0; i < num_items; i++) {
215 const auto &item = (*s)[i];
std::string ValueStr(Trackdir td)
Return name of given Trackdir.
std::string_view ItemAt(E idx, std::span< const std::string_view > names, std::string_view unknown_name)
Helper template function that returns item of array at given index or unknown_name when index is out ...
std::string ComposeName(Tbitset value, std::span< const std::string_view > names, std::string_view unknown_name)
Helper template function that returns compound bitfield name that is concatenation of names of each s...
Different types to 'show' directions.
DiagDirection
Enumeration for diagonal directions.
#define S
Climate sub-tropic.
constexpr std::underlying_type_t< enum_type > to_underlying(enum_type e)
Implementation of std::to_underlying (from C++23).
Types and classes related to signals.
SignalType
Type of signal, i.e.
Used as a key into map of known object instances.
const void * ptr
Pointer to the structure.
KnownStructKey(size_t type_id, const void *ptr)
Create the key.
size_t type_id
Unique identifier of the type.
Class that represents the dump-into-string target.
std::map< KnownStructKey, std::string > KnownNamesMap
Mapping of the KnownStructKey to the name for that structure.
KnownNamesMap known_names
Map of known object instances and their structured names.
std::stack< std::string > cur_struct
Tracker of the current structure name.
void WriteTile(std::string_view name, TileIndex t)
Write name & TileIndex to the output.
void BeginStruct(size_t type_id, std::string_view name, const void *ptr)
Open new structure (one level deeper than the current one) 'name = {<LF>'.
int indent
Current indent/nesting level.
void WriteStructT(std::string_view name, const std::deque< S > *s)
Dump nested object (or only its name if this instance is already known).
std::string GetCurrentStructName()
Return structured name of the current class/structure.
std::string output_buffer
The output string.
void WriteStructT(std::string_view name, const S *s)
Dump nested object (or only its name if this instance is already known).
std::optional< std::string > FindKnownAsName(size_t type_id, const void *ptr)
Find the given instance in our anti-recursion repository.
void WriteEnumT(std::string_view name, E e)
Dump given enum value (as a number and as named value).
void WriteIndent()
Write some leading spaces into the output.
void EndStruct()
Close structure '}<LF>'.
void WriteValue(std::string_view name, const auto &value)
Write 'name = value' with indent and new-line.
static size_t NewTypeId()
Create a new type_id.
StrongType::Typedef< uint32_t, struct TileIndexTag, StrongType::Compare, StrongType::Integer, StrongType::Compatible< int32_t >, StrongType::Compatible< int64_t > > TileIndex
The index/ID of a Tile.
All types related to tracks.
EnumBitSet< Trackdir, uint16_t > TrackdirBits
Bitset of Trackdir elements.
Trackdir
Enumeration for tracks and directions.