iceoryx2
C++ Language Bindings
Loading...
Searching...
No Matches
assertions.hpp
Go to the documentation of this file.
1// Copyright (c) 2023 by Apex.AI Inc. All rights reserved.
2// Copyright (c) 2024 by ekxide IO GmbH. All rights reserved.
3// Copyright (c) 2025 Contributors to the Eclipse Foundation
4//
5// See the NOTICE file(s) distributed with this work for additional
6// information regarding copyright ownership.
7//
8// This program and the accompanying materials are made available under the
9// terms of the Apache Software License 2.0 which is available at
10// https://www.apache.org/licenses/LICENSE-2.0, or the MIT license
11// which is available at https://opensource.org/licenses/MIT.
12//
13// SPDX-License-Identifier: Apache-2.0 OR MIT
14
15#ifndef IOX2_BB_DETAIL_ASSERTIONS_HPP
16#define IOX2_BB_DETAIL_ASSERTIONS_HPP
17
20
22
23// ***
24// * Define public assertion API
25// ***
26
27// NOLINTBEGIN(cppcoreguidelines-macro-usage) source location requires macros
28
29// The following macros are statements (not expressions).
30// This is important, as it enforces correct use to some degree.
31// For example they cannot be used as function arguments and must be terminated with a ';'.
32//
33// Note: once source location becomes available without macro usage this could (and arguably should)
34// be transformed into a function API.
35
39#define IOX2_PANIC(message) iox2::legacy::er::forwardPanic(iox2::bb::detail::SourceLocation::current(), message)
40
41//************************************************************************************************
42//* For documentation of intent, defensive programming and debugging
43//*
44//* There are no error codes/errors required here on purpose, as it would make the use cumbersome.
45//* Instead a special internal error type is used.
46//************************************************************************************************
47
49#define IOX2_ASSERT_INTERNAL(location, condition, stringified_condition, message) \
50 if (iox2::legacy::er::Configuration::CHECK_ASSERT && !(condition)) { \
51 iox2::legacy::er::forwardFatalError(iox2::legacy::er::Violation::createAssertViolation(), \
52 iox2::legacy::er::ASSERT_VIOLATION, \
53 location, \
54 stringified_condition, \
55 message); \
56 } \
57 []() -> void { }() // the empty lambda forces a semicolon on the caller side
58
63#define IOX2_ASSERT(condition, message) \
64 IOX2_ASSERT_INTERNAL(iox2::bb::detail::SourceLocation::current(), condition, #condition, message)
65
67#define IOX2_ENFORCE_INTERNAL(location, condition, stringified_condition, message) \
68 if (!(condition)) { \
69 iox2::legacy::er::forwardFatalError(iox2::legacy::er::Violation::createEnforceViolation(), \
70 iox2::legacy::er::ENFORCE_VIOLATION, \
71 location, \
72 stringified_condition, \
73 message); \
74 } \
75 []() -> void { }() // the empty lambda forces a semicolon on the caller side
76
81#define IOX2_ENFORCE(condition, message) \
82 IOX2_ENFORCE_INTERNAL(iox2::bb::detail::SourceLocation::current(), condition, #condition, message)
83
85#define IOX2_UNREACHABLE() \
86 iox2::legacy::er::detail::unreachable_wrapped<void, void>(iox2::bb::detail::SourceLocation::current(), \
87 "Reached code that was supposed to be unreachable.")
88
91#define IOX2_TODO() iox2::legacy::er::forwardPanic(iox2::bb::detail::SourceLocation::current(), "Not yet implemented!")
92
93// NOLINTEND(cppcoreguidelines-macro-usage)
94
95#endif // IOX2_BB_DETAIL_ASSERTIONS_HPP