libatomprobe
Library for Atom Probe Tomography (APT) computation
aptAssert.cpp
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2020 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 
19 
20 namespace AtomProbe
21 {
22 
23 bool hardAssert=true;
24 
26 {
27  return hardAssert;
28 }
29 
30 void setHardAssert(bool enabled)
31 {
32  hardAssert=enabled;
33 }
34 
35 void askAssert(const char * const filename, const unsigned int lineNumber)
36 {
37 
38  static bool skipAll=false;
39 
40  std::cerr << "ASSERTION ERROR!" << std::endl;
41  std::cerr << "Filename: " << filename << std::endl;
42  std::cerr << "Line number: " << lineNumber << std::endl;
43 
44  if(skipAll)
45  {
46  std::cerr << "\tContinuing, as previously requested" << std::endl;
47  return;
48  }
49 
50  if(!hardAssert)
51  {
52  std::cerr << "Do you wish to continue? - (y)es/(n)o/(a)lways -";
53  char y = '_';
54  while (y != 'n' && y != 'y' && y!= 'a')
55  std::cin >> y;
56 
57  if (y == 'n')
58  assert(false);
59 
60  if(y == 'a')
61  skipAll=true;
62  }
63  else
64  {
65  assert(false);
66  }
67 }
68 }
bool hardAssert
Definition: aptAssert.cpp:23
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
bool getHardAssert()
Definition: aptAssert.cpp:25
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