Elm  2
ELM is a library providing generic data structures, OS-independent interface, plugins and XML.
assert.h
1 /*
2  * $Id$
3  * assert module interface
4  *
5  * This file is part of OTAWA
6  * Copyright (c) 2007-09, IRIT UPS.
7  *
8  * OTAWA is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; either version 2 of the License, or
11  * (at your option) any later version.
12  *
13  * OTAWA is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with OTAWA; if not, write to the Free Software
20  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
21  */
22 #ifndef ELM_ASSERT_H
23 #define ELM_ASSERT_H
24 
25 // Useful functions
26 namespace elm {
27 
28 #ifdef __GNUC__
29  void crash(void) __attribute__ ((noreturn));
30 #else
31  void crash(void);
32 #endif
33 
34 
35 } // elm
36 
37 // Macros
38 #ifndef NDEBUG
39 # include <elm/io.h>
40 # define ELM_ASSERT_MSG(msg) \
41  elm::cerr << "ASSERT:" << __FILE__ << ":" << __LINE__ << ": " << msg << elm::io::endl
42 # define ELM_ASSERT(cond) \
43  { if(!(cond)) { ELM_ASSERT_MSG("assert failure: " #cond); elm::crash(); } }
44 # define ELM_ASSERTP(cond, msg) \
45  { if(!(cond)) { ELM_ASSERT_MSG(msg); elm::crash(); } }
46 # define ELM_IN_ASSERT(x) x
47 #else
48 # define ELM_ASSERT(cond) ;
49 # define ELM_ASSERTP(cond, msg);
50 # define ELM_IN_ASSERT(x)
51 #endif
52 
53 // Macros without prefix
54 #ifndef ELM_NO_ASSERT_SHORTCUT
55 # define ASSERT(cond) ELM_ASSERT(cond)
56 # define ASSERTP(cond, msg) ELM_ASSERTP(cond, msg)
57 # define IN_ASSERT(x) ELM_IN_ASSERT(x)
58 #endif
59 
60 #endif // ELM_ASSERT_H
elm::crash
void crash(void)
Definition: debug.cpp:53
elm
Definition: adapter.h:26