quill
SourceLocation.h
1 #pragma once
2 
9 #pragma once
10 
11 #include "quill/core/Attributes.h"
12 #include <cstdint>
13 
14 #if !defined(QUILL_BUILTIN_FUNCTION_NAME)
15  #if defined(QUILL_DISABLE_FUNCTION_NAME)
16  #define QUILL_BUILTIN_FUNCTION_NAME ""
17  #else
18  #define QUILL_BUILTIN_FUNCTION_NAME __builtin_FUNCTION()
19  #endif
20 #endif
21 
22 #if !defined(QUILL_BUILTIN_FILE_NAME)
23  #if defined(QUILL_DISABLE_FILE_INFO)
24  #define QUILL_BUILTIN_FILE_NAME ""
25  #else
26  #define QUILL_BUILTIN_FILE_NAME __builtin_FILE()
27  #endif
28 #endif
29 
30 #if !defined(QUILL_BUILTIN_LINE_NO)
31  #if defined(QUILL_DISABLE_FILE_INFO)
32  #define QUILL_BUILTIN_LINE_NO 0u
33  #else
34  #define QUILL_BUILTIN_LINE_NO __builtin_LINE()
35  #endif
36 #endif
37 
38 QUILL_BEGIN_NAMESPACE
39 
41 {
42  static constexpr SourceLocation current(char const* file = QUILL_BUILTIN_FILE_NAME,
43  char const* function = QUILL_BUILTIN_FUNCTION_NAME,
44  std::uint_least32_t line = QUILL_BUILTIN_LINE_NO) noexcept
45  {
46  return SourceLocation{file, function, line};
47  }
48 
49  constexpr SourceLocation(char const* file, char const* function, std::uint_least32_t line)
50  : _file(file), _function(function), _line(line)
51  {
52  }
53 
54  QUILL_NODISCARD constexpr const char* file_name() const noexcept { return _file; }
55  QUILL_NODISCARD constexpr const char* function_name() const noexcept { return _function; }
56  QUILL_NODISCARD constexpr std::uint_least32_t line() const noexcept { return _line; }
57 
58 private:
59  char const* _file;
60  char const* _function;
61  std::uint_least32_t _line;
62 };
63 
64 QUILL_END_NAMESPACE
Definition: SourceLocation.h:40