symbol.h 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. #pragma once
  2. #include <util/generic/string.h>
  3. #include <util/string/builder.h>
  4. #include <util/system/src_location.h>
  5. #define LWTRACE_DEFINE_SYMBOL(variable, text) \
  6. static TString variable##_holder(text); \
  7. ::NLWTrace::TSymbol variable(&variable##_holder); \
  8. /**/
  9. #define LWTRACE_INLINE_SYMBOL(text) \
  10. [&] { \
  11. static TString _holder(text); \
  12. return ::NLWTrace::TSymbol(&_holder); \
  13. }() /**/
  14. #define LWTRACE_LOCATION_SYMBOL \
  15. [](const char* func) { \
  16. static TString _holder(TStringBuilder() << func << " (" << __LOCATION__ << ")"); \
  17. return ::NLWTrace::TSymbol(&_holder); \
  18. }(Y_FUNC_SIGNATURE) /**/
  19. namespace NLWTrace {
  20. struct TSymbol {
  21. TString* Str;
  22. TSymbol()
  23. : Str(nullptr)
  24. {
  25. }
  26. explicit TSymbol(TString* str)
  27. : Str(str)
  28. {
  29. }
  30. TSymbol& operator=(const TSymbol& o) {
  31. Str = o.Str;
  32. return *this;
  33. }
  34. TSymbol(const TSymbol& o)
  35. : Str(o.Str)
  36. {
  37. }
  38. bool operator<(const TSymbol& rhs) const {
  39. return Str < rhs.Str;
  40. }
  41. bool operator>(const TSymbol& rhs) const {
  42. return Str > rhs.Str;
  43. }
  44. bool operator<=(const TSymbol& rhs) const {
  45. return Str <= rhs.Str;
  46. }
  47. bool operator>=(const TSymbol& rhs) const {
  48. return Str >= rhs.Str;
  49. }
  50. bool operator==(const TSymbol& rhs) const {
  51. return Str == rhs.Str;
  52. }
  53. bool operator!=(const TSymbol& rhs) const {
  54. return Str != rhs.Str;
  55. }
  56. };
  57. }