escript
Revision_
|
00001 00002 /***************************************************************************** 00003 * 00004 * Copyright (c) 2003-2014 by University of Queensland 00005 * http://www.uq.edu.au 00006 * 00007 * Primary Business: Queensland, Australia 00008 * Licensed under the Open Software License version 3.0 00009 * http://www.opensource.org/licenses/osl-3.0.php 00010 * 00011 * Development until 2012 by Earth Systems Science Computational Center (ESSCC) 00012 * Development 2012-2013 by School of Earth Sciences 00013 * Development from 2014 by Centre for Geoscience Computing (GeoComp) 00014 * 00015 *****************************************************************************/ 00016 00017 00018 #if !defined escript_EsysAssert_20040330_H 00019 #define escript_EsysAssert_20040330_H 00020 #include "system_dep.h" 00032 // 00033 // Note that the ANSI C Standard requires all headers to be idempotent except 00034 // <assert.h> which is explicitly required not to be idempotent (section 4.1.2). 00035 // This version of EsysAssert follows this requirement, consequently this 00036 // part of the header is intentionally outside the single pass guard. 00037 // 00038 00039 #undef EsysAssert 00040 00041 #if defined DOASSERT 00042 00043 // 00044 // DOASSERT is defined, replace EsysAssert with Exception throw 00045 // 00046 00047 #include "EsysAssertException.h" 00048 #include <sstream> 00049 00050 namespace esysUtils { 00051 00052 class ErrStream 00053 { 00054 public: 00055 template <typename Tmpl> 00056 ErrStream& operator<<(Tmpl t) 00057 { 00058 std::stringstream str; 00059 str << t; 00060 m_msg += str.str(); 00061 00062 return *this; 00063 } 00064 00065 inline 00066 const std::string &toString() const 00067 { 00068 return m_msg; 00069 } 00070 00071 private: 00072 std::string m_msg; 00073 }; 00074 00075 inline 00076 std::ostream& operator<<(std::ostream& oStream, 00077 const ErrStream& errStream) 00078 { 00079 oStream << errStream.toString(); 00080 return oStream; 00081 } 00082 00083 } 00084 00085 #define EsysAssert(AssertTest,AssertMessage) \ 00086 (void)((AssertTest) || \ 00087 ((esysUtils::EsysAssertException::assertFailure(#AssertTest, __DATE__, __FILE__, __LINE__, \ 00088 (esysUtils::ErrStream()<<AssertMessage).toString())),0),0) 00089 00090 #else 00091 00092 // 00093 // DOASSERT os not defined, replace EsysAssert with "NO-OP" 00094 // 00095 00096 #define EsysAssert(AssertTest,AssertMessage) ((void)0) 00097 00098 #endif 00099 00100 #endif