ergo
DebugPolicies.h
Go to the documentation of this file.
00001 /* Ergo, version 3.2, a program for linear scaling electronic structure
00002  * calculations.
00003  * Copyright (C) 2012 Elias Rudberg, Emanuel H. Rubensson, and Pawel Salek.
00004  * 
00005  * This program is free software: you can redistribute it and/or modify
00006  * it under the terms of the GNU General Public License as published by
00007  * the Free Software Foundation, either version 3 of the License, or
00008  * (at your option) any later version.
00009  * 
00010  * This program is distributed in the hope that it will be useful,
00011  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00012  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013  * GNU General Public License for more details.
00014  * 
00015  * You should have received a copy of the GNU General Public License
00016  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
00017  * 
00018  * Primary academic reference:
00019  * Kohn−Sham Density Functional Theory Electronic Structure Calculations 
00020  * with Linearly Scaling Computational Time and Memory Usage,
00021  * Elias Rudberg, Emanuel H. Rubensson, and Pawel Salek,
00022  * J. Chem. Theory Comput. 7, 340 (2011),
00023  * <http://dx.doi.org/10.1021/ct100611z>
00024  * 
00025  * For further information about Ergo, see <http://www.ergoscf.org>.
00026  */
00027 
00042 #ifndef MAT_DEBUGPOLICIES
00043 #define MAT_DEBUGPOLICIES
00044 
00045 #include <cstdlib>
00046 
00047 namespace mat{
00048 #if 0
00049 #define ASSERTALWAYS(x)                                         \
00050   this->assertAlways(__FILE__, __LINE__, __DATE__, __TIME__,x)
00051 #define ASSERTDEBUG(x)                                          \
00052   this->assertDebug(__FILE__, __LINE__, __DATE__, __TIME__,x)
00053   /* debugPolicies */
00054 
00055   class DebugLevelHigh {
00056   public:
00057     void assertAlways(char const * theFile, int const theLine, 
00058                       char const * theDate, char const * theTime,
00059                       bool const statement) const {
00060       if (!statement) {
00061         std::cout<<"Assertion failed: "<<theFile<<":"<<theLine
00062                  <<" Compiled on "<<theDate<<" at "<<theTime<<".\n";
00063         std::exit(1);
00064       }
00065     }
00066     inline void assertDebug(char const * theFile, int const theLine, 
00067                             char const * theDate, char const * theTime,
00068                             bool const statement) const {
00069       assertAlways(theFile, theLine, theDate, theTime, statement);
00070     }
00071   };
00072   class DebugLevelMedium : public DebugLevelHigh {};
00073   class DebugLevelLow : public DebugLevelMedium  {
00074   public:
00075     inline void assertDebug(char const * theFile, int const theLine, 
00076                             char const * theDate, char const * theTime,
00077                             bool const statement) const {}
00078   };
00079 
00080 #else
00081   
00082 
00083 #define ASSERTALWAYS(x)                                         \
00084   this->assertAlways(__FILE__, __LINE__, __ID__,x)
00085 #define ASSERTDEBUG(x)                                          \
00086   this->assertDebug(__FILE__, __LINE__, __ID__,x)
00087 #endif
00088   /* debugPolicies */
00089   class DebugLevelHigh {
00090   public:
00091     void assertAlways(char const * theFile, int const theLine, 
00092                       char const * theId, bool const statement) const {
00093       if (!statement) {
00094         std::cout<<"Assertion failed: "<<theFile<<":"<<theLine
00095                  <<" svn info: "<<theId<<".\n";
00096         std::exit(1);
00097       }
00098     }
00099     inline void assertDebug(char const * theFile, int const theLine, 
00100                             char const * theId, bool const statement) const {
00101       assertAlways(theFile, theLine, theId, statement);
00102     }
00103   };
00104   class DebugLevelMedium : public DebugLevelHigh {};
00105   class DebugLevelLow : public DebugLevelMedium  {
00106   public:
00107     inline void assertDebug(char const * theFile, int const theLine, 
00108                             char const * theId, bool const statement) const {}
00109   };
00110 
00111 
00112   
00113 } /* end namespace mat */
00114 #endif