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.
This commit is contained in:
Ivan Popivanov
2014-10-14 22:37:12 -04:00
parent d864a9b7ea
commit 4707a6df83
5 changed files with 26 additions and 12 deletions

View File

@@ -114,7 +114,7 @@
<ClCompile> <ClCompile>
<Optimization>Disabled</Optimization> <Optimization>Disabled</Optimization>
<AdditionalIncludeDirectories>.\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories> <AdditionalIncludeDirectories>.\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<PreprocessorDefinitions>WIN32;_DEBUG;_WINDOWS;_USRDLL;Foundation_EXPORTS;PCRE_STATIC;%(PreprocessorDefinitions)</PreprocessorDefinitions> <PreprocessorDefinitions>WIN32;NOMINMAX;_DEBUG;_WINDOWS;_USRDLL;Foundation_EXPORTS;PCRE_STATIC;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<StringPooling>true</StringPooling> <StringPooling>true</StringPooling>
<MinimalRebuild>true</MinimalRebuild> <MinimalRebuild>true</MinimalRebuild>
<BasicRuntimeChecks>EnableFastChecks</BasicRuntimeChecks> <BasicRuntimeChecks>EnableFastChecks</BasicRuntimeChecks>
@@ -149,7 +149,7 @@
<FavorSizeOrSpeed>Speed</FavorSizeOrSpeed> <FavorSizeOrSpeed>Speed</FavorSizeOrSpeed>
<OmitFramePointers>true</OmitFramePointers> <OmitFramePointers>true</OmitFramePointers>
<AdditionalIncludeDirectories>.\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories> <AdditionalIncludeDirectories>.\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<PreprocessorDefinitions>WIN32;NDEBUG;_WINDOWS;_USRDLL;Foundation_EXPORTS;PCRE_STATIC;%(PreprocessorDefinitions)</PreprocessorDefinitions> <PreprocessorDefinitions>WIN32;NOMINMAX;NDEBUG;_WINDOWS;_USRDLL;Foundation_EXPORTS;PCRE_STATIC;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<PreprocessToFile>false</PreprocessToFile> <PreprocessToFile>false</PreprocessToFile>
<PreprocessSuppressLineNumbers>false</PreprocessSuppressLineNumbers> <PreprocessSuppressLineNumbers>false</PreprocessSuppressLineNumbers>
<PreprocessKeepComments>false</PreprocessKeepComments> <PreprocessKeepComments>false</PreprocessKeepComments>
@@ -189,7 +189,7 @@
<FavorSizeOrSpeed>Speed</FavorSizeOrSpeed> <FavorSizeOrSpeed>Speed</FavorSizeOrSpeed>
<OmitFramePointers>true</OmitFramePointers> <OmitFramePointers>true</OmitFramePointers>
<AdditionalIncludeDirectories>.\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories> <AdditionalIncludeDirectories>.\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<PreprocessorDefinitions>WIN32;NDEBUG;_WINDOWS;Foundation_EXPORTS;POCO_STATIC;PCRE_STATIC;%(PreprocessorDefinitions)</PreprocessorDefinitions> <PreprocessorDefinitions>WIN32;NOMINMAX;NDEBUG;_WINDOWS;Foundation_EXPORTS;POCO_STATIC;PCRE_STATIC;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<PreprocessToFile>false</PreprocessToFile> <PreprocessToFile>false</PreprocessToFile>
<PreprocessSuppressLineNumbers>false</PreprocessSuppressLineNumbers> <PreprocessSuppressLineNumbers>false</PreprocessSuppressLineNumbers>
<PreprocessKeepComments>false</PreprocessKeepComments> <PreprocessKeepComments>false</PreprocessKeepComments>
@@ -217,7 +217,7 @@
<ClCompile> <ClCompile>
<Optimization>Disabled</Optimization> <Optimization>Disabled</Optimization>
<AdditionalIncludeDirectories>.\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories> <AdditionalIncludeDirectories>.\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<PreprocessorDefinitions>WIN32;_DEBUG;_WINDOWS;Foundation_EXPORTS;POCO_STATIC;PCRE_STATIC;%(PreprocessorDefinitions)</PreprocessorDefinitions> <PreprocessorDefinitions>WIN32;NOMINMAX;_DEBUG;_WINDOWS;Foundation_EXPORTS;POCO_STATIC;PCRE_STATIC;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<StringPooling>true</StringPooling> <StringPooling>true</StringPooling>
<MinimalRebuild>true</MinimalRebuild> <MinimalRebuild>true</MinimalRebuild>
<BasicRuntimeChecks>EnableFastChecks</BasicRuntimeChecks> <BasicRuntimeChecks>EnableFastChecks</BasicRuntimeChecks>
@@ -244,7 +244,7 @@
<ClCompile> <ClCompile>
<Optimization>Disabled</Optimization> <Optimization>Disabled</Optimization>
<AdditionalIncludeDirectories>.\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories> <AdditionalIncludeDirectories>.\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<PreprocessorDefinitions>WIN32;_DEBUG;_WINDOWS;Foundation_EXPORTS;POCO_STATIC;PCRE_STATIC;%(PreprocessorDefinitions)</PreprocessorDefinitions> <PreprocessorDefinitions>WIN32;NOMINMAX;_DEBUG;_WINDOWS;Foundation_EXPORTS;POCO_STATIC;PCRE_STATIC;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<StringPooling>true</StringPooling> <StringPooling>true</StringPooling>
<MinimalRebuild>true</MinimalRebuild> <MinimalRebuild>true</MinimalRebuild>
<BasicRuntimeChecks>EnableFastChecks</BasicRuntimeChecks> <BasicRuntimeChecks>EnableFastChecks</BasicRuntimeChecks>
@@ -275,7 +275,7 @@
<FavorSizeOrSpeed>Speed</FavorSizeOrSpeed> <FavorSizeOrSpeed>Speed</FavorSizeOrSpeed>
<OmitFramePointers>true</OmitFramePointers> <OmitFramePointers>true</OmitFramePointers>
<AdditionalIncludeDirectories>.\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories> <AdditionalIncludeDirectories>.\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<PreprocessorDefinitions>WIN32;NDEBUG;_WINDOWS;Foundation_EXPORTS;POCO_STATIC;PCRE_STATIC;%(PreprocessorDefinitions)</PreprocessorDefinitions> <PreprocessorDefinitions>WIN32;NOMINMAX;NDEBUG;_WINDOWS;Foundation_EXPORTS;POCO_STATIC;PCRE_STATIC;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<PreprocessToFile>false</PreprocessToFile> <PreprocessToFile>false</PreprocessToFile>
<PreprocessSuppressLineNumbers>false</PreprocessSuppressLineNumbers> <PreprocessSuppressLineNumbers>false</PreprocessSuppressLineNumbers>
<PreprocessKeepComments>false</PreprocessKeepComments> <PreprocessKeepComments>false</PreprocessKeepComments>

View File

@@ -21,6 +21,7 @@
#include "Poco/Foundation.h" #include "Poco/Foundation.h"
#include <cstddef>
#include <string> #include <string>
#if defined(_DEBUG) #if defined(_DEBUG)
# include <iostream> # include <iostream>
@@ -40,7 +41,7 @@ class Foundation_API Bugcheck
/// automatically provide useful context information. /// automatically provide useful context information.
{ {
public: 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 /// An assertion failed. Break into the debugger, if
/// possible, then throw an AssertionViolationException. /// possible, then throw an AssertionViolationException.
@@ -71,7 +72,7 @@ public:
/// possible. /// possible.
protected: 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) #if defined(_DEBUG)
#define poco_assert_dbg(cond) \ #define poco_assert_dbg(cond) \
if (!(cond)) Poco::Bugcheck::assertion(#cond, __FILE__, __LINE__); else (void) 0 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 #else
#define poco_assert_msg_dbg(cond, text)
#define poco_assert_dbg(cond) #define poco_assert_dbg(cond)
#endif #endif
@@ -92,6 +97,8 @@ protected:
#define poco_assert(cond) \ #define poco_assert(cond) \
if (!(cond)) Poco::Bugcheck::assertion(#cond, __FILE__, __LINE__); else (void) 0 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) \ #define poco_check_ptr(ptr) \
if (!(ptr)) Poco::Bugcheck::nullPointer(#ptr, __FILE__, __LINE__); else (void) 0 if (!(ptr)) Poco::Bugcheck::nullPointer(#ptr, __FILE__, __LINE__); else (void) 0

View File

@@ -47,6 +47,9 @@ public:
typedef Int64 UtcTimeVal; /// monotonic UTC time value in 100 nanosecond resolution typedef Int64 UtcTimeVal; /// monotonic UTC time value in 100 nanosecond resolution
typedef Int64 TimeDiff; /// difference between two timestamps in microseconds typedef Int64 TimeDiff; /// difference between two timestamps in microseconds
static const TimeVal Min;
static const TimeVal Max;
Timestamp(); Timestamp();
/// Creates a timestamp with the current time. /// Creates a timestamp with the current time.

View File

@@ -23,10 +23,10 @@
namespace Poco { 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); Debugger::enter(std::string("Assertion violation: ") + cond + (text != NULL ? (std::string(" (") + text + std::string(")")) : ""), file, line);
throw AssertionViolationException(what(cond, 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; std::ostringstream str;
if (msg) str << msg << " "; if (msg) str << msg << " ";
if (text != NULL) str << "(" << text << ") ";
str << "in file \"" << file << "\", line " << line; str << "in file \"" << file << "\", line " << line;
return str.str(); return str.str();
} }

View File

@@ -18,6 +18,7 @@
#include "Poco/Timespan.h" #include "Poco/Timespan.h"
#include "Poco/Exception.h" #include "Poco/Exception.h"
#include <algorithm> #include <algorithm>
#include <limits>
#if defined(POCO_OS_FAMILY_UNIX) #if defined(POCO_OS_FAMILY_UNIX)
#include <time.h> #include <time.h>
#include <unistd.h> #include <unistd.h>
@@ -260,6 +261,8 @@ Timestamp& Timestamp::operator -= (const Timespan& span)
return *this -= span.totalMicroseconds(); return *this -= span.totalMicroseconds();
} }
const Timestamp::TimeVal Timestamp::Min = std::numeric_limits<Timestamp::TimeVal>::min();
const Timestamp::TimeVal Timestamp::Max = std::numeric_limits<Timestamp::TimeVal>::max();
#if defined(_WIN32) #if defined(_WIN32)