DocWire SDK
DocWire SDK: Award-winning modern data processing in C++20. SourceForge Community Choice & Microsoft support. AI-driven processing. Supports nearly 100 data formats, including email boxes and OCR. Boost efficiency in text extraction, web data extraction, data mining, document analysis. Offline processing possible for security and confidentiality
source_location.h
1 /*********************************************************************************************************************************************/
2 /* DocWire SDK: Award-winning modern data processing in C++20. SourceForge Community Choice & Microsoft support. AI-driven processing. */
3 /* Supports nearly 100 data formats, including email boxes and OCR. Boost efficiency in text extraction, web data extraction, data mining, */
4 /* document analysis. Offline processing possible for security and confidentiality */
5 /* */
6 /* Copyright (c) SILVERCODERS Ltd, http://silvercoders.com */
7 /* Project homepage: https://github.com/docwire/docwire */
8 /* */
9 /* SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-DocWire-Commercial */
10 /*********************************************************************************************************************************************/
11 
12 #ifndef DOCWIRE_SOURCE_LOCATION_H
13 #define DOCWIRE_SOURCE_LOCATION_H
14 
15 #if __has_include(<source_location>) && (!defined(__clang__) || __clang_major__ >= 16) // https://github.com/llvm/llvm-project/issues/56379
16  #define USE_STD_SOURCE_LOCATION 1
17 #else
18  #warning "Cannot use std::source_location, falling back to custom implementation. For best performance, use a C++20 compliant compiler that fully supports std::source_location (e.g., GCC 11+, Clang 16+, MSVC 19.29+)."
19  #define USE_STD_SOURCE_LOCATION 0
20 #endif
21 
22 #include <cstdint>
23 #if USE_STD_SOURCE_LOCATION
24  #include <source_location>
25 #endif
26 
27 namespace docwire {
28 
31 {
32 public:
33  static constexpr basic_source_location current(
34  const char* file = __builtin_FILE(),
35  const char* function = __builtin_FUNCTION(),
36  const std::uint_least32_t line = __builtin_LINE()) noexcept
37  {
38  return basic_source_location(file, function, line);
39  }
40 
41  constexpr basic_source_location() noexcept = default;
42 
43  constexpr const char* file_name() const noexcept { return m_file; }
44  constexpr const char* function_name() const noexcept { return m_function; }
45  constexpr std::uint_least32_t line() const noexcept { return m_line; }
46  constexpr std::uint_least32_t column() const noexcept { return 0; }
47 
48 private:
49  constexpr basic_source_location(const char* file, const char* function, std::uint_least32_t line) noexcept
50  : m_file(file), m_function(function), m_line(line)
51  {}
52 
53  const char* m_file = "";
54  const char* m_function = "";
55  std::uint_least32_t m_line{};
56 };
57 
58 #if USE_STD_SOURCE_LOCATION
60  using source_location = std::source_location;
61 #else
64 #endif
65 
66 } // namespace docwire
67 
68 #undef USE_STD_SOURCE_LOCATION
69 
70 #endif // DOCWIRE_SOURCE_LOCATION_H
The main namespace for the DocWire SDK.
Definition: ai_elements.h:19
A fallback implementation of source_location for compilers that do not support std::source_location.