18 #if defined(QT_CORE_LIB) 20 #include <QtCore/QByteArray> 21 #include <QtCore/QString> 22 #include <QtCore/QUrl> 25 #if !defined(NX_KIT_API) 36 NX_KIT_API uint8_t* unalignedPtr(
void* data);
38 NX_KIT_API std::string format(std::string formatStr, ...);
40 NX_KIT_API
bool isAsciiPrintable(
int c);
43 NX_KIT_API
char pathSeparator();
45 NX_KIT_API
size_t commonPrefixSize(
const std::string& s1,
const std::string& s2);
51 NX_KIT_API
const char* relativeSrcFilename(
const char* file);
53 NX_KIT_API std::string fileBaseNameWithoutExt(
const char* file);
59 #if defined(NX_PRINT_TO_QDEBUG) 60 #define NX_DEBUG_STREAM qDebug().nospace().noquote() 62 static inline QDebug operator<<(QDebug d,
const std::string& s)
64 return d << QString::fromStdString(s);
68 #if !defined(NX_DEBUG_INI) 70 #define NX_DEBUG_INI ini(). 73 #if !defined(NX_DEBUG_ENABLE_OUTPUT) 75 #define NX_DEBUG_ENABLE_OUTPUT NX_DEBUG_INI enableOutput 78 #if !defined(NX_PRINT_PREFIX) 80 #define NX_PRINT_PREFIX nx::kit::debug::detail::printPrefix(__FILE__) 83 #if !defined(NX_DEBUG_STREAM) 85 #define NX_DEBUG_STREAM *nx::kit::debug::stream() 88 #if !defined(NX_DEBUG_ENDL) 90 #define NX_DEBUG_ENDL << std::endl 97 NX_KIT_API std::ostream*& stream();
99 #if !defined(NX_PRINT) 106 ( []() { struct Endl { ~Endl() { NX_DEBUG_STREAM NX_DEBUG_ENDL; } }; \ 107 return std::make_shared<Endl>(); }() ) , \ 108 NX_DEBUG_STREAM << NX_PRINT_PREFIX 115 if (!(NX_DEBUG_ENABLE_OUTPUT)) {} else NX_PRINT 127 #define NX_KIT_ASSERT(...) \ 128 NX_KIT_DEBUG_DETAIL_MSVC_EXPAND(NX_KIT_DEBUG_DETAIL_GET_3RD_ARG( \ 129 __VA_ARGS__, NX_KIT_DEBUG_DETAIL_ASSERT2, NX_KIT_DEBUG_DETAIL_ASSERT1, \ 130 args_required)(__VA_ARGS__)) 139 NX_PRINT << "####### LL line " << __LINE__ \ 140 << NX_KIT_DEBUG_DETAIL_THREAD_ID() \ 141 << ", file " << nx::kit::debug::relativeSrcFilename(__FILE__); 147 std::string toString(T value);
152 #define NX_PRINT_VALUE(VALUE) \ 153 NX_PRINT << "####### " #VALUE ": " << nx::kit::debug::toString((VALUE)) 158 #define NX_PRINT_HEX_DUMP(TAG, BYTES, SIZE) \ 159 nx::kit::debug::detail::printHexDump( \ 160 NX_KIT_DEBUG_DETAIL_PRINT_FUNC, (TAG), (const char*) (BYTES), (int) (SIZE)) 165 #if !defined(NX_DEBUG_ENABLE_TIME) 167 #define NX_DEBUG_ENABLE_TIME NX_DEBUG_INI enableTime 173 #define NX_TIME_BEGIN(TAG) \ 174 nx::kit::debug::detail::Timer nxTimer_##TAG( \ 175 (NX_DEBUG_ENABLE_TIME), NX_KIT_DEBUG_DETAIL_PRINT_FUNC, #TAG) 181 #define NX_TIME_MARK(TAG, MARK) do \ 183 if (NX_DEBUG_ENABLE_TIME) \ 184 nxTimer_##TAG.mark((MARK)); \ 190 #define NX_TIME_END(TAG) do \ 192 if (NX_DEBUG_ENABLE_TIME) \ 193 nxTimer_##TAG.finish(); \ 199 #if !defined(NX_DEBUG_ENABLE_FPS) 201 #define NX_DEBUG_ENABLE_FPS NX_DEBUG_INI enableFps 208 #define NX_FPS(TAG, ...) do \ 210 if (NX_KIT_DEBUG_DETAIL_CONCAT(NX_DEBUG_ENABLE_FPS, TAG)) \ 212 static nx::kit::debug::detail::Fps fps( \ 213 NX_KIT_DEBUG_DETAIL_PRINT_FUNC, #TAG); \ 214 fps.mark(__VA_ARGS__); \ 225 #define NX_KIT_DEBUG_DETAIL_MSVC_EXPAND(ARG) ARG 228 #define NX_KIT_DEBUG_DETAIL_GET_3RD_ARG(ARG1, ARG2, ARG3, ...) ARG3 230 #define NX_KIT_DEBUG_DETAIL_ASSERT1(CONDITION) \ 231 NX_KIT_DEBUG_DETAIL_ASSERT(CONDITION, "") 233 #define NX_KIT_DEBUG_DETAIL_ASSERT2(CONDITION, MESSAGE) \ 234 NX_KIT_DEBUG_DETAIL_ASSERT(CONDITION, MESSAGE) 236 #define NX_KIT_DEBUG_DETAIL_ASSERT(CONDITION, MESSAGE) do \ 240 nx::kit::debug::detail::assertionFailed( \ 241 NX_KIT_DEBUG_DETAIL_PRINT_FUNC, #CONDITION, (MESSAGE), __FILE__, __LINE__); \ 245 #define NX_KIT_DEBUG_DETAIL_CONCAT(X, Y) NX_KIT_DEBUG_DETAIL_CONCAT2(X, Y) 246 #define NX_KIT_DEBUG_DETAIL_CONCAT2(X, Y) X##Y 249 std::string toString(T value)
251 std::ostringstream outputString;
252 outputString << value;
253 return outputString.str();
256 NX_KIT_API std::string toString(std::string s);
257 NX_KIT_API std::string toString(
char c);
258 NX_KIT_API std::string toString(
const char* s);
259 NX_KIT_API std::string toString(
char* s);
260 NX_KIT_API std::string toString(
const void* ptr);
261 NX_KIT_API std::string toString(
bool b);
263 #if defined(QT_CORE_LIB) 265 static inline std::string toString(
const QByteArray& b)
267 return toString(b.toStdString());
270 static inline std::string toString(
const QString& s)
272 return toString(s.toUtf8().constData());
275 static inline std::string toString(
const QUrl& u)
277 return toString(u.toEncoded().toStdString());
280 #endif // defined(QT_CORE_LIB) 283 std::string toString(P* ptr)
285 return toString((
const void*) ptr);
290 typedef std::function<void(const char*)> PrintFunc;
292 #define NX_KIT_DEBUG_DETAIL_PRINT_FUNC [&](const char* message) { NX_PRINT << message; } 295 NX_KIT_API std::string printPrefix(
const char* file);
297 NX_KIT_API
void assertionFailed(
298 PrintFunc printFunc,
const char* conditionStr,
const std::string& message,
299 const char* file,
int line);
304 Timer(
bool enabled, PrintFunc printFunc,
const char* tag);
306 void mark(
const char* markStr);
317 Fps(PrintFunc printFunc,
const char* tag);
319 void mark(
const char* markStr =
nullptr);
326 NX_KIT_API
void printHexDump(
327 PrintFunc printFunc,
const char* caption,
const char* bytes,
int size);
335 #if defined(__linux__) 337 #define NX_KIT_DEBUG_DETAIL_THREAD_ID() \ 338 nx::kit::debug::format(", thread %llx", (long long) pthread_self()) 339 #elif defined(QT_CORE_LIB) 340 #include <QtCore/QThread> 341 #define NX_KIT_DEBUG_DETAIL_THREAD_ID() \ 342 nx::kit::debug::format(", thread %llx", (long long) QThread::currentThreadId()) 345 #define NX_KIT_DEBUG_DETAIL_THREAD_ID() ""
Definition: debug.cpp:367
Definition: debug.cpp:292