stdex
Additional custom or not Standard C++ covered algorithms
Loading...
Searching...
No Matches
debug.hpp
1/*
2 SPDX-License-Identifier: MIT
3 Copyright © 2023 Amebis
4*/
5
6#pragma once
7
8#include "compat.hpp"
9#include "string.hpp"
10#include <stdarg.h>
11#include <stdio.h>
12
13namespace stdex
14{
15 namespace diag {
17 inline void vprintf(_In_z_ _Printf_format_string_ const char* format, _In_ va_list arg)
18 {
19#if defined(NDEBUG)
20 UNREFERENCED_PARAMETER(format);
21 UNREFERENCED_PARAMETER(arg);
22#elif defined(_WIN32)
23 auto tmp = stdex::vsprintf(format, stdex::locale_default, arg);
24 OutputDebugStringA(tmp.c_str());
25#else
26 vfprintf(stdout, format, arg);
27#endif
28 }
29
30 inline void vprintf(_In_z_ _Printf_format_string_ const wchar_t* format, _In_ va_list arg)
31 {
32#if defined(NDEBUG)
33 UNREFERENCED_PARAMETER(format);
34 UNREFERENCED_PARAMETER(arg);
35#elif defined(_WIN32)
36 auto tmp = stdex::vsprintf(format, stdex::locale_default, arg);
37 OutputDebugStringW(tmp.c_str());
38#else
39 vfwprintf(stdout, format, arg);
40#endif
41 }
43
53 template <class T>
54 inline void printf(_In_z_ _Printf_format_string_ const T* format, ...)
55 {
56#if defined(NDEBUG)
57 UNREFERENCED_PARAMETER(format);
58#else
59 va_list arg;
60 va_start(arg, format);
61 vprintf(format, arg);
62 va_end(arg);
63#endif
64 }
65 }
66
67 namespace err {
69 inline void vprintf(_In_z_ _Printf_format_string_ const char* format, _In_ va_list arg)
70 {
71#if defined(NDEBUG)
72 UNREFERENCED_PARAMETER(format);
73 UNREFERENCED_PARAMETER(arg);
74#elif defined(_WIN32)
75 auto tmp = stdex::vsprintf(format, stdex::locale_default, arg);
76 OutputDebugStringA(tmp.c_str());
77#else
78 vfprintf(stderr, format, arg);
79#endif
80 }
81
82 inline void vprintf(_In_z_ _Printf_format_string_ const wchar_t* format, _In_ va_list arg)
83 {
84#if defined(NDEBUG)
85 UNREFERENCED_PARAMETER(format);
86 UNREFERENCED_PARAMETER(arg);
87#elif defined(_WIN32)
88 auto tmp = stdex::vsprintf(format, stdex::locale_default, arg);
89 OutputDebugStringW(tmp.c_str());
90#else
91 vfwprintf(stderr, format, arg);
92#endif
93 }
95
105 template <class T>
106 inline void printf(_In_z_ _Printf_format_string_ const T* format, ...)
107 {
108#if defined(NDEBUG)
109 UNREFERENCED_PARAMETER(format);
110#else
111 va_list arg;
112 va_start(arg, format);
113 vprintf(format, arg);
114 va_end(arg);
115#endif
116 }
117 }
118}