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);
71inline std::string
ComposeName(E value, std::span<const std::string_view> names, std::string_view unknown_name, E invalid_index, std::string_view invalid_name)
74 if (value == invalid_index) {
76 }
else if (value == 0) {
79 for (
size_t i = 0; i < std::size(names); i++) {
80 if ((value & (1 << i)) == 0)
continue;
81 out += (!out.empty() ?
"+" :
"");
83 value &= ~(E)(1 << i);
86 out += (!out.empty() ?
"+" :
"");
103inline std::string
ComposeName(E value, std::span<const std::string_view> names, std::string_view unknown_name)
106 if (value.base() == 0) {
109 for (
size_t i = 0; i < std::size(names); ++i) {
110 if (!value.Test(
static_cast<E::EnumType
>(i)))
continue;
111 out += (!out.empty() ?
"+" :
"");
113 value.Reset(
static_cast<E::EnumType
>(i));
115 if (value.base() != 0) {
116 out += (!out.empty() ?
"+" :
"");
144 if (
reinterpret_cast<size_t>(this->ptr) <
reinterpret_cast<size_t>(other.
ptr))
return true;
145 if (
reinterpret_cast<size_t>(this->ptr) >
reinterpret_cast<size_t>(other.
ptr))
return false;
146 if (this->type_id < other.
type_id)
return true;
161 std::optional<std::string>
FindKnownAsName(
size_t type_id,
const void *ptr);
173 format_append(this->output_buffer,
"{} = {}\n", name, value);
183 template <
typename E>
void WriteEnumT(std::string_view name, E e)
188 void BeginStruct(
size_t type_id, std::string_view name,
const void *ptr);
196 template <
typename S>
void WriteStructT(std::string_view name,
const S *s)
198 static const size_t type_id = this->
NewTypeId();
205 if (
auto known_as = this->
FindKnownAsName(type_id, s); known_as.has_value()) {
221 template <
typename S>
void WriteStructT(std::string_view name,
const std::deque<S> *s)
223 static const size_t type_id = this->
NewTypeId();
230 if (
auto known_as = this->
FindKnownAsName(type_id, s); known_as.has_value()) {
236 size_t num_items = s->size();
238 for (
size_t i = 0; i < num_items; i++) {
239 const auto &item = (*s)[i];
std::string ComposeName(E value, std::span< const std::string_view > names, std::string_view unknown_name, E invalid_index, std::string_view invalid_name)
Helper template function that returns compound bitfield name that is concatenation of names of each s...
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 ...
Different types to 'show' directions.
DiagDirection
Enumeration for diagonal directions.
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.
Trackdir
Enumeration for tracks and directions.
TrackdirBits
Allow incrementing of Trackdir variables.