src/Utility/RuntimeError.h

説明を見る。
00001 // 
00002 // Copyright (c) 2005-2008 Kenichi Watanabe.
00003 // Copyright (c) 2005-2008 Yasuhiro Watari.
00004 // Copyright (c) 2005-2008 Hironori Ichibayashi.
00005 // Copyright (c) 2008-2009 Kazuo Horio.
00006 // Copyright (c) 2009-2013 Naruki Kurata.
00007 // Copyright (c) 2005-2013 Ryota Shioya.
00008 // Copyright (c) 2005-2013 Masahiro Goshima.
00009 // 
00010 // This software is provided 'as-is', without any express or implied
00011 // warranty. In no event will the authors be held liable for any damages
00012 // arising from the use of this software.
00013 // 
00014 // Permission is granted to anyone to use this software for any purpose,
00015 // including commercial applications, and to alter it and redistribute it
00016 // freely, subject to the following restrictions:
00017 // 
00018 // 1. The origin of this software must not be misrepresented; you must not
00019 // claim that you wrote the original software. If you use this software
00020 // in a product, an acknowledgment in the product documentation would be
00021 // appreciated but is not required.
00022 // 
00023 // 2. Altered source versions must be plainly marked as such, and must not be
00024 // misrepresented as being the original software.
00025 // 
00026 // 3. This notice may not be removed or altered from any source
00027 // distribution.
00028 // 
00029 // 
00030 
00031 
00032 //
00033 // Exception utility
00034 // *** DO NOT USE THESE UTILITY MACROS IN CONSTRUCTOR ***
00035 // These macros use exception mechanism and it can not work in constructor.
00036 //
00037 
00038 #ifndef UTILITY_RUNTIME_ERROR_H
00039 #define UTILITY_RUNTIME_ERROR_H
00040 
00041 #include "Utility/String.h"
00042 #include "SysDeps/Debug.h"
00043 
00044 namespace Onikiri
00045 {
00046     void SetAssertNoThrow( bool noThrow );
00047     void SuppressWaning( bool suppress );
00048     bool IsInException();
00049 
00050     struct RuntimeErrorInfo
00051     {
00052         const char* file; 
00053         int line;
00054         const char* func;
00055         const char* name;
00056         const char* cond;
00057         RuntimeErrorInfo(){};
00058         RuntimeErrorInfo(
00059             const char* fileArg, 
00060             int lineArg,
00061             const char* funcArg,
00062             const char* nameArg,
00063             const char* condArg
00064         ) : 
00065             file( fileArg ),
00066             line( lineArg ),
00067             func( funcArg ),
00068             name( nameArg ),
00069             cond( condArg )
00070         {
00071         };
00072     };
00073 
00074     void RuntimeErrorFunction( const RuntimeErrorInfo& info, const char* fmt, ... );
00075     void RuntimeWarningFunction( const RuntimeErrorInfo& info, const char* fmt, ... );
00076 
00077     void AssertFunction( const RuntimeErrorInfo& info, bool assertCond, const char* fmt, ... );
00078     void AssertFunction( const RuntimeErrorInfo& info, bool assertCond );
00079 
00080     // Source file & function name
00081     static const char* Who()
00082     {
00083         return "Unknown";
00084     }
00085     #define ONIKIRI_DEBUG_NAME Who()
00086 
00087     #define DEBUG_WHERE_ARGS() \
00088         ONIKIRI_DEBUG_FILE , ONIKIRI_DEBUG_LINE, ONIKIRI_DEBUG_FUNCTION, ONIKIRI_DEBUG_NAME
00089 
00090     #if defined(COMPILER_IS_GCC)
00091         // Runtime exception
00092         #define THROW_RUNTIME_ERROR(...) \
00093             RuntimeErrorFunction(   RuntimeErrorInfo( DEBUG_WHERE_ARGS(), "" ), ## __VA_ARGS__ )
00094 
00095         // Runtime warning message
00096         #define RUNTIME_WARNING(...) \
00097             RuntimeWarningFunction( RuntimeErrorInfo( DEBUG_WHERE_ARGS(), "" ), ## __VA_ARGS__ )
00098     #else
00099         // Runtime exception
00100         #define THROW_RUNTIME_ERROR(...) \
00101             RuntimeErrorFunction(   RuntimeErrorInfo( DEBUG_WHERE_ARGS(), "" ), __VA_ARGS__ )
00102 
00103         // Runtime warning message
00104         #define RUNTIME_WARNING(...) \
00105             RuntimeWarningFunction( RuntimeErrorInfo( DEBUG_WHERE_ARGS(), "" ), __VA_ARGS__ )
00106     #endif
00107 
00108     // Assert
00109     #ifdef ONIKIRI_DEBUG
00110         #if defined(COMPILER_IS_GCC)
00111             // Assert
00112             #define ASSERT(cond, ...) \
00113                 if(!(cond)){AssertFunction( RuntimeErrorInfo( DEBUG_WHERE_ARGS(), #cond ), false, ## __VA_ARGS__);}
00114         #else
00115             // C++0x supports a variable arguments length macro (__VA_ARGS__).
00116             // Assert
00117             #define ASSERT(cond, ...) \
00118                 if(!(cond)){AssertFunction( RuntimeErrorInfo( DEBUG_WHERE_ARGS(), #cond ), false, __VA_ARGS__);}
00119         #endif
00120     #else
00121         #if defined(COMPILER_IS_MSVC) || defined(COMPILER_IS_GCC)
00122             #define ASSERT(...)
00123         #else
00124             inline void AssertDummy(bool, const char* str, ...){};
00125             inline void AssertDummy(bool){};
00126             #define ASSERT AssertDummy
00127         #endif
00128     #endif
00129 
00130 
00131 } // namespace Onikiri
00132 
00133 
00134 #endif

Onikiri2に対してTue Jun 18 14:34:27 2013に生成されました。  doxygen 1.4.7