OpenTTD Source: DumpTarget Struct Reference

OpenTTD Source 15.3

Data Structures | Public Types | Public Member Functions | Static Public Member Functions | Data Fields
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
typedef std::map< KnownStructKey, std::string > | KNOWN_NAMES

## Public Member Functions
std::string | GetCurrentStructName ()
| Return structured name of the current class/structure.
bool | FindKnownName (size_t type_id, const void *ptr, std::string &name)
| 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 & | LastTypeId ()
| Keep track of the last assigned type_id.

## Data Fields
std::string | m_out
| the output string
int | m_indent
| current indent/nesting level
std::stack< std::string > | m_cur_struct
| here we will track the current structure name
KNOWN_NAMES | m_known_names
| map of known object instances and their structured names

## Detailed Description

Class that represents the dump-into-string target.

Definition at line 109 of file dbg_helpers.h.

## Member Typedef Documentation

## ◆ KNOWN_NAMES

typedef std::map<KnownStructKey, std::string> DumpTarget::KNOWN_NAMES

Definition at line 130 of file dbg_helpers.h.

## Constructor & Destructor Documentation

## ◆ DumpTarget()

DumpTarget::DumpTarget | ( |  | ) |
| inline

Definition at line 137 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>'.

Definition at line 119 of file dbg_helpers.cpp.

References GetCurrentStructName(), m_cur_struct, m_indent, m_known_names, m_out, and WriteIndent().

Referenced by WriteStructT(), and WriteStructT().

## ◆ EndStruct()

void DumpTarget::EndStruct | ( |  | ) |

Close structure '}<LF>'.

Definition at line 143 of file dbg_helpers.cpp.

References m_cur_struct, m_indent, m_out, and WriteIndent().

Referenced by WriteStructT(), and WriteStructT().

## ◆ FindKnownName()

bool DumpTarget::FindKnownName | ( | size_t | type_id,
|  | const void * | ptr,
|  | std::string & | name
| ) |  |

Find the given instance in our anti-recursion repository.

Return true and set name when object was found.

Definition at line 89 of file dbg_helpers.cpp.

References m_known_names.

Referenced by WriteStructT(), and WriteStructT().

## ◆ GetCurrentStructName()

std::string DumpTarget::GetCurrentStructName | ( |  | ) |

Return structured name of the current class/structure.

Definition at line 75 of file dbg_helpers.cpp.

References m_cur_struct.

Referenced by BeginStruct().

## ◆ LastTypeId()

size_t & DumpTarget::LastTypeId | ( |  | ) |
| static

Keep track of the last assigned type_id.

Used for anti-recursion. static

Definition at line 68 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)

Definition at line 157 of file dbg_helpers.h.

References ValueStr(), and WriteValue().

## ◆ WriteIndent()

void DumpTarget::WriteIndent | ( |  | ) |

Write some leading spaces into the output.

Definition at line 101 of file dbg_helpers.cpp.

References m_indent, and m_out.

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).

Definition at line 166 of file dbg_helpers.h.

References BeginStruct(), EndStruct(), FindKnownName(), LastTypeId(), 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).

Definition at line 189 of file dbg_helpers.h.

References BeginStruct(), EndStruct(), FindKnownName(), LastTypeId(), WriteStructT(), and WriteValue().

## ◆ WriteTile()

void DumpTarget::WriteTile | ( | std::string_view | name,
|  | TileIndex | t
| ) |  |

Write name & TileIndex to the output.

Definition at line 110 of file dbg_helpers.cpp.

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

## ◆ WriteValue()

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

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

Definition at line 148 of file dbg_helpers.h.

References m_out, and WriteIndent().

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

## Field Documentation

## ◆ m_cur_struct

std::stack<std::string> DumpTarget::m_cur_struct

here we will track the current structure name

Definition at line 134 of file dbg_helpers.h.

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

## ◆ m_indent

int DumpTarget::m_indent

current indent/nesting level

Definition at line 133 of file dbg_helpers.h.

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

## ◆ m_known_names

KNOWN_NAMES DumpTarget::m_known_names

map of known object instances and their structured names

Definition at line 135 of file dbg_helpers.h.

Referenced by BeginStruct(), and FindKnownName().

## ◆ m_out

std::string DumpTarget::m_out

the output string

Definition at line 132 of file dbg_helpers.h.

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

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

- src/misc/dbg_helpers.h
- src/misc/dbg_helpers.cpp