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

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

Parent Directory Parent Directory | Revision Log Revision Log


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

1 ksteube 1312
2     /*******************************************************
3 ksteube 1811 *
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 ksteube 1312
14 ksteube 1811
15 jgs 102 #if !defined escript_EsysAssert_20040330_H
16 jgs 82 #define escript_EsysAssert_20040330_H
17 woo409 757 #include "system_dep.h"
18 jgs 82 /**
19     \brief
20     EsysAssert is a MACRO that will throw an exception if the boolean
21 jgs 102 condition specified is false.
22 jgs 82
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 jgs 102 // <assert.h> which is explicitly required not to be idempotent (section 4.1.2).
32 jgs 82 // This version of EsysAssert follows this requirement, consequently this
33 jgs 102 // part of the header is intentionally outside the single pass guard.
34 jgs 82 //
35    
36 jgs 468 #undef EsysAssert
37 jgs 82
38     #if defined DOASSERT
39 jgs 102
40 jgs 82 //
41     // DOASSERT is defined, replace EsysAssert with Exception throw
42     //
43 jgs 102
44 jgs 82 #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 phornby 1628 inline
63 jgs 82 const std::string &toString() const
64     {
65     return m_msg;
66     }
67    
68     private:
69     std::string m_msg;
70     };
71    
72 phornby 1628 inline
73 ksteube 1670 std::ostream& operator<<(std::ostream& oStream,
74 phornby 1628 const ErrStream& errStream)
75 jgs 82 {
76     oStream << errStream.toString();
77     return oStream;
78     }
79    
80     }
81    
82     #define EsysAssert(AssertTest,AssertMessage) \
83 jgs 102 (void)((AssertTest) || \
84     ((esysUtils::EsysAssertException::assertFailure(#AssertTest, __DATE__, __FILE__, __LINE__, \
85     (esysUtils::ErrStream()<<AssertMessage).toString())),0),0)
86 jgs 82
87     #else
88 jgs 102
89 jgs 82 //
90     // DOASSERT os not defined, replace EsysAssert with "NO-OP"
91     //
92 jgs 102
93 jgs 82 #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