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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 757 - (hide annotations)
Mon Jun 26 13:12:56 2006 UTC (13 years, 2 months ago) by woo409
File MIME type: text/plain
File size: 2443 byte(s)
+ Merge of intelc_win32 branch (revision 741:755) with trunk. Tested on iVEC altix (run_tests and py_tests all pass)

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

Properties

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

  ViewVC Help
Powered by ViewVC 1.1.26