cwidget 0.5.18
eassert.h
1// eassert.h -*-c++-*-
2//
3// Copyright (C) 2005, 2007 Daniel Burrows
4//
5// This program is free software; you can redistribute it and/or
6// modify it under the terms of the GNU General Public License as
7// published by the Free Software Foundation; either version 2 of
8// the License, or (at your option) any later version.
9//
10// This program is distributed in the hope that it will be useful,
11// but WITHOUT ANY WARRANTY; without even the implied warranty of
12// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13// General Public License for more details.
14//
15// You should have received a copy of the GNU General Public License
16// along with this program; see the file COPYING. If not, write to
17// the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18// Boston, MA 02111-1307, USA.
19
20#include "exception.h"
21
22#ifndef EASSERT_H
23#define EASSERT_H
24
25namespace cwidget
26{
27 namespace util
28 {
31 {
32 std::string file;
33 std::string func;
34 std::string exp;
35 std::string msg;
36 size_t line;
37 public:
46 AssertionFailure(const std::string &file,
47 size_t line,
48 const std::string &func,
49 const std::string &exp,
50 const std::string &msg);
51
52 std::string errmsg() const;
53
55 std::string get_file() const
56 {
57 return file;
58 }
59
61 size_t get_line() const
62 {
63 return line;
64 }
65
67 std::string get_func() const
68 {
69 return func;
70 }
71
73 std::string get_exp() const
74 {
75 return exp;
76 }
77 };
78 }
79}
80
84#define eassert2(invariant, msg) \
85 do { if(!(invariant)) \
86 throw cwidget::util::AssertionFailure(__FILE__, __LINE__, __PRETTY_FUNCTION__, #invariant, msg); \
87 } while(0)
88
94#define eassert(invariant) eassert2(invariant, "")
95
96#endif
Represents an assertion failure.
Definition eassert.h:31
std::string get_file() const
Definition eassert.h:55
std::string get_exp() const
Definition eassert.h:73
std::string get_func() const
Definition eassert.h:67
size_t get_line() const
Definition eassert.h:61
Definition exception.h:38
The namespace containing everything defined by cwidget.
Definition columnify.cc:28