src/misc/dbg_helpers.h
author Tero Marttila <terom@fixme.fi>
Tue, 22 Jul 2008 21:51:14 +0300
changeset 11180 982e9f814f97
parent 10429 1b99254f9607
permissions -rw-r--r--
scan for tarfiles in CACHE_DIR, remember what Subdirectory a tar was found in, set the GCF_FLAG on GRFs loaded from there, and hide those in the NewGRF GUI
7618
99822745fcfd (svn r10395) -Fix [YAPF]: missing include + some signed/unsigned comparison warnings
KUDr
parents: 7614
diff changeset
     1
/* $Id$ */
7614
a70f01c9eb57 (svn r10391) -Add: debug support - structured dump of variables/classes/structures (with anti-recursion repository) into string
KUDr
parents:
diff changeset
     2
10429
1b99254f9607 (svn r12971) -Documentation: add @file in files that missed them and add something more than whitespace as description of files that don't have a description.
rubidium
parents: 7618
diff changeset
     3
/** @file dbg_helpers.h Functions to be used for debug printings. */
7614
a70f01c9eb57 (svn r10391) -Add: debug support - structured dump of variables/classes/structures (with anti-recursion repository) into string
KUDr
parents:
diff changeset
     4
a70f01c9eb57 (svn r10391) -Add: debug support - structured dump of variables/classes/structures (with anti-recursion repository) into string
KUDr
parents:
diff changeset
     5
#ifndef DBG_HELPERS
a70f01c9eb57 (svn r10391) -Add: debug support - structured dump of variables/classes/structures (with anti-recursion repository) into string
KUDr
parents:
diff changeset
     6
#define DBG_HELPERS
a70f01c9eb57 (svn r10391) -Add: debug support - structured dump of variables/classes/structures (with anti-recursion repository) into string
KUDr
parents:
diff changeset
     7
a70f01c9eb57 (svn r10391) -Add: debug support - structured dump of variables/classes/structures (with anti-recursion repository) into string
KUDr
parents:
diff changeset
     8
#include <new>
a70f01c9eb57 (svn r10391) -Add: debug support - structured dump of variables/classes/structures (with anti-recursion repository) into string
KUDr
parents:
diff changeset
     9
#include <map>
a70f01c9eb57 (svn r10391) -Add: debug support - structured dump of variables/classes/structures (with anti-recursion repository) into string
KUDr
parents:
diff changeset
    10
#include <stack>
a70f01c9eb57 (svn r10391) -Add: debug support - structured dump of variables/classes/structures (with anti-recursion repository) into string
KUDr
parents:
diff changeset
    11
a70f01c9eb57 (svn r10391) -Add: debug support - structured dump of variables/classes/structures (with anti-recursion repository) into string
KUDr
parents:
diff changeset
    12
#include "blob.hpp"
a70f01c9eb57 (svn r10391) -Add: debug support - structured dump of variables/classes/structures (with anti-recursion repository) into string
KUDr
parents:
diff changeset
    13
#include "str.hpp"
a70f01c9eb57 (svn r10391) -Add: debug support - structured dump of variables/classes/structures (with anti-recursion repository) into string
KUDr
parents:
diff changeset
    14
a70f01c9eb57 (svn r10391) -Add: debug support - structured dump of variables/classes/structures (with anti-recursion repository) into string
KUDr
parents:
diff changeset
    15
/** Helper template class that provides C array length and item type */
a70f01c9eb57 (svn r10391) -Add: debug support - structured dump of variables/classes/structures (with anti-recursion repository) into string
KUDr
parents:
diff changeset
    16
template <typename T> struct ArrayT;
a70f01c9eb57 (svn r10391) -Add: debug support - structured dump of variables/classes/structures (with anti-recursion repository) into string
KUDr
parents:
diff changeset
    17
a70f01c9eb57 (svn r10391) -Add: debug support - structured dump of variables/classes/structures (with anti-recursion repository) into string
KUDr
parents:
diff changeset
    18
/** Helper template class that provides C array length and item type */
a70f01c9eb57 (svn r10391) -Add: debug support - structured dump of variables/classes/structures (with anti-recursion repository) into string
KUDr
parents:
diff changeset
    19
template <typename T, size_t N> struct ArrayT<T[N]> {
a70f01c9eb57 (svn r10391) -Add: debug support - structured dump of variables/classes/structures (with anti-recursion repository) into string
KUDr
parents:
diff changeset
    20
	static const size_t length = N;
a70f01c9eb57 (svn r10391) -Add: debug support - structured dump of variables/classes/structures (with anti-recursion repository) into string
KUDr
parents:
diff changeset
    21
	typedef T item_t;
a70f01c9eb57 (svn r10391) -Add: debug support - structured dump of variables/classes/structures (with anti-recursion repository) into string
KUDr
parents:
diff changeset
    22
};
a70f01c9eb57 (svn r10391) -Add: debug support - structured dump of variables/classes/structures (with anti-recursion repository) into string
KUDr
parents:
diff changeset
    23
a70f01c9eb57 (svn r10391) -Add: debug support - structured dump of variables/classes/structures (with anti-recursion repository) into string
KUDr
parents:
diff changeset
    24
a70f01c9eb57 (svn r10391) -Add: debug support - structured dump of variables/classes/structures (with anti-recursion repository) into string
KUDr
parents:
diff changeset
    25
/**
a70f01c9eb57 (svn r10391) -Add: debug support - structured dump of variables/classes/structures (with anti-recursion repository) into string
KUDr
parents:
diff changeset
    26
* Helper template function that returns item of array at given index
a70f01c9eb57 (svn r10391) -Add: debug support - structured dump of variables/classes/structures (with anti-recursion repository) into string
KUDr
parents:
diff changeset
    27
* or t_unk when index is out of bounds.
a70f01c9eb57 (svn r10391) -Add: debug support - structured dump of variables/classes/structures (with anti-recursion repository) into string
KUDr
parents:
diff changeset
    28
*/
a70f01c9eb57 (svn r10391) -Add: debug support - structured dump of variables/classes/structures (with anti-recursion repository) into string
KUDr
parents:
diff changeset
    29
template <typename E, typename T>
a70f01c9eb57 (svn r10391) -Add: debug support - structured dump of variables/classes/structures (with anti-recursion repository) into string
KUDr
parents:
diff changeset
    30
inline typename ArrayT<T>::item_t ItemAtT(E idx, T &t, typename ArrayT<T>::item_t t_unk)
a70f01c9eb57 (svn r10391) -Add: debug support - structured dump of variables/classes/structures (with anti-recursion repository) into string
KUDr
parents:
diff changeset
    31
{
a70f01c9eb57 (svn r10391) -Add: debug support - structured dump of variables/classes/structures (with anti-recursion repository) into string
KUDr
parents:
diff changeset
    32
	if ((size_t)idx >= ArrayT<T>::length) {
a70f01c9eb57 (svn r10391) -Add: debug support - structured dump of variables/classes/structures (with anti-recursion repository) into string
KUDr
parents:
diff changeset
    33
		return t_unk;
a70f01c9eb57 (svn r10391) -Add: debug support - structured dump of variables/classes/structures (with anti-recursion repository) into string
KUDr
parents:
diff changeset
    34
	}
a70f01c9eb57 (svn r10391) -Add: debug support - structured dump of variables/classes/structures (with anti-recursion repository) into string
KUDr
parents:
diff changeset
    35
	return t[idx];
a70f01c9eb57 (svn r10391) -Add: debug support - structured dump of variables/classes/structures (with anti-recursion repository) into string
KUDr
parents:
diff changeset
    36
}
a70f01c9eb57 (svn r10391) -Add: debug support - structured dump of variables/classes/structures (with anti-recursion repository) into string
KUDr
parents:
diff changeset
    37
a70f01c9eb57 (svn r10391) -Add: debug support - structured dump of variables/classes/structures (with anti-recursion repository) into string
KUDr
parents:
diff changeset
    38
/**
a70f01c9eb57 (svn r10391) -Add: debug support - structured dump of variables/classes/structures (with anti-recursion repository) into string
KUDr
parents:
diff changeset
    39
* Helper template function that returns item of array at given index
a70f01c9eb57 (svn r10391) -Add: debug support - structured dump of variables/classes/structures (with anti-recursion repository) into string
KUDr
parents:
diff changeset
    40
* or t_inv when index == idx_inv
a70f01c9eb57 (svn r10391) -Add: debug support - structured dump of variables/classes/structures (with anti-recursion repository) into string
KUDr
parents:
diff changeset
    41
* or t_unk when index is out of bounds.
a70f01c9eb57 (svn r10391) -Add: debug support - structured dump of variables/classes/structures (with anti-recursion repository) into string
KUDr
parents:
diff changeset
    42
*/
a70f01c9eb57 (svn r10391) -Add: debug support - structured dump of variables/classes/structures (with anti-recursion repository) into string
KUDr
parents:
diff changeset
    43
template <typename E, typename T>
a70f01c9eb57 (svn r10391) -Add: debug support - structured dump of variables/classes/structures (with anti-recursion repository) into string
KUDr
parents:
diff changeset
    44
inline typename ArrayT<T>::item_t ItemAtT(E idx, T &t, typename ArrayT<T>::item_t t_unk, E idx_inv, typename ArrayT<T>::item_t t_inv)
a70f01c9eb57 (svn r10391) -Add: debug support - structured dump of variables/classes/structures (with anti-recursion repository) into string
KUDr
parents:
diff changeset
    45
{
a70f01c9eb57 (svn r10391) -Add: debug support - structured dump of variables/classes/structures (with anti-recursion repository) into string
KUDr
parents:
diff changeset
    46
	if ((size_t)idx < ArrayT<T>::length) {
a70f01c9eb57 (svn r10391) -Add: debug support - structured dump of variables/classes/structures (with anti-recursion repository) into string
KUDr
parents:
diff changeset
    47
		return t[idx];
a70f01c9eb57 (svn r10391) -Add: debug support - structured dump of variables/classes/structures (with anti-recursion repository) into string
KUDr
parents:
diff changeset
    48
	}
a70f01c9eb57 (svn r10391) -Add: debug support - structured dump of variables/classes/structures (with anti-recursion repository) into string
KUDr
parents:
diff changeset
    49
	if (idx == idx_inv) {
a70f01c9eb57 (svn r10391) -Add: debug support - structured dump of variables/classes/structures (with anti-recursion repository) into string
KUDr
parents:
diff changeset
    50
		return t_inv;
a70f01c9eb57 (svn r10391) -Add: debug support - structured dump of variables/classes/structures (with anti-recursion repository) into string
KUDr
parents:
diff changeset
    51
	}
a70f01c9eb57 (svn r10391) -Add: debug support - structured dump of variables/classes/structures (with anti-recursion repository) into string
KUDr
parents:
diff changeset
    52
	return t_unk;
a70f01c9eb57 (svn r10391) -Add: debug support - structured dump of variables/classes/structures (with anti-recursion repository) into string
KUDr
parents:
diff changeset
    53
}
a70f01c9eb57 (svn r10391) -Add: debug support - structured dump of variables/classes/structures (with anti-recursion repository) into string
KUDr
parents:
diff changeset
    54
a70f01c9eb57 (svn r10391) -Add: debug support - structured dump of variables/classes/structures (with anti-recursion repository) into string
KUDr
parents:
diff changeset
    55
/**
a70f01c9eb57 (svn r10391) -Add: debug support - structured dump of variables/classes/structures (with anti-recursion repository) into string
KUDr
parents:
diff changeset
    56
* Helper template function that returns compound bitfield name that is
a70f01c9eb57 (svn r10391) -Add: debug support - structured dump of variables/classes/structures (with anti-recursion repository) into string
KUDr
parents:
diff changeset
    57
* concatenation of names of each set bit in the given value
a70f01c9eb57 (svn r10391) -Add: debug support - structured dump of variables/classes/structures (with anti-recursion repository) into string
KUDr
parents:
diff changeset
    58
* or t_inv when index == idx_inv
a70f01c9eb57 (svn r10391) -Add: debug support - structured dump of variables/classes/structures (with anti-recursion repository) into string
KUDr
parents:
diff changeset
    59
* or t_unk when index is out of bounds.
a70f01c9eb57 (svn r10391) -Add: debug support - structured dump of variables/classes/structures (with anti-recursion repository) into string
KUDr
parents:
diff changeset
    60
*/
a70f01c9eb57 (svn r10391) -Add: debug support - structured dump of variables/classes/structures (with anti-recursion repository) into string
KUDr
parents:
diff changeset
    61
template <typename E, typename T>
a70f01c9eb57 (svn r10391) -Add: debug support - structured dump of variables/classes/structures (with anti-recursion repository) into string
KUDr
parents:
diff changeset
    62
inline CStrA ComposeNameT(E value, T &t, const char* t_unk, E val_inv, const char* name_inv)
a70f01c9eb57 (svn r10391) -Add: debug support - structured dump of variables/classes/structures (with anti-recursion repository) into string
KUDr
parents:
diff changeset
    63
{
a70f01c9eb57 (svn r10391) -Add: debug support - structured dump of variables/classes/structures (with anti-recursion repository) into string
KUDr
parents:
diff changeset
    64
	CStrA out;
a70f01c9eb57 (svn r10391) -Add: debug support - structured dump of variables/classes/structures (with anti-recursion repository) into string
KUDr
parents:
diff changeset
    65
	if (value == val_inv) {
a70f01c9eb57 (svn r10391) -Add: debug support - structured dump of variables/classes/structures (with anti-recursion repository) into string
KUDr
parents:
diff changeset
    66
		out = name_inv;
a70f01c9eb57 (svn r10391) -Add: debug support - structured dump of variables/classes/structures (with anti-recursion repository) into string
KUDr
parents:
diff changeset
    67
	} else if (value == 0) {
a70f01c9eb57 (svn r10391) -Add: debug support - structured dump of variables/classes/structures (with anti-recursion repository) into string
KUDr
parents:
diff changeset
    68
		out = "<none>";
a70f01c9eb57 (svn r10391) -Add: debug support - structured dump of variables/classes/structures (with anti-recursion repository) into string
KUDr
parents:
diff changeset
    69
	} else {
7618
99822745fcfd (svn r10395) -Fix [YAPF]: missing include + some signed/unsigned comparison warnings
KUDr
parents: 7614
diff changeset
    70
		for (size_t i = 0; i < ArrayT<T>::length; i++) {
7614
a70f01c9eb57 (svn r10391) -Add: debug support - structured dump of variables/classes/structures (with anti-recursion repository) into string
KUDr
parents:
diff changeset
    71
			if ((value & (1 << i)) == 0) continue;
a70f01c9eb57 (svn r10391) -Add: debug support - structured dump of variables/classes/structures (with anti-recursion repository) into string
KUDr
parents:
diff changeset
    72
			out.AddFormat("%s%s", (out.Size() > 0 ? "+" : ""), t[i]);
a70f01c9eb57 (svn r10391) -Add: debug support - structured dump of variables/classes/structures (with anti-recursion repository) into string
KUDr
parents:
diff changeset
    73
			value &= ~(E)(1 << i);
a70f01c9eb57 (svn r10391) -Add: debug support - structured dump of variables/classes/structures (with anti-recursion repository) into string
KUDr
parents:
diff changeset
    74
		}
a70f01c9eb57 (svn r10391) -Add: debug support - structured dump of variables/classes/structures (with anti-recursion repository) into string
KUDr
parents:
diff changeset
    75
		if (value != 0) out.AddFormat("%s%s", (out.Size() > 0 ? "+" : ""), t_unk);
a70f01c9eb57 (svn r10391) -Add: debug support - structured dump of variables/classes/structures (with anti-recursion repository) into string
KUDr
parents:
diff changeset
    76
	}
a70f01c9eb57 (svn r10391) -Add: debug support - structured dump of variables/classes/structures (with anti-recursion repository) into string
KUDr
parents:
diff changeset
    77
	return out.Transfer();
a70f01c9eb57 (svn r10391) -Add: debug support - structured dump of variables/classes/structures (with anti-recursion repository) into string
KUDr
parents:
diff changeset
    78
}
a70f01c9eb57 (svn r10391) -Add: debug support - structured dump of variables/classes/structures (with anti-recursion repository) into string
KUDr
parents:
diff changeset
    79
a70f01c9eb57 (svn r10391) -Add: debug support - structured dump of variables/classes/structures (with anti-recursion repository) into string
KUDr
parents:
diff changeset
    80
CStrA ValueStr(Trackdir td);
a70f01c9eb57 (svn r10391) -Add: debug support - structured dump of variables/classes/structures (with anti-recursion repository) into string
KUDr
parents:
diff changeset
    81
CStrA ValueStr(TrackdirBits td_bits);
a70f01c9eb57 (svn r10391) -Add: debug support - structured dump of variables/classes/structures (with anti-recursion repository) into string
KUDr
parents:
diff changeset
    82
CStrA ValueStr(DiagDirection dd);
a70f01c9eb57 (svn r10391) -Add: debug support - structured dump of variables/classes/structures (with anti-recursion repository) into string
KUDr
parents:
diff changeset
    83
CStrA ValueStr(SignalType t);
a70f01c9eb57 (svn r10391) -Add: debug support - structured dump of variables/classes/structures (with anti-recursion repository) into string
KUDr
parents:
diff changeset
    84
a70f01c9eb57 (svn r10391) -Add: debug support - structured dump of variables/classes/structures (with anti-recursion repository) into string
KUDr
parents:
diff changeset
    85
/** Class that represents the dump-into-string target. */
a70f01c9eb57 (svn r10391) -Add: debug support - structured dump of variables/classes/structures (with anti-recursion repository) into string
KUDr
parents:
diff changeset
    86
struct DumpTarget {
a70f01c9eb57 (svn r10391) -Add: debug support - structured dump of variables/classes/structures (with anti-recursion repository) into string
KUDr
parents:
diff changeset
    87
a70f01c9eb57 (svn r10391) -Add: debug support - structured dump of variables/classes/structures (with anti-recursion repository) into string
KUDr
parents:
diff changeset
    88
	/** Used as a key into map of known object instances. */
a70f01c9eb57 (svn r10391) -Add: debug support - structured dump of variables/classes/structures (with anti-recursion repository) into string
KUDr
parents:
diff changeset
    89
	struct KnownStructKey {
a70f01c9eb57 (svn r10391) -Add: debug support - structured dump of variables/classes/structures (with anti-recursion repository) into string
KUDr
parents:
diff changeset
    90
		size_t      m_type_id;
a70f01c9eb57 (svn r10391) -Add: debug support - structured dump of variables/classes/structures (with anti-recursion repository) into string
KUDr
parents:
diff changeset
    91
		const void *m_ptr;
a70f01c9eb57 (svn r10391) -Add: debug support - structured dump of variables/classes/structures (with anti-recursion repository) into string
KUDr
parents:
diff changeset
    92
a70f01c9eb57 (svn r10391) -Add: debug support - structured dump of variables/classes/structures (with anti-recursion repository) into string
KUDr
parents:
diff changeset
    93
		KnownStructKey(size_t type_id, const void *ptr)
a70f01c9eb57 (svn r10391) -Add: debug support - structured dump of variables/classes/structures (with anti-recursion repository) into string
KUDr
parents:
diff changeset
    94
			: m_type_id(type_id)
a70f01c9eb57 (svn r10391) -Add: debug support - structured dump of variables/classes/structures (with anti-recursion repository) into string
KUDr
parents:
diff changeset
    95
			, m_ptr(ptr)
a70f01c9eb57 (svn r10391) -Add: debug support - structured dump of variables/classes/structures (with anti-recursion repository) into string
KUDr
parents:
diff changeset
    96
		{}
a70f01c9eb57 (svn r10391) -Add: debug support - structured dump of variables/classes/structures (with anti-recursion repository) into string
KUDr
parents:
diff changeset
    97
a70f01c9eb57 (svn r10391) -Add: debug support - structured dump of variables/classes/structures (with anti-recursion repository) into string
KUDr
parents:
diff changeset
    98
		KnownStructKey(const KnownStructKey &src)
a70f01c9eb57 (svn r10391) -Add: debug support - structured dump of variables/classes/structures (with anti-recursion repository) into string
KUDr
parents:
diff changeset
    99
		{
a70f01c9eb57 (svn r10391) -Add: debug support - structured dump of variables/classes/structures (with anti-recursion repository) into string
KUDr
parents:
diff changeset
   100
			m_type_id = src.m_type_id;
a70f01c9eb57 (svn r10391) -Add: debug support - structured dump of variables/classes/structures (with anti-recursion repository) into string
KUDr
parents:
diff changeset
   101
			m_ptr = src.m_ptr;
a70f01c9eb57 (svn r10391) -Add: debug support - structured dump of variables/classes/structures (with anti-recursion repository) into string
KUDr
parents:
diff changeset
   102
		}
a70f01c9eb57 (svn r10391) -Add: debug support - structured dump of variables/classes/structures (with anti-recursion repository) into string
KUDr
parents:
diff changeset
   103
a70f01c9eb57 (svn r10391) -Add: debug support - structured dump of variables/classes/structures (with anti-recursion repository) into string
KUDr
parents:
diff changeset
   104
		bool operator < (const KnownStructKey &other) const
a70f01c9eb57 (svn r10391) -Add: debug support - structured dump of variables/classes/structures (with anti-recursion repository) into string
KUDr
parents:
diff changeset
   105
		{
a70f01c9eb57 (svn r10391) -Add: debug support - structured dump of variables/classes/structures (with anti-recursion repository) into string
KUDr
parents:
diff changeset
   106
			if ((size_t)m_ptr < (size_t)other.m_ptr) return true;
a70f01c9eb57 (svn r10391) -Add: debug support - structured dump of variables/classes/structures (with anti-recursion repository) into string
KUDr
parents:
diff changeset
   107
			if ((size_t)m_ptr > (size_t)other.m_ptr) return false;
a70f01c9eb57 (svn r10391) -Add: debug support - structured dump of variables/classes/structures (with anti-recursion repository) into string
KUDr
parents:
diff changeset
   108
			if (m_type_id < other.m_type_id) return true;
a70f01c9eb57 (svn r10391) -Add: debug support - structured dump of variables/classes/structures (with anti-recursion repository) into string
KUDr
parents:
diff changeset
   109
			return false;
a70f01c9eb57 (svn r10391) -Add: debug support - structured dump of variables/classes/structures (with anti-recursion repository) into string
KUDr
parents:
diff changeset
   110
		}
a70f01c9eb57 (svn r10391) -Add: debug support - structured dump of variables/classes/structures (with anti-recursion repository) into string
KUDr
parents:
diff changeset
   111
	};
a70f01c9eb57 (svn r10391) -Add: debug support - structured dump of variables/classes/structures (with anti-recursion repository) into string
KUDr
parents:
diff changeset
   112
a70f01c9eb57 (svn r10391) -Add: debug support - structured dump of variables/classes/structures (with anti-recursion repository) into string
KUDr
parents:
diff changeset
   113
	typedef std::map<KnownStructKey, CStrA> KNOWN_NAMES;
a70f01c9eb57 (svn r10391) -Add: debug support - structured dump of variables/classes/structures (with anti-recursion repository) into string
KUDr
parents:
diff changeset
   114
a70f01c9eb57 (svn r10391) -Add: debug support - structured dump of variables/classes/structures (with anti-recursion repository) into string
KUDr
parents:
diff changeset
   115
	CStrA              m_out;         ///< the output string
a70f01c9eb57 (svn r10391) -Add: debug support - structured dump of variables/classes/structures (with anti-recursion repository) into string
KUDr
parents:
diff changeset
   116
	int                m_indent;      ///< current indent/nesting level
a70f01c9eb57 (svn r10391) -Add: debug support - structured dump of variables/classes/structures (with anti-recursion repository) into string
KUDr
parents:
diff changeset
   117
	std::stack<CStrA>  m_cur_struct;  ///< here we will track the current structure name
a70f01c9eb57 (svn r10391) -Add: debug support - structured dump of variables/classes/structures (with anti-recursion repository) into string
KUDr
parents:
diff changeset
   118
	KNOWN_NAMES        m_known_names; ///< map of known object instances and their structured names
a70f01c9eb57 (svn r10391) -Add: debug support - structured dump of variables/classes/structures (with anti-recursion repository) into string
KUDr
parents:
diff changeset
   119
a70f01c9eb57 (svn r10391) -Add: debug support - structured dump of variables/classes/structures (with anti-recursion repository) into string
KUDr
parents:
diff changeset
   120
	DumpTarget()
a70f01c9eb57 (svn r10391) -Add: debug support - structured dump of variables/classes/structures (with anti-recursion repository) into string
KUDr
parents:
diff changeset
   121
		: m_indent(0)
a70f01c9eb57 (svn r10391) -Add: debug support - structured dump of variables/classes/structures (with anti-recursion repository) into string
KUDr
parents:
diff changeset
   122
	{}
a70f01c9eb57 (svn r10391) -Add: debug support - structured dump of variables/classes/structures (with anti-recursion repository) into string
KUDr
parents:
diff changeset
   123
a70f01c9eb57 (svn r10391) -Add: debug support - structured dump of variables/classes/structures (with anti-recursion repository) into string
KUDr
parents:
diff changeset
   124
	static size_t& LastTypeId();
a70f01c9eb57 (svn r10391) -Add: debug support - structured dump of variables/classes/structures (with anti-recursion repository) into string
KUDr
parents:
diff changeset
   125
	CStrA GetCurrentStructName();
a70f01c9eb57 (svn r10391) -Add: debug support - structured dump of variables/classes/structures (with anti-recursion repository) into string
KUDr
parents:
diff changeset
   126
	bool FindKnownName(size_t type_id, const void* ptr, CStrA &name);
a70f01c9eb57 (svn r10391) -Add: debug support - structured dump of variables/classes/structures (with anti-recursion repository) into string
KUDr
parents:
diff changeset
   127
a70f01c9eb57 (svn r10391) -Add: debug support - structured dump of variables/classes/structures (with anti-recursion repository) into string
KUDr
parents:
diff changeset
   128
	void WriteIndent();
a70f01c9eb57 (svn r10391) -Add: debug support - structured dump of variables/classes/structures (with anti-recursion repository) into string
KUDr
parents:
diff changeset
   129
a70f01c9eb57 (svn r10391) -Add: debug support - structured dump of variables/classes/structures (with anti-recursion repository) into string
KUDr
parents:
diff changeset
   130
	void WriteLine(const char *format, ...);
a70f01c9eb57 (svn r10391) -Add: debug support - structured dump of variables/classes/structures (with anti-recursion repository) into string
KUDr
parents:
diff changeset
   131
	void WriteValue(const char *name, const char *value_str);
a70f01c9eb57 (svn r10391) -Add: debug support - structured dump of variables/classes/structures (with anti-recursion repository) into string
KUDr
parents:
diff changeset
   132
	void WriteTile(const char *name, TileIndex t);
a70f01c9eb57 (svn r10391) -Add: debug support - structured dump of variables/classes/structures (with anti-recursion repository) into string
KUDr
parents:
diff changeset
   133
a70f01c9eb57 (svn r10391) -Add: debug support - structured dump of variables/classes/structures (with anti-recursion repository) into string
KUDr
parents:
diff changeset
   134
	/** Dump given enum value (as a number and as named value) */
a70f01c9eb57 (svn r10391) -Add: debug support - structured dump of variables/classes/structures (with anti-recursion repository) into string
KUDr
parents:
diff changeset
   135
	template <typename E> void WriteEnumT(const char *name, E e)
a70f01c9eb57 (svn r10391) -Add: debug support - structured dump of variables/classes/structures (with anti-recursion repository) into string
KUDr
parents:
diff changeset
   136
	{
a70f01c9eb57 (svn r10391) -Add: debug support - structured dump of variables/classes/structures (with anti-recursion repository) into string
KUDr
parents:
diff changeset
   137
		WriteValue(name, ValueStr(e).Data());
a70f01c9eb57 (svn r10391) -Add: debug support - structured dump of variables/classes/structures (with anti-recursion repository) into string
KUDr
parents:
diff changeset
   138
	}
a70f01c9eb57 (svn r10391) -Add: debug support - structured dump of variables/classes/structures (with anti-recursion repository) into string
KUDr
parents:
diff changeset
   139
a70f01c9eb57 (svn r10391) -Add: debug support - structured dump of variables/classes/structures (with anti-recursion repository) into string
KUDr
parents:
diff changeset
   140
	void BeginStruct(size_t type_id, const char *name, const void *ptr);
a70f01c9eb57 (svn r10391) -Add: debug support - structured dump of variables/classes/structures (with anti-recursion repository) into string
KUDr
parents:
diff changeset
   141
	void EndStruct();
a70f01c9eb57 (svn r10391) -Add: debug support - structured dump of variables/classes/structures (with anti-recursion repository) into string
KUDr
parents:
diff changeset
   142
a70f01c9eb57 (svn r10391) -Add: debug support - structured dump of variables/classes/structures (with anti-recursion repository) into string
KUDr
parents:
diff changeset
   143
	/** Dump nested object (or only its name if this instance is already known). */
a70f01c9eb57 (svn r10391) -Add: debug support - structured dump of variables/classes/structures (with anti-recursion repository) into string
KUDr
parents:
diff changeset
   144
	template <typename S> void WriteStructT(const char *name, const S *s)
a70f01c9eb57 (svn r10391) -Add: debug support - structured dump of variables/classes/structures (with anti-recursion repository) into string
KUDr
parents:
diff changeset
   145
	{
a70f01c9eb57 (svn r10391) -Add: debug support - structured dump of variables/classes/structures (with anti-recursion repository) into string
KUDr
parents:
diff changeset
   146
		static size_t type_id = ++LastTypeId();
a70f01c9eb57 (svn r10391) -Add: debug support - structured dump of variables/classes/structures (with anti-recursion repository) into string
KUDr
parents:
diff changeset
   147
a70f01c9eb57 (svn r10391) -Add: debug support - structured dump of variables/classes/structures (with anti-recursion repository) into string
KUDr
parents:
diff changeset
   148
		if (s == NULL) {
a70f01c9eb57 (svn r10391) -Add: debug support - structured dump of variables/classes/structures (with anti-recursion repository) into string
KUDr
parents:
diff changeset
   149
			/* No need to dump NULL struct. */
a70f01c9eb57 (svn r10391) -Add: debug support - structured dump of variables/classes/structures (with anti-recursion repository) into string
KUDr
parents:
diff changeset
   150
			WriteLine("%s = <null>", name);
a70f01c9eb57 (svn r10391) -Add: debug support - structured dump of variables/classes/structures (with anti-recursion repository) into string
KUDr
parents:
diff changeset
   151
			return;
a70f01c9eb57 (svn r10391) -Add: debug support - structured dump of variables/classes/structures (with anti-recursion repository) into string
KUDr
parents:
diff changeset
   152
		}
a70f01c9eb57 (svn r10391) -Add: debug support - structured dump of variables/classes/structures (with anti-recursion repository) into string
KUDr
parents:
diff changeset
   153
		CStrA known_as;
a70f01c9eb57 (svn r10391) -Add: debug support - structured dump of variables/classes/structures (with anti-recursion repository) into string
KUDr
parents:
diff changeset
   154
		if (FindKnownName(type_id, s, known_as)) {
a70f01c9eb57 (svn r10391) -Add: debug support - structured dump of variables/classes/structures (with anti-recursion repository) into string
KUDr
parents:
diff changeset
   155
			/* We already know this one, no need to dump it. */
a70f01c9eb57 (svn r10391) -Add: debug support - structured dump of variables/classes/structures (with anti-recursion repository) into string
KUDr
parents:
diff changeset
   156
			WriteLine("%s = known_as.%s", name, known_as.Data());
a70f01c9eb57 (svn r10391) -Add: debug support - structured dump of variables/classes/structures (with anti-recursion repository) into string
KUDr
parents:
diff changeset
   157
		} else {
a70f01c9eb57 (svn r10391) -Add: debug support - structured dump of variables/classes/structures (with anti-recursion repository) into string
KUDr
parents:
diff changeset
   158
			/* Still unknown, dump it */
a70f01c9eb57 (svn r10391) -Add: debug support - structured dump of variables/classes/structures (with anti-recursion repository) into string
KUDr
parents:
diff changeset
   159
			BeginStruct(type_id, name, s);
a70f01c9eb57 (svn r10391) -Add: debug support - structured dump of variables/classes/structures (with anti-recursion repository) into string
KUDr
parents:
diff changeset
   160
			s->Dump(*this);
a70f01c9eb57 (svn r10391) -Add: debug support - structured dump of variables/classes/structures (with anti-recursion repository) into string
KUDr
parents:
diff changeset
   161
			EndStruct();
a70f01c9eb57 (svn r10391) -Add: debug support - structured dump of variables/classes/structures (with anti-recursion repository) into string
KUDr
parents:
diff changeset
   162
		}
a70f01c9eb57 (svn r10391) -Add: debug support - structured dump of variables/classes/structures (with anti-recursion repository) into string
KUDr
parents:
diff changeset
   163
	}
a70f01c9eb57 (svn r10391) -Add: debug support - structured dump of variables/classes/structures (with anti-recursion repository) into string
KUDr
parents:
diff changeset
   164
};
a70f01c9eb57 (svn r10391) -Add: debug support - structured dump of variables/classes/structures (with anti-recursion repository) into string
KUDr
parents:
diff changeset
   165
a70f01c9eb57 (svn r10391) -Add: debug support - structured dump of variables/classes/structures (with anti-recursion repository) into string
KUDr
parents:
diff changeset
   166
#endif /* DBG_HELPERS */