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