Main Page | Class Hierarchy | Class List | File List | Class Members | Related Pages

designbycontract.h

00001 /* 00002 00003 freesteam - IAPWS-IF97 steam tables library 00004 Copyright (C) 2004-2005 John Pye 00005 00006 This program is free software; you can redistribute it and/or 00007 modify it under the terms of the GNU General Public License 00008 as published by the Free Software Foundation; either version 2 00009 of the License, or (at your option) any later version. 00010 00011 This program is distributed in the hope that it will be useful, 00012 but WITHOUT ANY WARRANTY; without even the implied warranty of 00013 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00014 GNU General Public License for more details. 00015 00016 You should have received a copy of the GNU General Public License 00017 along with this program; if not, write to the Free Software 00018 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 00019 00020 */ 00021 00022 #ifndef DESIGNBYCONTRACT_H 00023 #define DESIGNBYCONTRACT_H 00024 00026 00031 class DesignByContract { 00032 00033 public: 00034 00035 #ifndef NDEBUG 00036 virtual bool isValid() const; 00037 00038 static void __throw_error_(const char *file, const int line, 00039 const char *expr, const char *type); 00040 00041 static void DesignByContract::__report_Message_(const char *file, const int line, const char *msg); 00042 00043 #endif 00044 00045 }; 00046 00047 // The debug mode also defines the following macros. Failure of any of these macros leads to 00048 // program termination. The user is notified of the error condition with the right file name 00049 // and line number. The actual failing operation is also printed using the stringizing operator # 00050 00051 #ifndef NDEBUG 00052 00053 #define ASSERT__(type,expr) if (!(expr)) DesignByContract::__throw_error_(__FILE__, __LINE__, #expr,type) 00054 00055 #define ASSERT(expr) ASSERT__("ASSERTION",expr) 00056 #define IS_VALID(obj) ASSERT__("CONSTISTENCY CHECK",(obj) != NULL && (obj)->isValid()) 00057 #define IS_VALID_REF(obj) ASSERT__("CONSTISTENCY CHECK",(obj).isValid()) 00058 #define REQUIRE(expr) ASSERT__("PRE-CONDITION",expr) 00059 #define ENSURE(expr) ASSERT__("POST-CONDITION",expr) 00060 00061 #define MESSAGE(msg) DesignByContract::__report_Message_(__FILE__,__LINE__,msg) 00062 00063 #else 00064 00065 // When built in release mode, the _DEBUG flag would not be defined, thus there will be no overhead 00066 // in the final release from these checks. 00067 00068 #define ASSERT(expr) ((void) 0) 00069 #define IS_VALID(expr) ((void) 0) 00070 #define IS_VALID_REF(expr) ((void) 0) 00071 #define REQUIRE(expr) ((void) 0) 00072 #define ENSURE(expr) ((void) 0) 00073 00074 #define MESGAGE(msg) ((void) 0) 00075 00076 #endif 00077 00078 #endif

Generated on Tue Mar 22 19:07:05 2005 for freesteam by doxygen 1.3.8