ergo
DebugPolicies.h
Go to the documentation of this file.
1 /* Ergo, version 3.7, a program for linear scaling electronic structure
2  * calculations.
3  * Copyright (C) 2018 Elias Rudberg, Emanuel H. Rubensson, Pawel Salek,
4  * and Anastasia Kruchinina.
5  *
6  * This program is free software: you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation, either version 3 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program. If not, see <http://www.gnu.org/licenses/>.
18  *
19  * Primary academic reference:
20  * Ergo: An open-source program for linear-scaling electronic structure
21  * calculations,
22  * Elias Rudberg, Emanuel H. Rubensson, Pawel Salek, and Anastasia
23  * Kruchinina,
24  * SoftwareX 7, 107 (2018),
25  * <http://dx.doi.org/10.1016/j.softx.2018.03.005>
26  *
27  * For further information about Ergo, see <http://www.ergoscf.org>.
28  */
29 
44 #ifndef MAT_DEBUGPOLICIES
45 #define MAT_DEBUGPOLICIES
46 
47 #include <cstdlib>
48 
49 namespace mat{
50 #if 0
51 #define ASSERTALWAYS(x) \
52  this->assertAlways(__FILE__, __LINE__, __DATE__, __TIME__,x)
53 #define ASSERTDEBUG(x) \
54  this->assertDebug(__FILE__, __LINE__, __DATE__, __TIME__,x)
55  /* debugPolicies */
56 
57  class DebugLevelHigh {
58  public:
59  void assertAlways(char const * theFile, int const theLine,
60  char const * theDate, char const * theTime,
61  bool const statement) const {
62  if (!statement) {
63  std::cout<<"Assertion failed: "<<theFile<<":"<<theLine
64  <<" Compiled on "<<theDate<<" at "<<theTime<<".\n";
65  std::exit(1);
66  }
67  }
68  inline void assertDebug(char const * theFile, int const theLine,
69  char const * theDate, char const * theTime,
70  bool const statement) const {
71  assertAlways(theFile, theLine, theDate, theTime, statement);
72  }
73  };
74  class DebugLevelMedium : public DebugLevelHigh {};
75  class DebugLevelLow : public DebugLevelMedium {
76  public:
77  inline void assertDebug(char const * theFile, int const theLine,
78  char const * theDate, char const * theTime,
79  bool const statement) const {}
80  };
81 
82 #else
83 
84 
85 #define ASSERTALWAYS(x) \
86  this->assertAlways(__FILE__, __LINE__, __ID__,x)
87 #define ASSERTDEBUG(x) \
88  this->assertDebug(__FILE__, __LINE__, __ID__,x)
89 #endif
90  /* debugPolicies */
92  public:
93  void assertAlways(char const * theFile, int const theLine,
94  char const * theId, bool const statement) const {
95  if (!statement) {
96  std::cout<<"Assertion failed: "<<theFile<<":"<<theLine
97  <<" svn info: "<<theId<<".\n";
98  std::exit(1);
99  }
100  }
101  inline void assertDebug(char const * theFile, int const theLine,
102  char const * theId, bool const statement) const {
103  assertAlways(theFile, theLine, theId, statement);
104  }
105  };
106  class DebugLevelMedium : public DebugLevelHigh {};
108  public:
109  inline void assertDebug(char const * theFile, int const theLine,
110  char const * theId, bool const statement) const {}
111  };
112 
113 
114 
115 } /* end namespace mat */
116 #endif
Definition: DebugPolicies.h:106
void assertDebug(char const *theFile, int const theLine, char const *theId, bool const statement) const
Definition: DebugPolicies.h:101
Definition: allocate.cc:39
void assertDebug(char const *theFile, int const theLine, char const *theId, bool const statement) const
Definition: DebugPolicies.h:109
Definition: DebugPolicies.h:91
void assertAlways(char const *theFile, int const theLine, char const *theId, bool const statement) const
Definition: DebugPolicies.h:93
Definition: DebugPolicies.h:107