DocWire SDK
DocWire SDK: Deterministic, auditable, and secure data processing in C++20. On-premise by default. No compromises on computational speed.
Toggle main menu visibility
Loading...
Searching...
No Matches
enforce.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_ENFORCE_H
13
#define DOCWIRE_ENFORCE_H
14
15
#include "safety_policy.h"
16
#include "with_source_location.h"
17
#include "make_error.h"
18
#include "error_tags.h"
19
#include "debug_assert.h"
20
21
namespace
docwire
22
{
23
37
template
<
safety_policy
safety_level = default_safety_level,
typename
... Context>
38
void
enforce
(
detail::with_source_location<bool>
condition, Context&&... context)
39
{
40
if
(!condition.value)
41
{
42
if
constexpr
(safety_level ==
strict
) {
43
auto
context_tuple = std::make_tuple(std::forward<Context>(context)...,
errors::program_logic
{});
44
throw
errors::make_error_from_tuple
(condition.location, std::move(context_tuple));
45
}
else
{
// relaxed
46
debug_assert
(condition,
"Contract violation"
, std::forward<Context>(context)...,
errors::program_logic
{});
47
}
48
}
49
}
50
51
}
52
53
#endif
// DOCWIRE_ENFORCE_H
docwire::errors::make_error_from_tuple
auto make_error_from_tuple(const source_location &location, std::tuple< Context... > &&context_tuple)
Creates an error object from a tuple of context information.
Definition
make_error.h:30
docwire
The main namespace for the DocWire SDK.
Definition
ai_elements.h:19
docwire::enforce
void enforce(detail::with_source_location< bool > condition, Context &&... context)
Enforces a condition based on the safety policy.
Definition
enforce.h:38
docwire::debug_assert
void debug_assert(detail::with_source_location< bool > condition, Context &&... context)
Asserts a condition in debug builds.
Definition
debug_assert.h:56
docwire::safety_policy
safety_policy
Defines the safety policy for operations.
Definition
safety_policy.h:21
docwire::safety_policy::strict
@ strict
Perform runtime checks and throw exceptions on violations.
Definition
safety_policy.h:23
docwire::detail::with_source_location
Helper struct to capture the source location of a call site. This is implicitly constructed from a va...
Definition
with_source_location.h:26
docwire::errors::program_logic
Program logic failure error tag.
Definition
error_tags.h:40
enforce.h
Generated by
1.18.0