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
debug_assert.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_DEBUG_ASSERT_H
13 #define DOCWIRE_DEBUG_ASSERT_H
14 
15 #include "make_error.h"
16 #include "with_source_location.h"
17 
18 // In debug builds (when NDEBUG is not defined), DOCWIRE_DEBUG_ASSERT checks a condition
19 // and if it's false, prints a message and terminates the program.
20 // In release builds (when NDEBUG is defined), it compiles to nothing.
21 #ifndef NDEBUG
22 namespace docwire::errors
23 {
27  [[noreturn]] DOCWIRE_CORE_EXPORT void panic(std::exception_ptr eptr);
28 }
29 #endif // NDEBUG
30 
31 namespace docwire
32 {
33 
34 #ifndef NDEBUG
35 
46 template<typename... Context>
47 void debug_assert(detail::with_source_location<bool> condition, Context&&... context)
48 {
49  if (!condition.value)
50  {
51  errors::panic(make_error_ptr_from_tuple(condition.location, std::make_tuple(std::forward<Context>(context)...)));
52  }
53 }
54 
55 #else
56 
57 template<typename... Context>
58 constexpr void debug_assert(detail::with_source_location<bool> /*condition*/, Context&&...) {}
59 
60 #endif // NDEBUG
61 
62 } // namespace docwire
63 
64 #endif // DOCWIRE_DEBUG_ASSERT_H
Provides features for reporting and handling errors with context data using nested exceptions.
Definition: contains_type.h:19
DOCWIRE_CORE_EXPORT void panic(std::exception_ptr eptr)
Terminates the program with a panic message in debug builds.
The main namespace for the DocWire SDK.
Definition: ai_elements.h:19
void debug_assert(detail::with_source_location< bool > condition, Context &&... context)
Asserts a condition in debug builds.
Definition: debug_assert.h:47
Helper struct to capture the source location of a call site. This is implicitly constructed from a va...