00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
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 ~DesignByContract();
00037
00038 virtual bool isValid() const;
00039
00040 static void __throw_error_(const char *file, const int line,
00041 const char *expr, const char *type);
00042
00043 static void __report_Message_(const char *file, const int line, const char *msg);
00044
00045 #endif
00046
00047 };
00048
00049
00050
00051
00052
00053 #ifndef NDEBUG
00054
00055 #define ASSERT__(type,expr) if (!(expr)) DesignByContract::__throw_error_(__FILE__, __LINE__, #expr,type)
00056
00057 #define ASSERT(expr) ASSERT__("ASSERTION",expr)
00058 #define IS_VALID(obj) ASSERT__("CONSTISTENCY CHECK",(obj) != NULL && (obj)->isValid())
00059 #define IS_VALID_REF(obj) ASSERT__("CONSTISTENCY CHECK",(obj).isValid())
00060 #define REQUIRE(expr) ASSERT__("PRE-CONDITION",expr)
00061 #define ENSURE(expr) ASSERT__("POST-CONDITION",expr)
00062
00063 #define MESSAGE(msg) DesignByContract::__report_Message_(__FILE__,__LINE__,msg)
00064
00065 #else
00066
00067
00068
00069
00070 #define ASSERT(expr) ((void) 0)
00071 #define IS_VALID(expr) ((void) 0)
00072 #define IS_VALID_REF(expr) ((void) 0)
00073 #define REQUIRE(expr) ((void) 0)
00074 #define ENSURE(expr) ((void) 0)
00075
00076 #define MESGAGE(msg) ((void) 0)
00077
00078 #endif
00079
00080 #endif