iceoryx2
C++ Language Bindings
Loading...
Searching...
No Matches
macros.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_REPORTING_ERROR_REPORTING_MACROS_HPP
16#define IOX2_BB_REPORTING_ERROR_REPORTING_MACROS_HPP
17
21
23
24// ***
25// * Define public error reporting API
26// ***
27
28// NOLINTBEGIN(cppcoreguidelines-macro-usage) source location requires macros
29
30// The following macros are statements (not expressions).
31// This is important, as it enforces correct use to some degree.
32// For example they cannot be used as function arguments and must be terminated with a ';'.
33//
34// Note: once source location becomes available without macro usage this could (and arguably should)
35// be transformed into a function API.
36
40#define IOX2_REPORT(error, kind) \
41 iox2::legacy::er::forwardNonFatalError( \
42 iox2::legacy::er::toError(error), kind, iox2::bb::detail::SourceLocation::current(), "")
43
46#define IOX2_REPORT_FATAL(error) \
47 iox2::legacy::er::forwardFatalError( \
48 iox2::legacy::er::toError(error), iox2::legacy::er::FATAL, iox2::bb::detail::SourceLocation::current(), "")
49
54#define IOX2_REPORT_IF(condition, error, kind) \
55 if (condition) { \
56 iox2::legacy::er::forwardNonFatalError( \
57 iox2::legacy::er::toError(error), kind, iox2::bb::detail::SourceLocation::current(), #condition); \
58 } \
59 [] { }() // the empty lambda forces a semicolon on the caller side
60
64#define IOX2_REPORT_FATAL_IF(condition, error) \
65 if (condition) { \
66 iox2::legacy::er::forwardFatalError(iox2::legacy::er::toError(error), \
67 iox2::legacy::er::FATAL, \
68 iox2::bb::detail::SourceLocation::current(), \
69 #condition); \
70 } \
71 [] { }() // the empty lambda forces a semicolon on the caller side
72
73// NOLINTEND(cppcoreguidelines-macro-usage)
74
75#endif // IOX2_BB_REPORTING_ERROR_REPORTING_MACROS_HPP