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:
Коммит
5b74121119
|
@ -21,6 +21,7 @@
|
|||
|
||||
|
||||
#include "Poco/Foundation.h"
|
||||
#include <cstddef>
|
||||
#include <string>
|
||||
#if defined(_DEBUG)
|
||||
# include <iostream>
|
||||
|
@ -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
|
||||
|
|
|
@ -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.
|
||||
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
|
|
|
@ -18,6 +18,13 @@
|
|||
#include "Poco/Timespan.h"
|
||||
#include "Poco/Exception.h"
|
||||
#include <algorithm>
|
||||
#ifdef min
|
||||
#undef min
|
||||
#endif
|
||||
#ifdef max
|
||||
#undef max
|
||||
#endif
|
||||
#include <limits>
|
||||
#if defined(POCO_OS_FAMILY_UNIX)
|
||||
#include <time.h>
|
||||
#include <unistd.h>
|
||||
|
@ -260,6 +267,8 @@ Timestamp& Timestamp::operator -= (const Timespan& span)
|
|||
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)
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче