mixer/src/debug.h

86 lines
2.5 KiB
C++

#pragma once
#if defined (QT_DEBUG) || defined (DEBUG) || defined (_DEBUG)
#ifdef INIT_FILELOG
std::wstring_convert<std::codecvt_utf8<wchar_t>, wchar_t> converter;
FILE* fileLog;
errno_t lfResult;
bool writable = false;
void inline initializeFileLogging() {
lfResult = fopen_s(&fileLog, "log.txt", "w");
if (!lfResult) writable = true;
else writable = false;
}
#else
extern std::wstring_convert<std::codecvt_utf8_utf16<wchar_t>, wchar_t> converter;
extern errno_t lfResult;
extern FILE* fileLog;
extern bool writable;
extern bool initializeFileLogging();
#endif
#define initialize_file_log() initializeFileLogging()
template<size_t Y, typename T>
std::bitset<Y> varToBitset(T info) {
std::bitset<Y> content(info);
return content;
}
#ifndef _WIN32
#define log_debugcpp(str) do { \
std::cout << "[DEBUG]" << "(" << __FILE__ << ":" << __LINE__ << "): " << str << std::endl; \
} while (0)
#define log_wdebugcpp(str) do { \
std::wcout << "[DEBUG]" << "(" << __FILE__ << ":" << __LINE__ << "): " << str << std::endl; \
} while (0)
#else
#include <Windows.h>
#include <debugapi.h>
#define WIDE2(x) L##x
#define WIDE1(x) WIDE2(x)
#define WFILE WIDE1(__FILE__)
#define log_debugcpp(str) { \
OutputDebugStringA(std::string("[DEBUG] (" + std::string(__FILE__) + ":" + std::to_string(__LINE__) + "): " + std::string(str) + "\n").c_str()); \
} while (0)
#define log_wdebugcpp(str) do { \
OutputDebugStringW(std::wstring(L"[DEBUG] (" + std::wstring(WFILE) + L":" + std::to_wstring(__LINE__) + L"): " + std::wstring(str) +L"\n").c_str()); \
} while (0)
#endif
#define log_to_file_simple(fmt) log_to_file(fmt, "")
#define log_to_file(fmt, cnt...) do { \
if(writable) fprintf_s(fileLog, fmt, cnt); \
} while (0)
#define print_as_binary(len, type, info) varToBitset<len, type>(info)
#define close_file_log_buffer() do { \
fclose(fileLog); \
} while (0)
#else
#define log_debugcpp(str)
#define log_wdebugcpp(str)
#define print_as_binary(len, type, info)
#define log_to_file_simple(fmt)
#define log_to_file(fmt, cnt...)
#define initialize_file_log() false
#define close_file_log_buffer()
#endif
/* Here as a quick reference, in case smthn similar is needed again */
/* typedef void (EndpointWidget::*epwMuteFunc)(bool muted); */
/* Typedef void (EndpointWidget::*epwMainVolumeFunc)(float newValue); */
/* typedef void (EndpointWidget::*epwChannelVolumeFunc)(uint32_t channel, float newValue); */
/* typedef void (EndpointWidget::*epwToggleFrontFunc)(bool active); */