#pragma once #include "engine.h" #include "dumpers.h" #include "auto.h" #include "colorscheme.h" #include #include #include #include /* * Cout << DbgDump(any) << Endl; * Cout << DbgDumpDeep(any) << Endl; * Cout << DbgDump(any).SetIndent(true) << Endl; * * specialize TDumper for extending dumper */ namespace NPrivate { template struct TTraitsShallow { struct TDump: public TDumpBase, public TColorSchemeContainer { template inline TDump(Args&&... args) : TDumpBase(std::forward(args)...) { } template inline void Pointer(const V* v) { if (v) { *this << DumpRaw("(") << DumpRaw(TypeName(v).data()) << DumpRaw(")") << Hex((size_t)v); } else { *this << DumpRaw("(") << DumpRaw(TypeName().data()) << DumpRaw("*)nullptr"); } } }; }; template struct TTraitsDeep { struct TDump: public TDumpBase, public TColorSchemeContainer { template inline TDump(Args&&... args) : TDumpBase(std::forward(args)...) { } template inline void Pointer(const V* v) { if (v && !Visited.contains((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 { *this << DumpRaw("(") << DumpRaw(TypeName().data()) << DumpRaw("*)nullptr"); } } THashSet Visited; }; }; template 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_; } inline TDbgDump& SetIndent(bool v) noexcept { Indent = v; return *this; } const T* T_; bool Indent; }; template static inline IOutputStream& operator<<(IOutputStream& out, const TDbgDump& d) { d.DumpTo(out); return out; } } template static inline ::NPrivate::TDbgDump> DbgDump(const T& t) { return {std::addressof(t)}; } template static inline ::NPrivate::TDbgDump> DbgDumpDeep(const T& t) { return {std::addressof(t)}; }