OpenTTD Source 20260304-master-g1baaa74679
dbg_helpers.h File Reference

Functions to be used for debug printings. More...

#include <stack>
#include "../direction_type.h"
#include "../signal_type.h"
#include "../tile_type.h"
#include "../track_type.h"
#include "../core/format.hpp"

Go to the source code of this file.

Data Structures

struct  DumpTarget
 Class that represents the dump-into-string target. More...
struct  DumpTarget::KnownStructKey
 Used as a key into map of known object instances. More...

Functions

template<typename E>
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 of bounds.
template<typename E>
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)
 Helper template function that returns item of array at given index or invalid_name when index == invalid_index or unknown_name when index is out of bounds.
template<typename E>
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 set bit in the given value or invalid_name when index == invalid_index or unknown_name when index is out of bounds.
template<typename E>
std::string ComposeName (E value, std::span< const std::string_view > names, std::string_view unknown_name)
 Helper template function that returns compound bitfield name that is concatenation of names of each set bit in the given value or unknown_name when index is out of bounds.
std::string ValueStr (Trackdir td)
 Return name of given Trackdir.
std::string ValueStr (TrackdirBits td_bits)
 Return composed name of given TrackdirBits.
std::string ValueStr (DiagDirection dd)
 Return name of given DiagDirection.
std::string ValueStr (SignalType t)
 Return name of given SignalType.

Detailed Description

Functions to be used for debug printings.

Definition in file dbg_helpers.h.

Function Documentation

◆ ComposeName() [1/2]

template<typename E>
std::string ComposeName ( E value,
std::span< const std::string_view > names,
std::string_view unknown_name )
inline

Helper template function that returns compound bitfield name that is concatenation of names of each set bit in the given value or unknown_name when index is out of bounds.

Parameters
valueThe bitmask of values.
namesSpan of names to index.
unknown_nameThe default value when the index does not exist.
Returns
The composed name.

Definition at line 103 of file dbg_helpers.h.

◆ ComposeName() [2/2]

template<typename E>
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 )
inline

Helper template function that returns compound bitfield name that is concatenation of names of each set bit in the given value or invalid_name when index == invalid_index or unknown_name when index is out of bounds.

Parameters
valueThe bitmask of values.
namesSpan of names to index.
unknown_nameThe default value when the index does not exist.
invalid_indexThe invalid value to consider.
invalid_nameThe value to output when the invalid value is given.
Returns
The composed name.

Definition at line 71 of file dbg_helpers.h.

Referenced by ValueStr().

◆ ItemAt() [1/2]

template<typename E>
std::string_view ItemAt ( E idx,
std::span< const std::string_view > names,
std::string_view unknown_name )
inline

Helper template function that returns item of array at given index or unknown_name when index is out of bounds.

Parameters
idxThe index into the span.
namesSpan of names to index.
unknown_nameThe default value when the index does not exist.
Returns
The idx'th string of names, or unknown_name.

Definition at line 30 of file dbg_helpers.h.

Referenced by ItemAt(), ValueStr(), ValueStr(), and ValueStr().

◆ ItemAt() [2/2]

template<typename E>
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 )
inline

Helper template function that returns item of array at given index or invalid_name when index == invalid_index or unknown_name when index is out of bounds.

Parameters
idxThe index into the span.
namesSpan of names to index.
unknown_nameThe default value when the index does not exist.
invalid_indexThe invalid value to consider.
invalid_nameThe value to output when the invalid value is given.
Returns
The idx'th string of names, invalid_name, or unknown_name.

Definition at line 50 of file dbg_helpers.h.

References ItemAt().

◆ ValueStr() [1/4]

std::string ValueStr ( DiagDirection dd)

Return name of given DiagDirection.

Parameters
ddThe diagonal direction.
Returns
The string representation.

Definition at line 54 of file dbg_helpers.cpp.

References diagdir_names, INVALID_DIAGDIR, ItemAt(), and to_underlying().

◆ ValueStr() [2/4]

std::string ValueStr ( SignalType t)

Return name of given SignalType.

Parameters
tThe signal type.
Returns
The string representation.

Definition at line 70 of file dbg_helpers.cpp.

References ItemAt(), signal_type_names, and to_underlying().

◆ ValueStr() [3/4]

std::string ValueStr ( Trackdir td)

Return name of given Trackdir.

Parameters
tdThe track direction.
Returns
String representation of the track direction.

Definition at line 28 of file dbg_helpers.cpp.

References INVALID_TRACKDIR, ItemAt(), to_underlying(), and trackdir_names.

Referenced by DumpTarget::WriteEnumT().

◆ ValueStr() [4/4]

std::string ValueStr ( TrackdirBits td_bits)

Return composed name of given TrackdirBits.

Parameters
td_bitsThe track direction bits.
Returns
The string representation.

Definition at line 38 of file dbg_helpers.cpp.

References ComposeName(), INVALID_TRACKDIR_BIT, to_underlying(), and trackdir_names.