CrossFramework Library
|
00001 00006 #if defined(XBASE_INCLUDED_DIVIDECHECK_HPP) 00007 #else 00008 #define XBASE_INCLUDED_DIVIDECHECK_HPP 00009 00010 //------------------------------------------------------------ 00011 #include <XBase/RuntimeAssert.hpp> 00012 00013 //------------------------------------------------------------ 00014 namespace XBase { 00015 // 割り算チェックで使うモノたち用空間。 00016 struct DivideCheck 00017 { 00018 // Assert用メッセージ文字列。 00019 static const char* const AssertionMessage; 00020 00021 // アサートで止めつつ引数の値をそのまま返す。 00022 template< typename T > 00023 static T Error( const T& aRetVal ) 00024 { 00025 XBASE_NOT_REACH_ASSERT_MSG(AssertionMessage); 00026 return aRetVal; 00027 } 00028 }; 00029 } 00031 00032 00033 00034 00039 #define XBASE_DIV_ASSIGN( lhs , rhs ) \ 00040 do \ 00041 { \ 00042 if ( rhs == 0 ) \ 00043 { \ 00044 XBASE_NOT_REACH_ASSERT_MSG( ::XBase::DivideCheck::AssertionMessage ); \ 00045 } \ 00046 else \ 00047 { \ 00048 lhs /= rhs; \ 00049 } \ 00050 } while(0) 00051 00056 #define XBASE_DIV( aLHS , aRHS ) ( aRHS != 0 ? ( aLHS / aRHS ) : ::XBase::DivideCheck::Error( aLHS ) ) 00057 00059 00060 //------------------------------------------------------------ 00061 #endif 00062 // EOF