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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1670 - (hide annotations)
Thu Jul 24 04:30:43 2008 UTC (11 years, 1 month ago) by ksteube
File MIME type: text/plain
File size: 2281 byte(s)
Fix variable declaration to compile under MPI

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

Properties

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

  ViewVC Help
Powered by ViewVC 1.1.26