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/dump.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/dump.h')
-rw-r--r-- | library/cpp/dbg_output/dump.h | 166 |
1 files changed, 83 insertions, 83 deletions
diff --git a/library/cpp/dbg_output/dump.h b/library/cpp/dbg_output/dump.h index 184df606c1..c7efa105ee 100644 --- a/library/cpp/dbg_output/dump.h +++ b/library/cpp/dbg_output/dump.h @@ -1,106 +1,106 @@ -#pragma once - -#include "engine.h" -#include "dumpers.h" +#pragma once + +#include "engine.h" +#include "dumpers.h" #include "auto.h" #include "colorscheme.h" - -#include <util/stream/format.h> + +#include <util/stream/format.h> #include <util/system/type_name.h> -#include <util/generic/hash_set.h> +#include <util/generic/hash_set.h> #include <utility> - -/* - * Cout << DbgDump(any) << Endl; - * Cout << DbgDumpDeep(any) << Endl; - * Cout << DbgDump(any).SetIndent(true) << Endl; - * - * specialize TDumper<your type> for extending dumper - */ - -namespace NPrivate { - template <class TColorScheme> - struct TTraitsShallow { + +/* + * Cout << DbgDump(any) << Endl; + * Cout << DbgDumpDeep(any) << Endl; + * Cout << DbgDump(any).SetIndent(true) << Endl; + * + * specialize TDumper<your type> for extending dumper + */ + +namespace NPrivate { + template <class TColorScheme> + struct TTraitsShallow { struct TDump: public TDumpBase, public TColorSchemeContainer<TColorScheme> { - template <typename... Args> - inline TDump(Args&&... args) + template <typename... Args> + inline TDump(Args&&... args) : TDumpBase(std::forward<Args>(args)...) - { - } - - template <class V> - inline void Pointer(const V* v) { - if (v) { + { + } + + template <class V> + inline void Pointer(const V* v) { + if (v) { *this << DumpRaw("(") << DumpRaw(TypeName(v).data()) << DumpRaw(")") << Hex((size_t)v); - } else { + } else { *this << DumpRaw("(") << DumpRaw(TypeName<V>().data()) << DumpRaw("*)nullptr"); - } - } - }; - }; - - template <class TColorScheme> - struct TTraitsDeep { + } + } + }; + }; + + template <class TColorScheme> + struct TTraitsDeep { struct TDump: public TDumpBase, public TColorSchemeContainer<TColorScheme> { - template <typename... Args> - inline TDump(Args&&... args) + template <typename... Args> + inline TDump(Args&&... args) : TDumpBase(std::forward<Args>(args)...) - { - } - - template <class V> - inline void Pointer(const V* v) { + { + } + + template <class V> + inline void Pointer(const V* v) { if (v && !Visited.contains((size_t)v)) { - Visited.insert((size_t)v); + Visited.insert((size_t)v); *this << DumpRaw("(") << DumpRaw(TypeName(v).data()) << DumpRaw(")") << Hex((size_t)v) << DumpRaw(" -> ") << *v; - Visited.erase((size_t)v); - } else { + Visited.erase((size_t)v); + } else { *this << DumpRaw("(") << DumpRaw(TypeName<V>().data()) << DumpRaw("*)nullptr"); - } - } - + } + } + THashSet<size_t> Visited; - }; - }; - - template <class T, class TTraits> - struct TDbgDump { - inline TDbgDump(const T* t) - : T_(t) - , Indent(false) - { - } - + }; + }; + + template <class T, class TTraits> + struct TDbgDump { + inline TDbgDump(const T* t) + : T_(t) + , Indent(false) + { + } + inline void DumpTo(IOutputStream& out) const { - typename TTraits::TDump d(out, Indent); - - d << *T_; - } - + typename TTraits::TDump d(out, Indent); + + d << *T_; + } + inline TDbgDump& SetIndent(bool v) noexcept { - Indent = v; - - return *this; - } - - const T* T_; - bool Indent; - }; - - template <class T, class TTraits> + Indent = v; + + return *this; + } + + const T* T_; + bool Indent; + }; + + template <class T, class TTraits> static inline IOutputStream& operator<<(IOutputStream& out, const TDbgDump<T, TTraits>& d) { - d.DumpTo(out); - - return out; - } -} - + d.DumpTo(out); + + return out; + } +} + template <class T, class TColorScheme = DBG_OUTPUT_DEFAULT_COLOR_SCHEME> static inline ::NPrivate::TDbgDump<T, ::NPrivate::TTraitsShallow<TColorScheme>> DbgDump(const T& t) { return {std::addressof(t)}; -} - +} + template <class T, class TColorScheme = DBG_OUTPUT_DEFAULT_COLOR_SCHEME> static inline ::NPrivate::TDbgDump<T, ::NPrivate::TTraitsDeep<TColorScheme>> DbgDumpDeep(const T& t) { return {std::addressof(t)}; -} +} |