source_location.h 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. #pragma once
  2. #include <util/generic/string.h>
  3. #ifdef __cpp_lib_source_location
  4. #include <source_location>
  5. #endif // __cpp_lib_source_location
  6. namespace NYT {
  7. ////////////////////////////////////////////////////////////////////////////////
  8. class TSourceLocation
  9. {
  10. public:
  11. TSourceLocation() = default;
  12. TSourceLocation(const char* fileName, int line);
  13. #ifdef __cpp_lib_source_location
  14. explicit TSourceLocation(const std::source_location& location);
  15. #endif // __cpp_lib_source_location
  16. const char* GetFileName() const;
  17. int GetLine() const;
  18. bool IsValid() const;
  19. bool operator<(const TSourceLocation& other) const;
  20. bool operator==(const TSourceLocation& other) const;
  21. private:
  22. const char* FileName_ = nullptr;
  23. int Line_ = -1;
  24. };
  25. //! Defines a macro to record the current source location.
  26. #ifdef __cpp_lib_source_location
  27. #define YT_CURRENT_SOURCE_LOCATION ::NYT::TSourceLocation(std::source_location::current())
  28. #else
  29. #define YT_CURRENT_SOURCE_LOCATION ::NYT::TSourceLocation(__FILE__, __LINE__)
  30. #endif // __cpp_lib_source_location
  31. ////////////////////////////////////////////////////////////////////////////////
  32. } // namespace NYT
  33. #define SOURCE_LOCATION_INL_H_
  34. #include "source_location-inl.h"
  35. #undef SOURCE_LOCATION_INL_H_