aboutsummaryrefslogtreecommitdiffstats
path: root/library/cpp/dbg_output/dumpers.h
blob: 4868e97da0723d08f498d47ce48ed88f83eadfd6 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
#pragma once

#include "engine.h"

#include <util/generic/fwd.h>
#include <util/generic/strbuf.h>
#include <util/generic/string.h>

//smart pointers
template <class T, class D>
struct TDumper<TAutoPtr<T, D>> {
    template <class S>
    static inline void Dump(S& s, const TAutoPtr<T, D>& v) {
        s << DumpRaw("TAutoPtr(") << v.Get() << DumpRaw(")");
    }
};

template <class T, class D>
struct TDumper<THolder<T, D>> {
    template <class S>
    static inline void Dump(S& s, const THolder<T, D>& v) {
        s << DumpRaw("THolder(") << v.Get() << DumpRaw(")");
    }
};

template <class T, class Ops>
struct TDumper<TIntrusivePtr<T, Ops>> {
    template <class S>
    static inline void Dump(S& s, const TIntrusivePtr<T, Ops>& v) {
        s << DumpRaw("TIntrusivePtr(") << v.Get() << DumpRaw(")");
    }
};

template <class T, class C, class D>
struct TDumper<TSharedPtr<T, C, D>> {
    template <class S>
    static inline void Dump(S& s, const TSharedPtr<T, C, D>& v) {
        s << DumpRaw("TSharedPtr(") << v.Get() << DumpRaw(")");
    }
};

template <class T, class C, class D>
struct TDumper<TCopyPtr<T, C, D>> {
    template <class S>
    static inline void Dump(S& s, const TCopyPtr<T, C, D>& v) {
        s << DumpRaw("TCopyPtr(") << v.Get() << DumpRaw(")");
    }
};

//small ints
// Default dumper prints them via IOutputStream << (value), which results in raw
// chars, not integer values. Cast to a bigger int type to force printing as
// integers.
// NB: i8 = signed char != char != unsigned char = ui8
template <>
struct TDumper<ui8>: public TDumper<i32> {
};

template <>
struct TDumper<i8>: public TDumper<i32> {
};

//chars
template <>
struct TDumper<char>: public TCharDumper {
};

template <>
struct TDumper<wchar16>: public TCharDumper {
};

//pairs
template <class A, class B>
struct TDumper<std::pair<A, B>> {
    template <class S>
    static inline void Dump(S& s, const std::pair<A, B>& v) {
        s.ColorScheme.Key(s);
        s.ColorScheme.Literal(s);
        s << v.first;
        s.ColorScheme.ResetType(s);
        s.ColorScheme.ResetRole(s);
        s.ColorScheme.Markup(s);
        s << DumpRaw(" -> ");
        s.ColorScheme.Value(s);
        s.ColorScheme.Literal(s);
        s << v.second;
        s.ColorScheme.ResetType(s);
        s.ColorScheme.ResetRole(s);
    }
};

//sequences
template <class T, class A>
struct TDumper<TVector<T, A>>: public TSeqDumper {
};

template <class T, class A>
struct TDumper<std::vector<T, A>>: public TSeqDumper {
};

template <class T>
struct TDumper<TArrayRef<T>>: public TSeqDumper {
};

template <class T, size_t N>
struct TDumper<std::array<T, N>>: public TSeqDumper {
};

template <class T, class A>
struct TDumper<TDeque<T, A>>: public TSeqDumper {
};

template <class T, class A>
struct TDumper<TList<T, A>>: public TSeqDumper {
};

//associatives
template <class K, class V, class P, class A>
struct TDumper<TMap<K, V, P, A>>: public TAssocDumper {
};

template <class K, class V, class P, class A>
struct TDumper<TMultiMap<K, V, P, A>>: public TAssocDumper {
};

template <class T, class P, class A>
struct TDumper<TSet<T, P, A>>: public TAssocDumper {
};

template <class T, class P, class A>
struct TDumper<TMultiSet<T, P, A>>: public TAssocDumper {
};

template <class K, class V, class H, class P, class A>
struct TDumper<THashMap<K, V, H, P, A>>: public TAssocDumper {
};

template <class K, class V, class H, class P, class A>
struct TDumper<THashMultiMap<K, V, H, P, A>>: public TAssocDumper {
};

template <class T, class H, class P, class A>
struct TDumper<THashSet<T, H, P, A>>: public TAssocDumper {
};

template <class T, class H, class P, class A>
struct TDumper<THashMultiSet<T, H, P, A>>: public TAssocDumper {
};

//strings
template <>
struct TDumper<TString>: public TStrDumper {
};

template <>
struct TDumper<const char*>: public TStrDumper {
};

template <>
struct TDumper<TUtf16String>: public TStrDumper {
};

template <>
struct TDumper<const wchar16*>: public TStrDumper {
};

template <class C, class T, class A>
struct TDumper<std::basic_string<C, T, A>>: public TStrDumper {
};

template <class TChar>
struct TDumper<TBasicStringBuf<TChar>>: public TStrDumper {
};