quill
SourceLocation.h
1 
7 #pragma once
8 
9 #include "quill/core/Attributes.h"
10 #include <cstdint>
11 
12 #if !defined(QUILL_BUILTIN_FUNCTION_NAME)
13  #if defined(QUILL_DISABLE_FUNCTION_NAME)
14  #define QUILL_BUILTIN_FUNCTION_NAME ""
15  #else
16  #define QUILL_BUILTIN_FUNCTION_NAME __builtin_FUNCTION()
17  #endif
18 #endif
19 
20 #if !defined(QUILL_BUILTIN_FILE_NAME)
21  #if defined(QUILL_DISABLE_FILE_INFO)
22  #define QUILL_BUILTIN_FILE_NAME ""
23  #else
24  #define QUILL_BUILTIN_FILE_NAME __builtin_FILE()
25  #endif
26 #endif
27 
28 #if !defined(QUILL_BUILTIN_LINE_NO)
29  #if defined(QUILL_DISABLE_FILE_INFO)
30  #define QUILL_BUILTIN_LINE_NO 0u
31  #else
32  #define QUILL_BUILTIN_LINE_NO __builtin_LINE()
33  #endif
34 #endif
35 
36 QUILL_BEGIN_NAMESPACE
37 
38 QUILL_BEGIN_EXPORT
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 char const* file_name() const noexcept { return _file; }
55  QUILL_NODISCARD constexpr char const* 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_EXPORT
65 
66 QUILL_END_NAMESPACE
Definition: SourceLocation.h:40