diff options
author | Anton Samokhvalov <pg83@yandex.ru> | 2022-02-10 16:45:17 +0300 |
---|---|---|
committer | Daniil Cherednik <dcherednik@yandex-team.ru> | 2022-02-10 16:45:17 +0300 |
commit | d3a398281c6fd1d3672036cb2d63f842d2cb28c5 (patch) | |
tree | dd4bd3ca0f36b817e96812825ffaf10d645803f2 /library/cpp/dbg_output/engine.h | |
parent | 72cb13b4aff9bc9cf22e49251bc8fd143f82538f (diff) | |
download | ydb-d3a398281c6fd1d3672036cb2d63f842d2cb28c5.tar.gz |
Restoring authorship annotation for Anton Samokhvalov <pg83@yandex.ru>. Commit 2 of 2.
Diffstat (limited to 'library/cpp/dbg_output/engine.h')
-rw-r--r-- | library/cpp/dbg_output/engine.h | 308 |
1 files changed, 154 insertions, 154 deletions
diff --git a/library/cpp/dbg_output/engine.h b/library/cpp/dbg_output/engine.h index cacd9c0a8f..f13c728c39 100644 --- a/library/cpp/dbg_output/engine.h +++ b/library/cpp/dbg_output/engine.h @@ -1,180 +1,180 @@ -#pragma once - -#include <util/stream/output.h> - +#pragma once + +#include <util/stream/output.h> + #include <utility> -#include <util/generic/strbuf.h> - -template <class T> -struct TDumper { - template <class S> - static inline void Dump(S& s, const T& t) { - s.Stream() << t; - } -}; - -namespace NDumpPrivate { - template <class T, class V> - inline void Dump(T& t, const V& v) { - ::TDumper<V>::Dump(t, v); - } - - template <class T, class V> - inline T&& operator<<(T&& t, V&& v) { - Dump(t, v); - +#include <util/generic/strbuf.h> + +template <class T> +struct TDumper { + template <class S> + static inline void Dump(S& s, const T& t) { + s.Stream() << t; + } +}; + +namespace NDumpPrivate { + template <class T, class V> + inline void Dump(T& t, const V& v) { + ::TDumper<V>::Dump(t, v); + } + + template <class T, class V> + inline T&& operator<<(T&& t, V&& v) { + Dump(t, v); + return std::forward<T>(t); - } - - struct TADLBase { - }; -} - -struct TDumpBase: public ::NDumpPrivate::TADLBase { + } + + struct TADLBase { + }; +} + +struct TDumpBase: public ::NDumpPrivate::TADLBase { inline TDumpBase(IOutputStream& out, bool indent) noexcept - : Out(&out) - , IndentLevel(0) - , Indent(indent) - { - } - + : Out(&out) + , IndentLevel(0) + , Indent(indent) + { + } + inline IOutputStream& Stream() const noexcept { - return *Out; - } - - void Char(char ch); - void Char(wchar16 ch); - - void String(const TStringBuf& s); - void String(const TWtringBuf& s); - - void Raw(const TStringBuf& s); - + return *Out; + } + + void Char(char ch); + void Char(wchar16 ch); + + void String(const TStringBuf& s); + void String(const TWtringBuf& s); + + void Raw(const TStringBuf& s); + IOutputStream* Out; - size_t IndentLevel; - bool Indent; -}; - -struct TIndentScope { - inline TIndentScope(TDumpBase& d) - : D(&d) - { - ++(D->IndentLevel); - } - + size_t IndentLevel; + bool Indent; +}; + +struct TIndentScope { + inline TIndentScope(TDumpBase& d) + : D(&d) + { + ++(D->IndentLevel); + } + inline ~TIndentScope() { - --(D->IndentLevel); - } - - TDumpBase* D; -}; - -template <class TChar> -struct TRawLiteral { + --(D->IndentLevel); + } + + TDumpBase* D; +}; + +template <class TChar> +struct TRawLiteral { const TBasicStringBuf<TChar> S; -}; - -template <class TChar> +}; + +template <class TChar> static inline TRawLiteral<TChar> DumpRaw(const TBasicStringBuf<TChar>& s) noexcept { return {s}; } template <class TChar> static inline TRawLiteral<TChar> DumpRaw(const TChar* s) noexcept { - return {s}; -} - -template <class C> -struct TDumper<TRawLiteral<C>> { - template <class S> - static inline void Dump(S& s, const TRawLiteral<C>& v) { - s.Raw(v.S); - } -}; - -struct TIndentNewLine { -}; - + return {s}; +} + +template <class C> +struct TDumper<TRawLiteral<C>> { + template <class S> + static inline void Dump(S& s, const TRawLiteral<C>& v) { + s.Raw(v.S); + } +}; + +struct TIndentNewLine { +}; + static inline TIndentNewLine IndentNewLine() noexcept { - return {}; -} - -template <> -struct TDumper<TIndentNewLine> { - template <class S> - static inline void Dump(S& s, const TIndentNewLine&) { - if (s.Indent) { + return {}; +} + +template <> +struct TDumper<TIndentNewLine> { + template <class S> + static inline void Dump(S& s, const TIndentNewLine&) { + if (s.Indent) { s << DumpRaw("\n") << DumpRaw(TString(s.IndentLevel * 4, ' ').data()); - } - } -}; - -template <class P> -struct TDumper<const P*> { - template <class S> - static inline void Dump(S& s, const P* p) { - s.Pointer(p); - } -}; - -template <class P> -struct TDumper<P*>: public TDumper<const P*> { -}; - -struct TCharDumper { - template <class S, class V> - static inline void Dump(S& s, const V& v) { - s.Char(v); - } -}; - -template <class S, class V> -static inline void OutSequence(S& s, const V& v, const char* openTag, const char* closeTag) { + } + } +}; + +template <class P> +struct TDumper<const P*> { + template <class S> + static inline void Dump(S& s, const P* p) { + s.Pointer(p); + } +}; + +template <class P> +struct TDumper<P*>: public TDumper<const P*> { +}; + +struct TCharDumper { + template <class S, class V> + static inline void Dump(S& s, const V& v) { + s.Char(v); + } +}; + +template <class S, class V> +static inline void OutSequence(S& s, const V& v, const char* openTag, const char* closeTag) { s.ColorScheme.Markup(s); - s << DumpRaw(openTag); - - { - TIndentScope scope(s); - size_t cnt = 0; - - for (const auto& x : v) { - if (cnt) { + s << DumpRaw(openTag); + + { + TIndentScope scope(s); + size_t cnt = 0; + + for (const auto& x : v) { + if (cnt) { s.ColorScheme.Markup(s); - s << DumpRaw(", "); - } - + s << DumpRaw(", "); + } + s << IndentNewLine(); s.ColorScheme.Literal(s); s << x; - ++cnt; - } - } - + ++cnt; + } + } + s << IndentNewLine(); s.ColorScheme.Markup(s); s << DumpRaw(closeTag); s.ColorScheme.ResetType(s); -} - -struct TAssocDumper { - template <class S, class V> - static inline void Dump(S& s, const V& v) { - ::OutSequence(s, v, "{", "}"); - } -}; - -struct TSeqDumper { - template <class S, class V> - static inline void Dump(S& s, const V& v) { - ::OutSequence(s, v, "[", "]"); - } -}; - -struct TStrDumper { - template <class S, class V> - static inline void Dump(S& s, const V& v) { +} + +struct TAssocDumper { + template <class S, class V> + static inline void Dump(S& s, const V& v) { + ::OutSequence(s, v, "{", "}"); + } +}; + +struct TSeqDumper { + template <class S, class V> + static inline void Dump(S& s, const V& v) { + ::OutSequence(s, v, "[", "]"); + } +}; + +struct TStrDumper { + template <class S, class V> + static inline void Dump(S& s, const V& v) { s.ColorScheme.String(s); - s.String(v); + s.String(v); s.ColorScheme.ResetType(s); - } -}; + } +}; |