dumpers.h 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  1. #pragma once
  2. #include "engine.h"
  3. #include <util/generic/fwd.h>
  4. #include <util/generic/strbuf.h>
  5. #include <util/generic/string.h>
  6. //smart pointers
  7. template <class T, class D>
  8. struct TDumper<TAutoPtr<T, D>> {
  9. template <class S>
  10. static inline void Dump(S& s, const TAutoPtr<T, D>& v) {
  11. s << DumpRaw("TAutoPtr(") << v.Get() << DumpRaw(")");
  12. }
  13. };
  14. template <class T, class D>
  15. struct TDumper<THolder<T, D>> {
  16. template <class S>
  17. static inline void Dump(S& s, const THolder<T, D>& v) {
  18. s << DumpRaw("THolder(") << v.Get() << DumpRaw(")");
  19. }
  20. };
  21. template <class T, class Ops>
  22. struct TDumper<TIntrusivePtr<T, Ops>> {
  23. template <class S>
  24. static inline void Dump(S& s, const TIntrusivePtr<T, Ops>& v) {
  25. s << DumpRaw("TIntrusivePtr(") << v.Get() << DumpRaw(")");
  26. }
  27. };
  28. template <class T, class C, class D>
  29. struct TDumper<TSharedPtr<T, C, D>> {
  30. template <class S>
  31. static inline void Dump(S& s, const TSharedPtr<T, C, D>& v) {
  32. s << DumpRaw("TSharedPtr(") << v.Get() << DumpRaw(")");
  33. }
  34. };
  35. template <class T, class C, class D>
  36. struct TDumper<TCopyPtr<T, C, D>> {
  37. template <class S>
  38. static inline void Dump(S& s, const TCopyPtr<T, C, D>& v) {
  39. s << DumpRaw("TCopyPtr(") << v.Get() << DumpRaw(")");
  40. }
  41. };
  42. //small ints
  43. // Default dumper prints them via IOutputStream << (value), which results in raw
  44. // chars, not integer values. Cast to a bigger int type to force printing as
  45. // integers.
  46. // NB: i8 = signed char != char != unsigned char = ui8
  47. template <>
  48. struct TDumper<ui8>: public TDumper<i32> {
  49. };
  50. template <>
  51. struct TDumper<i8>: public TDumper<i32> {
  52. };
  53. //chars
  54. template <>
  55. struct TDumper<char>: public TCharDumper {
  56. };
  57. template <>
  58. struct TDumper<wchar16>: public TCharDumper {
  59. };
  60. //pairs
  61. template <class A, class B>
  62. struct TDumper<std::pair<A, B>> {
  63. template <class S>
  64. static inline void Dump(S& s, const std::pair<A, B>& v) {
  65. s.ColorScheme.Key(s);
  66. s.ColorScheme.Literal(s);
  67. s << v.first;
  68. s.ColorScheme.ResetType(s);
  69. s.ColorScheme.ResetRole(s);
  70. s.ColorScheme.Markup(s);
  71. s << DumpRaw(" -> ");
  72. s.ColorScheme.Value(s);
  73. s.ColorScheme.Literal(s);
  74. s << v.second;
  75. s.ColorScheme.ResetType(s);
  76. s.ColorScheme.ResetRole(s);
  77. }
  78. };
  79. //sequences
  80. template <class T, class A>
  81. struct TDumper<TVector<T, A>>: public TSeqDumper {
  82. };
  83. template <class T, class A>
  84. struct TDumper<std::vector<T, A>>: public TSeqDumper {
  85. };
  86. template <class T>
  87. struct TDumper<TArrayRef<T>>: public TSeqDumper {
  88. };
  89. template <class T, size_t N>
  90. struct TDumper<std::array<T, N>>: public TSeqDumper {
  91. };
  92. template <class T, class A>
  93. struct TDumper<TDeque<T, A>>: public TSeqDumper {
  94. };
  95. template <class T, class A>
  96. struct TDumper<TList<T, A>>: public TSeqDumper {
  97. };
  98. //associatives
  99. template <class K, class V, class P, class A>
  100. struct TDumper<TMap<K, V, P, A>>: public TAssocDumper {
  101. };
  102. template <class K, class V, class P, class A>
  103. struct TDumper<TMultiMap<K, V, P, A>>: public TAssocDumper {
  104. };
  105. template <class T, class P, class A>
  106. struct TDumper<TSet<T, P, A>>: public TAssocDumper {
  107. };
  108. template <class T, class P, class A>
  109. struct TDumper<TMultiSet<T, P, A>>: public TAssocDumper {
  110. };
  111. template <class K, class V, class H, class P, class A>
  112. struct TDumper<THashMap<K, V, H, P, A>>: public TAssocDumper {
  113. };
  114. template <class K, class V, class H, class P, class A>
  115. struct TDumper<THashMultiMap<K, V, H, P, A>>: public TAssocDumper {
  116. };
  117. template <class T, class H, class P, class A>
  118. struct TDumper<THashSet<T, H, P, A>>: public TAssocDumper {
  119. };
  120. template <class T, class H, class P, class A>
  121. struct TDumper<THashMultiSet<T, H, P, A>>: public TAssocDumper {
  122. };
  123. //strings
  124. template <>
  125. struct TDumper<TString>: public TStrDumper {
  126. };
  127. template <>
  128. struct TDumper<const char*>: public TStrDumper {
  129. };
  130. template <>
  131. struct TDumper<TUtf16String>: public TStrDumper {
  132. };
  133. template <>
  134. struct TDumper<const wchar16*>: public TStrDumper {
  135. };
  136. template <class C, class T, class A>
  137. struct TDumper<std::basic_string<C, T, A>>: public TStrDumper {
  138. };
  139. template <class TChar>
  140. struct TDumper<TBasicStringBuf<TChar>>: public TStrDumper {
  141. };