From 57bcbc6cdbeba287f7664f9f3b6ff259a82a5629 Mon Sep 17 00:00:00 2001 From: bolero-MURAKAMI Date: Wed, 20 Mar 2013 02:21:25 +0900 Subject: [PATCH] fix SPROUT_ASSERT --- sprout/assert.hpp | 106 ++++++++++++++++++++++++++++++++++------------ 1 file changed, 80 insertions(+), 26 deletions(-) diff --git a/sprout/assert.hpp b/sprout/assert.hpp index 114404d6..222aac47 100644 --- a/sprout/assert.hpp +++ b/sprout/assert.hpp @@ -36,35 +36,54 @@ #elif defined(SPROUT_ENABLE_ASSERT_HANDLER) -namespace sprout_adl { - SPROUT_CONSTEXPR sprout::not_found_via_adl assertion_failed(...); +namespace sprout { + // + // assertion_info + // + class assertion_info { + private: + char const* expr_; + char const* function_; + char const* file_; + long line_; + public: + SPROUT_CONSTEXPR assertion_info(char const* expr, char const* function, char const* file, long line) + : expr_(expr), function_(function), file_(file), line_(line) + {} + SPROUT_CONSTEXPR char const* expr() const SPROUT_NOEXCEPT { + return expr_; + } + SPROUT_CONSTEXPR char const* function() const SPROUT_NOEXCEPT { + return function_; + } + SPROUT_CONSTEXPR char const* file() const SPROUT_NOEXCEPT { + return file_; + } + SPROUT_CONSTEXPR long line() const SPROUT_NOEXCEPT { + return line_; + } + }; + + // + // assertion_failed + // * user defined + // + void + assertion_failed(sprout::assertion_info const&); } // namespace sprout_adl -namespace sprout_assertion_detail { - using sprout_adl::assertion_failed; - - //template - inline SPROUT_CONSTEXPR bool - call_assertion_failed(bool cond, char const* formatted, char const* expr, char const* function, char const* file, long line) { - return cond ? true - : (assertion_failed(expr, function, file, line), false) - ; - } -} // namespace sprout - namespace sprout { -// // -// // assertion_failed -// // * user defined -// // -// void -// assertion_failed(char const* expr, char const* function, char const* file, long line); - namespace detail { + inline bool + assertion_failed(bool cond, char const* formatted, char const* expr, char const* function, char const* file, long line) { + return cond ? true + : ((void)sprout::assertion_failed(sprout::assertion_info(expr, function, file, line)), false) + ; + } inline SPROUT_CONSTEXPR bool assertion_check(bool cond, char const* formatted, char const* expr, char const* function, char const* file, long line) { return cond ? true - : sprout_assertion_detail::call_assertion_failed(cond, formatted, expr, function, file, line) + : sprout::detail::assertion_failed(cond, formatted, expr, function, file, line) ; } } // namespace detail @@ -111,22 +130,57 @@ namespace sprout { #elif defined(SPROUT_ENABLE_ASSERT_HANDLER) namespace sprout { + // + // assertion_info_msg + // + class assertion_info_msg { + private: + char const* expr_; + char const* msg_; + char const* function_; + char const* file_; + long line_; + public: + SPROUT_CONSTEXPR assertion_info_msg(char const* expr, char const* msg, char const* function, char const* file, long line) + : expr_(expr), msg_(msg), function_(function), file_(file), line_(line) + {} + SPROUT_CONSTEXPR char const* expr() const SPROUT_NOEXCEPT { + return expr_; + } + SPROUT_CONSTEXPR char const* msg() const SPROUT_NOEXCEPT { + return msg_; + } + SPROUT_CONSTEXPR char const* function() const SPROUT_NOEXCEPT { + return function_; + } + SPROUT_CONSTEXPR char const* file() const SPROUT_NOEXCEPT { + return file_; + } + SPROUT_CONSTEXPR long line() const SPROUT_NOEXCEPT { + return line_; + } + }; + // // assertion_failed_msg // * user defined // void - assertion_failed_msg(char const* expr, char const* msg, char const* function, char const* file, long line); + assertion_failed_msg(sprout::assertion_info_msg const&); +} // namespace sprout_adl +namespace sprout { namespace detail { inline bool - assertion_failed_msg(char const* formatted, char const* expr, char const* msg, char const* function, char const* file, long line) { - return sprout::assertion_failed_msg(expr, msg, function, file, line), false; + assertion_failed_msg(bool cond, char const* formatted, char const* expr, char const* msg, char const* function, char const* file, long line) { + return cond ? true + : ((void)sprout::assertion_failed_msg(sprout::assertion_info_msg(expr, msg, function, file, line)), false) + ; } inline SPROUT_CONSTEXPR bool assertion_check_msg(bool cond, char const* formatted, char const* expr, char const* msg, char const* function, char const* file, long line) { return cond ? true - : sprout::detail::assertion_failed_msg(formatted, expr, msg, function, file, line) + : sprout::detail::assertion_failed_msg(cond, formatted, expr, msg, function, file, line) ; } } // namespace detail