CPN
Computational Process Networks
ThrowingAssert.h
Go to the documentation of this file.
1 //=============================================================================
2 //Computational Process Networks class library Copyright (C) 1997-2006 Gregory
3 //E. Allen and The University of Texas
4 //
5 // This library is free software; you can redistribute it and/or modify it
6 // under the terms of the GNU Library General Public License as published by
7 // the Free Software Foundation; either version 2 of the License, or (at your
8 // option) any later version.
9 //
10 // This library is distributed in the hope that it will be useful, but WITHOUT
11 // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 // FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
13 // License for more details.
14 //
15 // The GNU Public License is available in the file LICENSE, or you can write
16 // to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
17 // MA 02111-1307, USA, or you can find it on the World Wide Web at
18 // http://www.fsf.org.
19 //=============================================================================
37 #ifndef THROWINGASSERT_H
38 #define THROWINGASSERT_H
39 #pragma once
40 #include <cpn/common.h>
41 #include <cpn/utils/Exception.h>
42 
46 class AssertException : public Exception {
47 public:
48  AssertException(const std::string &msg) throw();
49  virtual ~AssertException() throw();
50  virtual const char *what() const throw();
51 private:
52  std::string message;
53 };
54 
55 bool __ASSERT(const char *exp, const char *file, int line, const char *func, bool die) __attribute__((noreturn));
56 
57 bool __ASSERT(const char *exp, const char *file, int line, const char *func, bool die, const std::string &msg) __attribute__((noreturn));
58 
59 bool __ASSERT(const char *exp, const char *file, int line, const char *func, bool die, const char *fmt, ...) __attribute__((noreturn));
60 
61 #ifndef NDEBUG
62 #define ASSERT(exp, ...) (exp ? true : __ASSERT(#exp, __FILE__, __LINE__, __PRETTY_FUNCTION__, false, ## __VA_ARGS__))
63 #define ASSERT_ABORT(exp, ...) (exp ? true : __ASSERT(#exp, __FILE__, __LINE__, __PRETTY_FUNCTION__, true, ## __VA_ARGS__))
64 #define ENSURE(exp, ...) (exp ? true : __ASSERT(#exp, __FILE__, __LINE__, __PRETTY_FUNCTION__, false, ## __VA_ARGS__))
65 #define ENSURE_ABORT(exp, ...) (exp ? true : __ASSERT(#exp, __FILE__, __LINE__, __PRETTY_FUNCTION__, true, ## __VA_ARGS__))
66 #else
67 #define ASSERT(exp, ...)
68 #define ASSERT_ABORT(exp, ...)
69 #define ENSURE(exp, ...) exp
70 #define ENSURE_ABORT(exp, ...) exp
71 #endif
72 
73 #endif
74 
bool __ASSERT(const char *exp, const char *file, int line, const char *func, bool die) __attribute__((noreturn))
The exception thrown by the ASSERT macro.
std::string message
AssertException(const std::string &msg)
virtual ~AssertException()
virtual const char * what() const