libatomprobe
Library for Atom Probe Tomography (APT) computation
aptAssert.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2014 Daniel Haley
3  *
4  * This program is free software: you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation, either version 3 of the License, or
7  * (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program. If not, see <http://www.gnu.org/licenses/>.
16  */
17 
18 #ifndef APTASSERT_H
19 #define APTASSERT_H
20 #include <cassert>
21 #include <iostream>
22 
23 namespace AtomProbe
24 {
26  void setHardAssert(bool enabled);
27 
29  void askAssert(const char *, unsigned int);
30 };
31 
32 #ifdef DEBUG
33 #define ASSERT(f) {if(!(f)){AtomProbe::askAssert(__FILE__,__LINE__);}}
34 
35 #ifndef WARN
36 #define WARN(f,g) { if(!(f)) { std::cerr << "WARNING: " << __FILE__ << ":" <<__LINE__<< g << std::endl;}}
37 #endif
38 
39 #ifndef TEST
40 #define TEST(f,g) {if(!(f)) { std::cerr << "Test fail :" << __FILE__ << ":" << __LINE__ << "\t"<< g << std::endl;return false;}}
41 //Quick/quiet test
42 #define TEST_Q(f) {if(!(f)) { std::cerr << "Test fail :" << __FILE__ << ":" << __LINE__ << std::endl;return false;}}
43 #endif
44 
45 
46 #else
47  #define ASSERT(f)
48  #define WARN(f,g)
49  #define TEST(f,g)
50 #endif
51 
52 #endif
void askAssert(const char *, unsigned int)
Either abort program, or ask the user what to do for an assertion. depending on hardAssert setting...
Definition: aptAssert.cpp:35
void setHardAssert(bool enabled)
Do assertions cause a straight up crash (enabled), or write a mesage to stderr (disabled)? By default, hard crash.
Definition: aptAssert.cpp:30