77 Failure(
const char* file,
int line,
const char* expr)
80 std::size_t remain =
sizeof m_buf;
82 pBuf = concatCString(pBuf, remain, file);
83 pBuf = concatCString(pBuf, remain,
"(");
85 toCString(lineBuf,
sizeof lineBuf,
static_cast<unsigned int>(line));
86 pBuf = concatCString(pBuf, remain, lineBuf);
87 pBuf = concatCString(pBuf, remain,
"): Assertion failed (");
88 pBuf = concatCString(pBuf, remain, expr);
89 concatCString(pBuf, remain,
")");
103 static void assertFail(
const char* file,
int line,
const char* expr)
105 Failure failure(file, line, expr);
108 handler->
handle(failure.message());
110#ifndef CPPELIB_NO_EXCEPTIONS
115 static void setHandler(AssertHandler* handler)
117 getHandler() = handler;
123 static AssertHandler*& getHandler()
125 static AssertHandler* handler;
129 static void toCString(
char* buf, std::size_t size,
unsigned int val)
134 const std::size_t TMP_SIZE = 16U;
136 const char*
const numStr =
"0123456789";
138 for (i = 0U; i < TMP_SIZE - 1U; i++) {
142 tmp[i] = numStr[val % 10U];
145 const std::size_t tmpLen = i;
146 for (i = 0U; i < tmpLen; i++) {
148 buf[i] = tmp[tmpLen - i - 1U];
150 buf[size - 1U] =
'\0';
157 static char* concatCString(
char* buf, std::size_t& remain,
const char* str)
162 std::size_t len = copyCString(buf, remain, str);
167 static std::size_t copyCString(
char* to, std::size_t size,
const char* from)
172 const char* p = from;
174 for (std::size_t i = 0U; i < size; i++) {
183 to[size - 1U] =
'\0';