15#include "../direction_type.h"
16#include "../signal_type.h"
17#include "../tile_type.h"
18#include "../track_type.h"
19#include "../core/format.hpp"
26inline std::string_view
ItemAt(E idx, std::span<const std::string_view> t, std::string_view t_unk)
28 if (
static_cast<size_t>(idx) >= std::size(t)) {
40inline std::string_view
ItemAt(E idx, std::span<const std::string_view> t, std::string_view t_unk, E idx_inv, std::string_view t_inv)
45 return ItemAt(idx, t, t_unk);
55inline std::string
ComposeName(E value, std::span<const std::string_view> t, std::string_view t_unk, E val_inv, std::string_view name_inv)
58 if (value == val_inv) {
60 }
else if (value == 0) {
63 for (
size_t i = 0; i < std::size(t); i++) {
64 if ((value & (1 << i)) == 0)
continue;
65 out += (!out.empty() ?
"+" :
"");
67 value &= ~(E)(1 << i);
70 out += (!out.empty() ?
"+" :
"");
83inline std::string
ComposeName(E value, std::span<const std::string_view> names, std::string_view unknown_name)
86 if (value.base() == 0) {
89 for (
size_t i = 0; i < std::size(names); ++i) {
90 if (!value.Test(
static_cast<E::EnumType
>(i)))
continue;
91 out += (!out.empty() ?
"+" :
"");
93 value.Reset(
static_cast<E::EnumType
>(i));
95 if (value.base() != 0) {
96 out += (!out.empty() ?
"+" :
"");
123 if ((
size_t)m_ptr < (
size_t)other.m_ptr)
return true;
124 if ((
size_t)m_ptr > (
size_t)other.m_ptr)
return false;
125 if (m_type_id < other.m_type_id)
return true;
130 typedef std::map<KnownStructKey, std::string> KNOWN_NAMES;
143 bool FindKnownName(
size_t type_id,
const void *ptr, std::string &name);
151 format_append(
m_out,
"{} = {}\n", name, value);
157 template <
typename E>
void WriteEnumT(std::string_view name, E e)
162 void BeginStruct(
size_t type_id, std::string_view name,
const void *ptr);
166 template <
typename S>
void WriteStructT(std::string_view name,
const S *s)
175 std::string known_as;
178 std::string known_as_str = std::string(
"known_as.") + known_as;
189 template <
typename S>
void WriteStructT(std::string_view name,
const std::deque<S> *s)
198 std::string known_as;
201 std::string known_as_str = std::string(
"known_as.") + known_as;
206 size_t num_items = s->size();
208 for (
size_t i = 0; i < num_items; i++) {
209 const auto &item = (*s)[i];
std::string ComposeName(E value, std::span< const std::string_view > t, std::string_view t_unk, E val_inv, std::string_view name_inv)
Helper template function that returns compound bitfield name that is concatenation of names of each s...
std::string_view ItemAt(E idx, std::span< const std::string_view > t, std::string_view t_unk)
Helper template function that returns item of array at given index or t_unk when index is out of boun...
std::string ValueStr(Trackdir td)
Return name of given Trackdir.
DiagDirection
Enumeration for diagonal directions.
SignalType
Type of signal, i.e.
Used as a key into map of known object instances.
Class that represents the dump-into-string target.
int m_indent
current indent/nesting level
std::string m_out
the output string
void WriteTile(std::string_view name, TileIndex t)
Write name & TileIndex to the output.
std::stack< std::string > m_cur_struct
here we will track the current structure name
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>'.
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.
void WriteStructT(std::string_view name, const S *s)
Dump nested object (or only its name if this instance is already known).
KNOWN_NAMES m_known_names
map of known object instances and their structured names
bool FindKnownName(size_t type_id, const void *ptr, std::string &name)
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.
static size_t & LastTypeId()
Keep track of the last assigned type_id.
void EndStruct()
Close structure '}<LF>'.
void WriteValue(std::string_view name, const auto &value)
Write 'name = value' with indent and new-line.
Trackdir
Enumeration for tracks and directions.
TrackdirBits
Allow incrementing of Trackdir variables.