OpenTTD Source 20260218-master-g2123fca5ea
DumpTarget Struct Reference

Class that represents the dump-into-string target. More...

#include <dbg_helpers.h>

Data Structures

struct  KnownStructKey
 Used as a key into map of known object instances. More...

Public Types

using KnownNamesMap = std::map<KnownStructKey, std::string>
 Mapping of the KnownStructKey to the name for that structure.

Public Member Functions

std::string GetCurrentStructName ()
 Return structured name of the current class/structure.
std::optional< std::string > FindKnownAsName (size_t type_id, const void *ptr)
 Find the given instance in our anti-recursion repository.
void WriteIndent ()
 Write some leading spaces into the output.
void WriteValue (std::string_view name, const auto &value)
 Write 'name = value' with indent and new-line.
void WriteTile (std::string_view name, TileIndex t)
 Write name & TileIndex to the output.
template<typename E>
void WriteEnumT (std::string_view name, E e)
 Dump given enum value (as a number and as named value).
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 EndStruct ()
 Close structure '}<LF>'.
template<typename S>
void WriteStructT (std::string_view name, const S *s)
 Dump nested object (or only its name if this instance is already known).
template<typename S>
void WriteStructT (std::string_view name, const std::deque< S > *s)
 Dump nested object (or only its name if this instance is already known).

Static Public Member Functions

static size_t NewTypeId ()
 Create a new type_id.

Data Fields

std::string output_buffer
 The output string.
int indent = 0
 Current indent/nesting level.
std::stack< std::string > cur_struct
 Tracker of the current structure name.
KnownNamesMap known_names
 Map of known object instances and their structured names.

Detailed Description

Class that represents the dump-into-string target.

Definition at line 129 of file dbg_helpers.h.

Member Typedef Documentation

◆ KnownNamesMap

using DumpTarget::KnownNamesMap = std::map<KnownStructKey, std::string>

Mapping of the KnownStructKey to the name for that structure.

Definition at line 152 of file dbg_helpers.h.

Member Function Documentation

◆ BeginStruct()

void DumpTarget::BeginStruct ( size_t type_id,
std::string_view name,
const void * ptr )

Open new structure (one level deeper than the current one) 'name = {<LF>'.

Parameters
type_idIdentifier of the type being dumped.
nameThe name of the struct.
ptrThe content of the struct.

Definition at line 148 of file dbg_helpers.cpp.

References cur_struct, GetCurrentStructName(), indent, known_names, output_buffer, and WriteIndent().

Referenced by WriteStructT(), and WriteStructT().

◆ EndStruct()

void DumpTarget::EndStruct ( )

Close structure '}<LF>'.

Definition at line 172 of file dbg_helpers.cpp.

References cur_struct, indent, output_buffer, and WriteIndent().

Referenced by WriteStructT(), and WriteStructT().

◆ FindKnownAsName()

std::optional< std::string > DumpTarget::FindKnownAsName ( size_t type_id,
const void * ptr )

Find the given instance in our anti-recursion repository.

Parameters
type_idIdentifier of the type being dumped.
ptrThe content of the struct.
Returns
The name or std::nullopt when the type was not found.

Definition at line 114 of file dbg_helpers.cpp.

References known_names.

Referenced by WriteStructT(), and WriteStructT().

◆ GetCurrentStructName()

std::string DumpTarget::GetCurrentStructName ( )

Return structured name of the current class/structure.

Returns
The name of the current string.

Definition at line 100 of file dbg_helpers.cpp.

References cur_struct.

Referenced by BeginStruct().

◆ NewTypeId()

size_t DumpTarget::NewTypeId ( )
static

Create a new type_id.

Used for anti-recursion.

Returns
The new type_id.

Definition at line 90 of file dbg_helpers.cpp.

Referenced by WriteStructT(), and WriteStructT().

◆ WriteEnumT()

template<typename E>
void DumpTarget::WriteEnumT ( std::string_view name,
E e )
inline

Dump given enum value (as a number and as named value).

Parameters
nameThe name of the enumeration.
eThe value of the enumeration.

Definition at line 183 of file dbg_helpers.h.

References ValueStr(), and WriteValue().

◆ WriteIndent()

void DumpTarget::WriteIndent ( )

Write some leading spaces into the output.

Definition at line 123 of file dbg_helpers.cpp.

References indent, and output_buffer.

Referenced by BeginStruct(), EndStruct(), WriteTile(), and WriteValue().

◆ WriteStructT() [1/2]

template<typename S>
void DumpTarget::WriteStructT ( std::string_view name,
const S * s )
inline

Dump nested object (or only its name if this instance is already known).

Parameters
nameThe name of the struct.
sPointer to the struct.

Definition at line 196 of file dbg_helpers.h.

References BeginStruct(), EndStruct(), FindKnownAsName(), NewTypeId(), and WriteValue().

Referenced by WriteStructT().

◆ WriteStructT() [2/2]

template<typename S>
void DumpTarget::WriteStructT ( std::string_view name,
const std::deque< S > * s )
inline

Dump nested object (or only its name if this instance is already known).

Parameters
nameThe name of the struct.
sPointer to the std::deque of structs.

Definition at line 221 of file dbg_helpers.h.

References BeginStruct(), EndStruct(), FindKnownAsName(), NewTypeId(), WriteStructT(), and WriteValue().

◆ WriteTile()

void DumpTarget::WriteTile ( std::string_view name,
TileIndex tile )

Write name & TileIndex to the output.

Parameters
nameThe name to output.
tileThe tile to output.

Definition at line 136 of file dbg_helpers.cpp.

References output_buffer, TileStr(), and WriteIndent().

◆ WriteValue()

void DumpTarget::WriteValue ( std::string_view name,
const auto & value )
inline

Write 'name = value' with indent and new-line.

Parameters
nameThe name.
valueThe actual value to write.

Definition at line 170 of file dbg_helpers.h.

References WriteIndent().

Referenced by WriteEnumT(), WriteStructT(), and WriteStructT().

Field Documentation

◆ cur_struct

std::stack<std::string> DumpTarget::cur_struct

Tracker of the current structure name.

Definition at line 156 of file dbg_helpers.h.

Referenced by BeginStruct(), EndStruct(), and GetCurrentStructName().

◆ indent

int DumpTarget::indent = 0

Current indent/nesting level.

Definition at line 155 of file dbg_helpers.h.

Referenced by BeginStruct(), EndStruct(), and WriteIndent().

◆ known_names

KnownNamesMap DumpTarget::known_names

Map of known object instances and their structured names.

Definition at line 157 of file dbg_helpers.h.

Referenced by BeginStruct(), and FindKnownAsName().

◆ output_buffer

std::string DumpTarget::output_buffer

The output string.

Definition at line 154 of file dbg_helpers.h.

Referenced by BeginStruct(), EndStruct(), WriteIndent(), and WriteTile().


The documentation for this struct was generated from the following files: