ALib C++ Library
Library Version:
1912 R0
Documentation generated by
src
alib
lib
fs_debug
assert.hpp
Go to the documentation of this file.
1
/** ************************************************************************************************
2
* \file
3
* This header file is part of file set \alibfs_debug of the \aliblong.
4
*
5
* \emoji :copyright: 2013-2019 A-Worx GmbH, Germany.
6
* Published under \ref mainpage_license "Boost Software License".
7
**************************************************************************************************/
8
#ifndef HPP_ALIB_FS_DEBUG_ASSERT
9
#define HPP_ALIB_FS_DEBUG_ASSERT 1
10
11
#if !defined(HPP_ALIB_MODULES) && !defined(ALIB_DOX)
12
# include "
alib/lib/modules.hpp
"
13
#endif
14
15
ALIB_ASSERT_FILESET
(DEBUG)
16
17
#if !defined(HPP_ALIB_TOOLS) && !defined(ALIB_DOX)
18
# include "
alib/lib/tools.hpp
"
19
#endif
20
21
#if !defined(HPP_ALIB_FS_INTEGERS_INTEGERS)
22
# include "
alib/lib/fs_integers/integers.hpp
"
23
#endif
24
25
#if !defined(HPP_ALIB_FS_DEBUG_ASSERT)
26
# include "
alib/lib/fs_debug/assert.hpp
"
27
#endif
28
29
30
#if !defined (_ASSERT_H) && !defined(assert)
31
# include <assert.h>
32
#endif
33
34
#if ALIB_DEBUG
35
36
namespace
aworx
{
namespace
lib {
37
38
/**
39
* Some \alib modules do not (must not) rely on
40
* \ref aworx::lib::results::Report "Report" /
41
* \alib{results,ReportWriter} mechanics. Therefore, this simple method is
42
* used for error handling in those portions of \alib that are exposed in such modules.<br>
43
* This method first checks if static function pointer
44
* \alib{DBG_SIMPLE_ALIB_MSG_PLUGIN} is set and if yes, passes the parameters
45
* to this method and exits.
46
* If the complete \alib distribution is used, method
47
* \alib{ALibDistribution::Bootstrap}
48
* sets this plug-in function to a custom one which passes the message(s) to a proper
49
* \ref aworx::lib::results::Report "ALib Report".
50
*
51
* Otherwise the method just writes to the standard output stream and then,
52
* if \p{type} equals \c 0, invokes <c>assert(0)</c>.
53
*
54
* @param file The source file of the message invocation.
55
* @param line The line number within \p{file}.
56
* @param method The method invoking this function.
57
* @param type The type of the message. The default implementation does not use this, other
58
* than invoking <c>assert(0)</c> in the case this parameter equals \c 0.
59
* @param msg1 The first message string.
60
* @param msg2 Optional 2nd message string.
61
* @param msg3 Optional 3rd message string.
62
* @param msg4 Optional 4th message string.
63
* @param msg5 Optional 5th message string.
64
*
65
*/
66
ALIB_API
67
extern
void
DbgSimpleALibMsg
(
const
char
* file,
int
line,
const
char
* method,
68
int
type,
69
const
char
* msg1,
70
const
char
* msg2=
nullptr
,
71
const
char
* msg3=
nullptr
,
72
const
char
* msg4=
nullptr
,
73
const
char
* msg5=
nullptr
);
74
75
/**
76
* Overloaded version of
77
* \ref DbgSimpleALibMsg(const char*,int,const char*,int,const char*,const char*,const char*,const char*,const char*) "DbgSimpleALibMsg"
78
* which accepts one integral value and writes \p{msg} and \p{intValue} in sequence.
79
*
80
* @param file The source file of the message invocation.
81
* @param line The line number within \p{file}.
82
* @param method The method invoking this function.
83
* @param type The type of the message. The default implementation does not use this, other
84
* than invoking <c>assert(0)</c> in the case this parameter equals \c 0.
85
* @param msg The message string.
86
* @param intValue An integer parameter (optional due to overload).
87
*
88
*/
89
ALIB_API
90
extern
void
DbgSimpleALibMsg
(
const
char
* file,
int
line,
const
char
* method,
91
int
type,
92
const
char
* msg,
93
const
integer
intValue );
94
95
/**
96
* This function pointer defaults to \c nullptr and may be set to replace function
97
* #DbgSimpleALibMsg.
98
* With the use of \alib_results, the module's bootstrap code (precisely method
99
* \alib{results,Results::bootstrap}) sets this pointer to a small method which creates an
100
* \alib{results,Report} on the default \alib{results,ReportWriter}.
101
*
102
* - \p{file}: Information about the scope of invocation.
103
* - \p{line}: Information about the scope of invocation.
104
* - \p{method}: Information about the scope of invocation.
105
* - \p{type}: The type of the message. As a convention, 0 is severe error, others are warning levels.
106
* - \p{qtyMsgs}: The number of messages passed.
107
* - \p{msgs}: The message strings.
108
*/
109
extern
void (*
DBG_SIMPLE_ALIB_MSG_PLUGIN
)(
const
char
* file,
int
line,
const
char
* method,
110
int
type,
int
qtyMsgs,
const
char
** msgs );
111
112
113
}}
// namespace [aworx::lib]
114
115
#define ALIB_ERROR(...) { aworx::lib::DbgSimpleALibMsg( ALIB_CALLER_PRUNED, 0, __VA_ARGS__); }
116
#define ALIB_WARNING(...) { aworx::lib::DbgSimpleALibMsg( ALIB_CALLER_PRUNED, 1, __VA_ARGS__); }
117
#define ALIB_MESSAGE(...) { aworx::lib::DbgSimpleALibMsg( ALIB_CALLER_PRUNED, 2, __VA_ARGS__); }
118
#define ALIB_ASSERT(cond) { if(!(cond)) ALIB_ERROR( "Assertion Failed" ); }
119
#define ALIB_ASSERT_ERROR(cond, ...) { if(!(cond)) ALIB_ERROR( __VA_ARGS__ ); }
120
#define ALIB_ASSERT_WARNING(cond, ...) { if(!(cond)) ALIB_WARNING( __VA_ARGS__ ); }
121
#define ALIB_ASSERT_MESSAGE(cond, ...) { if(!(cond)) ALIB_MESSAGE( __VA_ARGS__ ); }
122
123
#else
124
#define ALIB_ERROR(...) ;
125
#define ALIB_WARNING(...) ;
126
#define ALIB_MESSAGE(...) ;
127
#define ALIB_ASSERT(cond) ;
128
#define ALIB_ASSERT_ERROR(cond, ...) ;
129
#define ALIB_ASSERT_WARNING(cond, ...) ;
130
#define ALIB_ASSERT_MESSAGE(cond, ...) ;
131
#endif
132
133
#if ALIB_DEBUG
134
#define ALIB_ASSERT_RESULT_EQUALS( func, value ) { auto result= func; assert(result == value); ((void) result); }
135
#define ALIB_ASSERT_RESULT_NOT_EQUALS( func, value ) { auto result= func; assert(result != value); ((void) result); }
136
#define ALIB_ASSERT_RESULT_GREATER_THAN(func, value ) { auto result= func; assert(result > value); ((void) result); }
137
#define ALIB_ASSERT_RESULT_LESS_THAN( func, value ) { auto result= func; assert(result < value); ((void) result); }
138
#else
139
#define ALIB_ASSERT_RESULT_EQUALS( func, value ) { func; }
140
#define ALIB_ASSERT_RESULT_NOT_EQUALS( func, value ) { func; }
141
#define ALIB_ASSERT_RESULT_GREATER_THAN(func, value ) { func; }
142
143
144
#define ALIB_ASSERT_RESULT_LESS_THAN( func, value ) { func; }
145
#endif
146
147
#endif // HPP_ALIB_FS_DEBUG_ASSERT
tools.hpp
aworx::lib::integer
platform_specific integer
Definition:
integers.hpp:53
aworx::lib::DBG_SIMPLE_ALIB_MSG_PLUGIN
void(* DBG_SIMPLE_ALIB_MSG_PLUGIN)(const char *file, int line, const char *method, int type, int qtyMsgs, const char **msgs)
Definition:
assert.cpp:33
integers.hpp
ALIB_ASSERT_FILESET
#define ALIB_ASSERT_FILESET(filesetname)
Definition:
modules.hpp:242
modules.hpp
aworx
Definition:
alox/alox.hpp:40
assert.hpp
ALIB_API
#define ALIB_API
Definition:
compilers.hpp:128
aworx::lib::DbgSimpleALibMsg
ALIB_API void DbgSimpleALibMsg(const char *file, int line, const char *method, int type, const char *msg1, const char *msg2=nullptr, const char *msg3=nullptr, const char *msg4=nullptr, const char *msg5=nullptr)