Merge pull request #573 from ivannp/assertmsg

Added Timestamp::Min/Max. Added poco_assert_msg and poco_assert_msg_dbg.
This commit is contained in:
Günter Obiltschnig 2014-11-06 11:40:17 +01:00
commit 5b74121119
4 changed files with 26 additions and 6 deletions

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,13 @@
#include "Poco/Timespan.h" #include "Poco/Timespan.h"
#include "Poco/Exception.h" #include "Poco/Exception.h"
#include <algorithm> #include <algorithm>
#ifdef min
#undef min
#endif
#ifdef max
#undef max
#endif
#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 +267,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)