/[escript]/trunk/esysUtils/src/EsysAssert.h
ViewVC logotype

Contents of /trunk/esysUtils/src/EsysAssert.h

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1811 - (show annotations)
Thu Sep 25 23:11:13 2008 UTC (11 years ago) by ksteube
File MIME type: text/plain
File size: 2246 byte(s)
Copyright updated in all files

1
2 /*******************************************************
3 *
4 * Copyright (c) 2003-2008 by University of Queensland
5 * Earth Systems Science Computational Center (ESSCC)
6 * http://www.uq.edu.au/esscc
7 *
8 * Primary Business: Queensland, Australia
9 * Licensed under the Open Software License version 3.0
10 * http://www.opensource.org/licenses/osl-3.0.php
11 *
12 *******************************************************/
13
14
15 #if !defined escript_EsysAssert_20040330_H
16 #define escript_EsysAssert_20040330_H
17 #include "system_dep.h"
18 /**
19 \brief
20 EsysAssert is a MACRO that will throw an exception if the boolean
21 condition specified is false.
22
23 Description:
24 EsysAssert is conditionally compiled into code only when DOASSERT is
25 defined. When DOASSERT is not defined, the EsysAssert statement is
26 entirely removed from code.
27 */
28
29 //
30 // Note that the ANSI C Standard requires all headers to be idempotent except
31 // <assert.h> which is explicitly required not to be idempotent (section 4.1.2).
32 // This version of EsysAssert follows this requirement, consequently this
33 // part of the header is intentionally outside the single pass guard.
34 //
35
36 #undef EsysAssert
37
38 #if defined DOASSERT
39
40 //
41 // DOASSERT is defined, replace EsysAssert with Exception throw
42 //
43
44 #include "EsysAssertException.h"
45 #include <sstream>
46
47 namespace esysUtils {
48
49 class ErrStream
50 {
51 public:
52 template <typename Tmpl>
53 ErrStream& operator<<(Tmpl t)
54 {
55 std::stringstream str;
56 str << t;
57 m_msg += str.str();
58
59 return *this;
60 }
61
62 inline
63 const std::string &toString() const
64 {
65 return m_msg;
66 }
67
68 private:
69 std::string m_msg;
70 };
71
72 inline
73 std::ostream& operator<<(std::ostream& oStream,
74 const ErrStream& errStream)
75 {
76 oStream << errStream.toString();
77 return oStream;
78 }
79
80 }
81
82 #define EsysAssert(AssertTest,AssertMessage) \
83 (void)((AssertTest) || \
84 ((esysUtils::EsysAssertException::assertFailure(#AssertTest, __DATE__, __FILE__, __LINE__, \
85 (esysUtils::ErrStream()<<AssertMessage).toString())),0),0)
86
87 #else
88
89 //
90 // DOASSERT os not defined, replace EsysAssert with "NO-OP"
91 //
92
93 #define EsysAssert(AssertTest,AssertMessage) ((void)0)
94
95 #endif
96
97 #endif

Properties

Name Value
svn:eol-style native
svn:keywords Author Date Id Revision

  ViewVC Help
Powered by ViewVC 1.1.26