OpenTTD Source
20240919-master-gdf0233f4c2
|
Go to the documentation of this file.
15 #include "../direction_type.h"
16 #include "../signal_type.h"
17 #include "../tile_type.h"
18 #include "../track_type.h"
24 template <
typename T,
size_t N>
struct ArrayT<T[N]> {
25 static const size_t length = N;
34 template <
typename E,
typename T>
48 template <
typename E,
typename T>
66 template <
typename E,
typename T>
67 inline std::string
ComposeNameT(E value, T &t,
const char *t_unk, E val_inv,
const char *name_inv)
70 if (value == val_inv) {
72 }
else if (value == 0) {
75 for (
size_t i = 0; i < ArrayT<T>::length; i++) {
76 if ((value & (1 << i)) == 0)
continue;
77 out += (!out.empty() ?
"+" :
"");
79 value &= ~(E)(1 << i);
82 out += (!out.empty() ?
"+" :
"");
109 if ((
size_t)m_ptr < (
size_t)other.m_ptr)
return true;
110 if ((
size_t)m_ptr > (
size_t)other.m_ptr)
return false;
111 if (m_type_id < other.m_type_id)
return true;
116 typedef std::map<KnownStructKey, std::string> KNOWN_NAMES;
129 bool FindKnownName(
size_t type_id,
const void *ptr, std::string &name);
133 void WriteValue(
const std::string &name,
int value);
134 void WriteValue(
const std::string &name,
const std::string &value_str);
138 template <
typename E>
void WriteEnumT(
const std::string &name, E e)
143 void BeginStruct(
size_t type_id,
const std::string &name,
const void *ptr);
147 template <
typename S>
void WriteStructT(
const std::string &name,
const S *s)
156 std::string known_as;
159 std::string known_as_str = std::string(
"known_as.") + name;
170 template <
typename S>
void WriteStructT(
const std::string &name,
const std::deque<S> *s)
179 std::string known_as;
182 std::string known_as_str = std::string(
"known_as.") + name;
187 size_t num_items = s->size();
188 this->
WriteValue(
"num_items", std::to_string(num_items));
189 for (
size_t i = 0; i < num_items; i++) {
190 const auto &item = (*s)[i];
bool FindKnownName(size_t type_id, const void *ptr, std::string &name)
Find the given instance in our anti-recursion repository.
static size_t & LastTypeId()
Keep track of the last assigned type_id.
std::string ComposeNameT(E value, T &t, const char *t_unk, E val_inv, const char *name_inv)
Helper template function that returns compound bitfield name that is concatenation of names of each s...
void WriteIndent()
Write some leading spaces into the output.
void EndStruct()
Close structure '}<LF>'.
std::string GetCurrentStructName()
Return structured name of the current class/structure.
DiagDirection
Enumeration for diagonal directions.
KNOWN_NAMES m_known_names
map of known object instances and their structured names
Used as a key into map of known object instances.
std::stack< std::string > m_cur_struct
here we will track the current structure name
std::string ValueStr(Trackdir td)
Return name of given Trackdir.
void WriteStructT(const std::string &name, const S *s)
Dump nested object (or only its name if this instance is already known).
Helper template class that provides C array length and item type.
int m_indent
current indent/nesting level
void WriteStructT(const std::string &name, const std::deque< S > *s)
Dump nested object (or only its name if this instance is already known).
Class that represents the dump-into-string target.
void WriteTile(const std::string &name, TileIndex t)
Write name & TileIndex to the output.
void BeginStruct(size_t type_id, const std::string &name, const void *ptr)
Open new structure (one level deeper than the current one) 'name = {<LF>'.
void WriteEnumT(const std::string &name, E e)
Dump given enum value (as a number and as named value)
Trackdir
Enumeration for tracks and directions.
std::string m_out
the output string
ArrayT< T >::Item ItemAtT(E idx, const T &t, typename ArrayT< T >::Item t_unk)
Helper template function that returns item of array at given index or t_unk when index is out of boun...
SignalType
Type of signal, i.e.
TrackdirBits
Allow incrementing of Trackdir variables.
void WriteValue(const std::string &name, int value)
Write 'name = value' with indent and new-line.