From 4707a6df8315a4c9942d9a826c6992a249a5b785 Mon Sep 17 00:00:00 2001 From: Ivan Popivanov Date: Tue, 14 Oct 2014 22:37:12 -0400 Subject: [PATCH 1/2] Added Timestamp::Min/Max which help define extreme timestamps, useful to initialize variables, especially for comparison. Added NOMINMAX as a preprocessor define for Windows. Otherwise some Windows headers define min/max as macros which interferes with std::numeric_limits::min/max Added poco_assert_msg and poco_assert_msg_dbg, which are equivalent to poco_assert and poco_assert_dbg, respectively, but support an extra text parameter. --- Foundation/Foundation_x64_vs120.vcxproj | 12 ++++++------ Foundation/include/Poco/Bugcheck.h | 11 +++++++++-- Foundation/include/Poco/Timestamp.h | 3 +++ Foundation/src/Bugcheck.cpp | 9 +++++---- Foundation/src/Timestamp.cpp | 3 +++ 5 files changed, 26 insertions(+), 12 deletions(-) diff --git a/Foundation/Foundation_x64_vs120.vcxproj b/Foundation/Foundation_x64_vs120.vcxproj index 4431dccec..3e811a8d4 100644 --- a/Foundation/Foundation_x64_vs120.vcxproj +++ b/Foundation/Foundation_x64_vs120.vcxproj @@ -114,7 +114,7 @@ Disabled .\include;%(AdditionalIncludeDirectories) - WIN32;_DEBUG;_WINDOWS;_USRDLL;Foundation_EXPORTS;PCRE_STATIC;%(PreprocessorDefinitions) + WIN32;NOMINMAX;_DEBUG;_WINDOWS;_USRDLL;Foundation_EXPORTS;PCRE_STATIC;%(PreprocessorDefinitions) true true EnableFastChecks @@ -149,7 +149,7 @@ Speed true .\include;%(AdditionalIncludeDirectories) - WIN32;NDEBUG;_WINDOWS;_USRDLL;Foundation_EXPORTS;PCRE_STATIC;%(PreprocessorDefinitions) + WIN32;NOMINMAX;NDEBUG;_WINDOWS;_USRDLL;Foundation_EXPORTS;PCRE_STATIC;%(PreprocessorDefinitions) false false false @@ -189,7 +189,7 @@ Speed true .\include;%(AdditionalIncludeDirectories) - WIN32;NDEBUG;_WINDOWS;Foundation_EXPORTS;POCO_STATIC;PCRE_STATIC;%(PreprocessorDefinitions) + WIN32;NOMINMAX;NDEBUG;_WINDOWS;Foundation_EXPORTS;POCO_STATIC;PCRE_STATIC;%(PreprocessorDefinitions) false false false @@ -217,7 +217,7 @@ Disabled .\include;%(AdditionalIncludeDirectories) - WIN32;_DEBUG;_WINDOWS;Foundation_EXPORTS;POCO_STATIC;PCRE_STATIC;%(PreprocessorDefinitions) + WIN32;NOMINMAX;_DEBUG;_WINDOWS;Foundation_EXPORTS;POCO_STATIC;PCRE_STATIC;%(PreprocessorDefinitions) true true EnableFastChecks @@ -244,7 +244,7 @@ Disabled .\include;%(AdditionalIncludeDirectories) - WIN32;_DEBUG;_WINDOWS;Foundation_EXPORTS;POCO_STATIC;PCRE_STATIC;%(PreprocessorDefinitions) + WIN32;NOMINMAX;_DEBUG;_WINDOWS;Foundation_EXPORTS;POCO_STATIC;PCRE_STATIC;%(PreprocessorDefinitions) true true EnableFastChecks @@ -275,7 +275,7 @@ Speed true .\include;%(AdditionalIncludeDirectories) - WIN32;NDEBUG;_WINDOWS;Foundation_EXPORTS;POCO_STATIC;PCRE_STATIC;%(PreprocessorDefinitions) + WIN32;NOMINMAX;NDEBUG;_WINDOWS;Foundation_EXPORTS;POCO_STATIC;PCRE_STATIC;%(PreprocessorDefinitions) false false false diff --git a/Foundation/include/Poco/Bugcheck.h b/Foundation/include/Poco/Bugcheck.h index f48ffb27c..0bd62eae8 100644 --- a/Foundation/include/Poco/Bugcheck.h +++ b/Foundation/include/Poco/Bugcheck.h @@ -21,6 +21,7 @@ #include "Poco/Foundation.h" +#include #include #if defined(_DEBUG) # include @@ -40,7 +41,7 @@ class Foundation_API Bugcheck /// automatically provide useful context information. { public: - static void assertion(const char* cond, const char* file, int line); + static void assertion(const char* cond, const char* file, int line, const char* text = NULL); /// An assertion failed. Break into the debugger, if /// possible, then throw an AssertionViolationException. @@ -71,7 +72,7 @@ public: /// possible. protected: - static std::string what(const char* msg, const char* file, int line); + static std::string what(const char* msg, const char* file, int line, const char* text = NULL); }; @@ -84,7 +85,11 @@ protected: #if defined(_DEBUG) #define poco_assert_dbg(cond) \ if (!(cond)) Poco::Bugcheck::assertion(#cond, __FILE__, __LINE__); else (void) 0 + + #define poco_assert_msg_dbg(cond, text) \ + if (!(cond)) Poco::Bugcheck::assertion(#cond, __FILE__, __LINE__, text); else (void) 0 #else + #define poco_assert_msg_dbg(cond, text) #define poco_assert_dbg(cond) #endif @@ -92,6 +97,8 @@ protected: #define poco_assert(cond) \ if (!(cond)) Poco::Bugcheck::assertion(#cond, __FILE__, __LINE__); else (void) 0 +#define poco_assert_msg(cond, text) \ + if (!(cond)) Poco::Bugcheck::assertion(#cond, __FILE__, __LINE__, text); else (void) 0 #define poco_check_ptr(ptr) \ if (!(ptr)) Poco::Bugcheck::nullPointer(#ptr, __FILE__, __LINE__); else (void) 0 diff --git a/Foundation/include/Poco/Timestamp.h b/Foundation/include/Poco/Timestamp.h index 2ce171048..3cc79cc03 100644 --- a/Foundation/include/Poco/Timestamp.h +++ b/Foundation/include/Poco/Timestamp.h @@ -47,6 +47,9 @@ public: typedef Int64 UtcTimeVal; /// monotonic UTC time value in 100 nanosecond resolution typedef Int64 TimeDiff; /// difference between two timestamps in microseconds + static const TimeVal Min; + static const TimeVal Max; + Timestamp(); /// Creates a timestamp with the current time. diff --git a/Foundation/src/Bugcheck.cpp b/Foundation/src/Bugcheck.cpp index ea2cfe9f5..c7609bc50 100644 --- a/Foundation/src/Bugcheck.cpp +++ b/Foundation/src/Bugcheck.cpp @@ -23,10 +23,10 @@ namespace Poco { -void Bugcheck::assertion(const char* cond, const char* file, int line) +void Bugcheck::assertion(const char* cond, const char* file, int line, const char* text) { - Debugger::enter(std::string("Assertion violation: ") + cond, file, line); - throw AssertionViolationException(what(cond, file, line)); + Debugger::enter(std::string("Assertion violation: ") + cond + (text != NULL ? (std::string(" (") + text + std::string(")")) : ""), file, line); + throw AssertionViolationException(what(cond, file, line, text)); } @@ -100,10 +100,11 @@ void Bugcheck::debugger(const char* msg, const char* file, int line) } -std::string Bugcheck::what(const char* msg, const char* file, int line) +std::string Bugcheck::what(const char* msg, const char* file, int line, const char* text) { std::ostringstream str; if (msg) str << msg << " "; + if (text != NULL) str << "(" << text << ") "; str << "in file \"" << file << "\", line " << line; return str.str(); } diff --git a/Foundation/src/Timestamp.cpp b/Foundation/src/Timestamp.cpp index a3c8a55f0..f889460b3 100644 --- a/Foundation/src/Timestamp.cpp +++ b/Foundation/src/Timestamp.cpp @@ -18,6 +18,7 @@ #include "Poco/Timespan.h" #include "Poco/Exception.h" #include +#include #if defined(POCO_OS_FAMILY_UNIX) #include #include @@ -260,6 +261,8 @@ Timestamp& Timestamp::operator -= (const Timespan& span) return *this -= span.totalMicroseconds(); } +const Timestamp::TimeVal Timestamp::Min = std::numeric_limits::min(); +const Timestamp::TimeVal Timestamp::Max = std::numeric_limits::max(); #if defined(_WIN32) From 3247d07bd0e11fa70a5d4b82aedab0416e46638d Mon Sep 17 00:00:00 2001 From: Ivan Popivanov Date: Wed, 15 Oct 2014 05:13:25 -0400 Subject: [PATCH 2/2] Removed the NOMINMAX compiler option, using undefs to avoid the conflict between std::numeric_limits and Windows headers. --- Foundation/Foundation_x64_vs120.vcxproj | 12 ++++++------ Foundation/src/Timestamp.cpp | 6 ++++++ 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/Foundation/Foundation_x64_vs120.vcxproj b/Foundation/Foundation_x64_vs120.vcxproj index 3e811a8d4..4431dccec 100644 --- a/Foundation/Foundation_x64_vs120.vcxproj +++ b/Foundation/Foundation_x64_vs120.vcxproj @@ -114,7 +114,7 @@ Disabled .\include;%(AdditionalIncludeDirectories) - WIN32;NOMINMAX;_DEBUG;_WINDOWS;_USRDLL;Foundation_EXPORTS;PCRE_STATIC;%(PreprocessorDefinitions) + WIN32;_DEBUG;_WINDOWS;_USRDLL;Foundation_EXPORTS;PCRE_STATIC;%(PreprocessorDefinitions) true true EnableFastChecks @@ -149,7 +149,7 @@ Speed true .\include;%(AdditionalIncludeDirectories) - WIN32;NOMINMAX;NDEBUG;_WINDOWS;_USRDLL;Foundation_EXPORTS;PCRE_STATIC;%(PreprocessorDefinitions) + WIN32;NDEBUG;_WINDOWS;_USRDLL;Foundation_EXPORTS;PCRE_STATIC;%(PreprocessorDefinitions) false false false @@ -189,7 +189,7 @@ Speed true .\include;%(AdditionalIncludeDirectories) - WIN32;NOMINMAX;NDEBUG;_WINDOWS;Foundation_EXPORTS;POCO_STATIC;PCRE_STATIC;%(PreprocessorDefinitions) + WIN32;NDEBUG;_WINDOWS;Foundation_EXPORTS;POCO_STATIC;PCRE_STATIC;%(PreprocessorDefinitions) false false false @@ -217,7 +217,7 @@ Disabled .\include;%(AdditionalIncludeDirectories) - WIN32;NOMINMAX;_DEBUG;_WINDOWS;Foundation_EXPORTS;POCO_STATIC;PCRE_STATIC;%(PreprocessorDefinitions) + WIN32;_DEBUG;_WINDOWS;Foundation_EXPORTS;POCO_STATIC;PCRE_STATIC;%(PreprocessorDefinitions) true true EnableFastChecks @@ -244,7 +244,7 @@ Disabled .\include;%(AdditionalIncludeDirectories) - WIN32;NOMINMAX;_DEBUG;_WINDOWS;Foundation_EXPORTS;POCO_STATIC;PCRE_STATIC;%(PreprocessorDefinitions) + WIN32;_DEBUG;_WINDOWS;Foundation_EXPORTS;POCO_STATIC;PCRE_STATIC;%(PreprocessorDefinitions) true true EnableFastChecks @@ -275,7 +275,7 @@ Speed true .\include;%(AdditionalIncludeDirectories) - WIN32;NOMINMAX;NDEBUG;_WINDOWS;Foundation_EXPORTS;POCO_STATIC;PCRE_STATIC;%(PreprocessorDefinitions) + WIN32;NDEBUG;_WINDOWS;Foundation_EXPORTS;POCO_STATIC;PCRE_STATIC;%(PreprocessorDefinitions) false false false diff --git a/Foundation/src/Timestamp.cpp b/Foundation/src/Timestamp.cpp index f889460b3..2497eb291 100644 --- a/Foundation/src/Timestamp.cpp +++ b/Foundation/src/Timestamp.cpp @@ -18,6 +18,12 @@ #include "Poco/Timespan.h" #include "Poco/Exception.h" #include +#ifdef min + #undef min +#endif +#ifdef max + #undef max +#endif #include #if defined(POCO_OS_FAMILY_UNIX) #include