20 #if !defined(NX_KIT_API) 34 NX_KIT_API std::string srcFileRelativePath(
const std::string& file);
39 NX_KIT_API std::string srcFileBaseNameWithoutExt(
const std::string& file);
45 #if defined(NX_PRINT_TO_QDEBUG) 46 #define NX_DEBUG_STREAM qDebug().nospace().noquote() 47 #define NX_DEBUG_ENDL "" 48 static inline QDebug operator<<(QDebug d,
const std::string& s)
50 return d << QString::fromStdString(s);
54 #if !defined(NX_DEBUG_INI) 56 #define NX_DEBUG_INI ini(). 59 #if !defined(NX_DEBUG_ENABLE_OUTPUT) 61 #define NX_DEBUG_ENABLE_OUTPUT NX_DEBUG_INI enableOutput 64 #if !defined(NX_PRINT_PREFIX) 66 #define NX_PRINT_PREFIX ::nx::kit::debug::detail::printPrefix(__FILE__) 69 #if !defined(NX_DEBUG_STREAM) 71 #define NX_DEBUG_STREAM *::nx::kit::debug::stream() 74 #if !defined(NX_DEBUG_ENDL) 76 #define NX_DEBUG_ENDL "\n" 83 NX_KIT_API std::ostream*& stream();
85 #if !defined(NX_PRINT) 91 nx::kit::debug::detail::Print(&(NX_DEBUG_STREAM), NX_DEBUG_ENDL) << NX_PRINT_PREFIX 99 int NX_KIT_DEBUG_DETAIL_CONCAT(nxOutput_, __line__) = 0; \ 100 NX_KIT_DEBUG_DETAIL_CONCAT(nxOutput_, __line__) != 1 && (NX_DEBUG_ENABLE_OUTPUT); \ 101 ++NX_KIT_DEBUG_DETAIL_CONCAT(nxOutput_, __line__) \ 122 #define NX_KIT_ASSERT( ...) \ 123 NX_KIT_DEBUG_DETAIL_MSVC_EXPAND(NX_KIT_DEBUG_DETAIL_GET_3RD_ARG( \ 124 __VA_ARGS__, NX_KIT_DEBUG_DETAIL_ASSERT2, NX_KIT_DEBUG_DETAIL_ASSERT1, \ 125 args_required)(__VA_ARGS__)) 131 NX_KIT_API
void intentionallyCrash(
const char* message);
140 NX_PRINT << "####### LL line " + ::nx::kit::utils::toString(__LINE__) \ 141 + NX_KIT_DEBUG_DETAIL_THREAD_ID \ 142 + ", " + ::nx::kit::debug::srcFileRelativePath(__FILE__) \ 148 #define NX_PRINT_VALUE(VALUE) \ 149 NX_PRINT << "####### " #VALUE ": " + ::nx::kit::utils::toString(VALUE) 154 #define NX_PRINT_HEX_DUMP(CAPTION, BYTES, SIZE) \ 155 ::nx::kit::debug::detail::printHexDump( \ 156 NX_KIT_DEBUG_DETAIL_PRINT_FUNC, (CAPTION), (const char*) (BYTES), (int) (SIZE)) 161 NX_KIT_API std::string hexDumpLine(
const char* bytes,
int size,
int bytesPerLine = 0);
163 #if !defined(NX_DEBUG_SAVE_DIR) 165 #define NX_DEBUG_SAVE_DIR ::nx::kit::IniConfig::iniFilesDir() 173 #define NX_SAVE_STR(FILENAME, STR) \ 174 ::nx::kit::debug::detail::saveStr( \ 175 NX_KIT_DEBUG_DETAIL_PRINT_FUNC, (NX_DEBUG_SAVE_DIR), (FILENAME), #STR, (STR)) 180 #define NX_SAVE_BIN(FILENAME, BYTES, SIZE) \ 181 ::nx::kit::debug::detail::saveBin( \ 182 NX_KIT_DEBUG_DETAIL_PRINT_FUNC, (NX_DEBUG_SAVE_DIR), (FILENAME), (BYTES), (SIZE)) 187 #if !defined(NX_DEBUG_ENABLE_TIME) 189 #define NX_DEBUG_ENABLE_TIME NX_DEBUG_INI enableTime 195 #define NX_TIME_BEGIN(TAG) \ 196 ::nx::kit::debug::detail::Timer nxTimer_##TAG( \ 197 (NX_DEBUG_ENABLE_TIME), NX_KIT_DEBUG_DETAIL_PRINT_FUNC, #TAG) 203 #define NX_TIME_MARK(TAG, MARK) do \ 205 if (NX_DEBUG_ENABLE_TIME) \ 206 nxTimer_##TAG.mark((MARK)); \ 212 #define NX_TIME_END(TAG) do \ 214 if (NX_DEBUG_ENABLE_TIME) \ 215 nxTimer_##TAG.finish(); \ 221 #if !defined(NX_DEBUG_ENABLE_FPS) 223 #define NX_DEBUG_ENABLE_FPS NX_DEBUG_INI enableFps 230 #define NX_FPS(TAG, ...) do \ 232 if (NX_KIT_DEBUG_DETAIL_CONCAT(NX_DEBUG_ENABLE_FPS, TAG)) \ 234 static ::nx::kit::debug::detail::Fps fps( \ 235 NX_KIT_DEBUG_DETAIL_PRINT_FUNC, #TAG); \ 236 fps.mark(__VA_ARGS__); \ 246 class Print:
public std::ostringstream
249 Print(std::ostream* outputStream,
const char*
const newline):
250 m_outputStream(outputStream), m_newline(newline)
256 (*this) << m_newline;
257 *m_outputStream << (*this).str();
261 std::ostream* m_outputStream;
262 const char*
const m_newline;
265 typedef std::function<void(const char*)> PrintFunc;
267 #define NX_KIT_DEBUG_DETAIL_PRINT_FUNC ([&](const char* message) { NX_PRINT << message; }) 273 #define NX_KIT_DEBUG_DETAIL_MSVC_EXPAND(ARG) ARG 276 #define NX_KIT_DEBUG_DETAIL_GET_3RD_ARG(ARG1, ARG2, ARG3, ...) ARG3 278 #define NX_KIT_DEBUG_DETAIL_ASSERT1(CONDITION) \ 279 ::nx::kit::debug::detail::doAssert( \ 280 !!(CONDITION), NX_KIT_DEBUG_DETAIL_PRINT_FUNC, #CONDITION, "", __FILE__, __LINE__) 282 #define NX_KIT_DEBUG_DETAIL_ASSERT2(CONDITION, MESSAGE) \ 283 ::nx::kit::debug::detail::doAssert( \ 284 !!(CONDITION), NX_KIT_DEBUG_DETAIL_PRINT_FUNC, #CONDITION, MESSAGE, __FILE__, __LINE__) 286 NX_KIT_API
void assertionFailed(
287 PrintFunc printFunc,
const char* conditionStr,
const std::string& message,
288 const char* file,
int line);
290 inline bool doAssert(
291 bool condition, PrintFunc printFunc,
const char* conditionStr,
const std::string& message,
292 const char* file,
int line)
295 assertionFailed(printFunc, conditionStr, message, file, line);
299 #define NX_KIT_DEBUG_DETAIL_CONCAT(X, Y) NX_KIT_DEBUG_DETAIL_CONCAT2(X, Y) 300 #define NX_KIT_DEBUG_DETAIL_CONCAT2(X, Y) X##Y 303 NX_KIT_API std::string printPrefix(
const char* file);
308 Timer(
bool enabled, PrintFunc printFunc,
const char* tag);
310 void mark(
const char* markStr);
321 Fps(PrintFunc printFunc,
const char* tag);
323 void mark(
const char* markStr =
nullptr);
330 NX_KIT_API
void printHexDump(
331 PrintFunc printFunc,
const char* caption,
const char* bytes,
int size);
333 NX_KIT_API
void saveStr(
335 const char* originDir,
336 const char* filename,
337 const char* strCaption,
338 const std::string& str);
340 NX_KIT_API
void saveBin(
342 const char* originDir,
343 const char* filename,
354 #if defined(__linux__) 355 #if defined(__has_include) //< This C++17 feature was available in GCC/Clang long before. 356 #if __has_include(<pthread.h>) 358 #define NX_KIT_DEBUG_DETAIL_THREAD_ID \ 359 ::nx::kit::utils::format(", thread %llx", (long long) pthread_self()) 362 #elif defined(QT_CORE_LIB) 363 #include <QtCore/QThread> 364 #define NX_KIT_DEBUG_DETAIL_THREAD_ID \ 365 ::nx::kit::utils::format(", thread %llx", (long long) QThread::currentThreadId()) 367 #if !defined(NX_KIT_DEBUG_DETAIL_THREAD_ID) 369 #define NX_KIT_DEBUG_DETAIL_THREAD_ID ""
Definition: debug.cpp:309
Definition: debug.cpp:234
Definition: apple_utils.h:6