libzypp 17.38.15

precondition.h
Go to the documentation of this file.
1/*---------------------------------------------------------------------\
2| ____ _ __ __ ___ |
3| |__ / \ / / . \ . \ |
4| / / \ V /| _/ _/ |
5| / /__ | | | | | | |
6| /_____||_| |_| |_| |
7| |
8\---------------------------------------------------------------------*/
16#ifndef ZYPPNG_BASE_PRECONDITION_H
17#define ZYPPNG_BASE_PRECONDITION_H
18
19#include <zypp-core/base/LogTools.h>
20
24#if __cplusplus >= 202002L
25# define ZYPP_DETAIL_UNLIKELY [[unlikely]]
26#else
27# define ZYPP_DETAIL_UNLIKELY
28#endif
29
42#define ZYPP_PRECONDITION( EXPR, ... ) \
43 do { \
44 if ( !( EXPR ) ) ZYPP_DETAIL_UNLIKELY \
45 ::zyppng::detail::preconditionViolated( \
46 __FILE__, __LINE__, __FUNCTION__, #EXPR, "" __VA_ARGS__ ); \
47 } while ( false )
48
49 namespace zyppng::detail {
50
51 [[noreturn]] inline void preconditionViolated(
52 const char * file,
53 int line,
54 const char * func,
55 const char * expr,
56 const char * msg )
57 {
58 INT << file << "(" << func << "):" << line
59 << ": PRECONDITION VIOLATED: (" << expr << ")"
60 << ( msg && *msg ? " — " : "" )
61 << ( msg && *msg ? msg : "" )
62 << std::endl;
63 std::terminate();
64 }
65
66} // namespace zyppng::detail
67
68#endif // ZYPPNG_BASE_PRECONDITION_H
LogTools.h
INT
#define INT
Definition Logger.h:134
zyppng::detail
Definition reporthelper.h:31
zyppng::detail::preconditionViolated
void preconditionViolated(const char *file, int line, const char *func, const char *expr, const char *msg)
Definition precondition.h:51