cwidget 0.5.16
|
00001 // eassert.h -*-c++-*- 00002 // 00003 // Copyright (C) 2005, 2007 Daniel Burrows 00004 // 00005 // This program is free software; you can redistribute it and/or 00006 // modify it under the terms of the GNU General Public License as 00007 // published by the Free Software Foundation; either version 2 of 00008 // the License, or (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 GNU 00013 // 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; see the file COPYING. If not, write to 00017 // the Free Software Foundation, Inc., 59 Temple Place - Suite 330, 00018 // Boston, MA 02111-1307, USA. 00019 00020 #include "exception.h" 00021 00022 #ifndef EASSERT_H 00023 #define EASSERT_H 00024 00025 namespace cwidget 00026 { 00027 namespace util 00028 { 00030 class AssertionFailure : public Exception 00031 { 00032 std::string file; 00033 std::string func; 00034 std::string exp; 00035 std::string msg; 00036 size_t line; 00037 public: 00046 AssertionFailure(const std::string &file, 00047 size_t line, 00048 const std::string &func, 00049 const std::string &exp, 00050 const std::string &msg); 00051 00052 std::string errmsg() const; 00053 00055 std::string get_file() const 00056 { 00057 return file; 00058 } 00059 00061 size_t get_line() const 00062 { 00063 return line; 00064 } 00065 00067 std::string get_func() const 00068 { 00069 return func; 00070 } 00071 00073 std::string get_exp() const 00074 { 00075 return exp; 00076 } 00077 }; 00078 } 00079 } 00080 00084 #define eassert2(invariant, msg) \ 00085 do { if(!(invariant)) \ 00086 throw cwidget::util::AssertionFailure(__FILE__, __LINE__, __PRETTY_FUNCTION__, #invariant, msg); \ 00087 } while(0) 00088 00094 #define eassert(invariant) eassert2(invariant, "") 00095 00096 #endif