FuncDoodle
Loading...
Searching...
No Matches
FuncPCH.h
Go to the documentation of this file.
1
22
23#pragma once
24
25#include <algorithm>
26#include <filesystem>
27#include <print>
28#include <string>
29#include <vector>
30
36extern std::vector<std::string> s_Logs;
37
38#if __cplusplus >= 202002L && defined(__cpp_lib_format)
39#include <format>
44#define FUNC_FORMAT_AVAILABLE 1
45#else
50#define FUNC_FORMAT_AVAILABLE 0
51#endif
52
53#if __cplusplus < 202002L
54#error \
55 "std::format is not supported by your compiler configuration. Please consider using -std=c++20 or later."
56#else
57#define FUNC_FMT(...) std::format(__VA_ARGS__)
58#endif
59
68#ifdef DEBUG
69#define FUNC_AOV(x) \
70 do { \
71 if (!(x)) { \
72 std::println("ASSERTION FAILED(DEBUG) at line {} in file {}", \
73 __LINE__, __FILE__); \
74 } \
75 } while (0)
76#else
77#ifdef NDEBUG
78#define FUNC_AOV(x) \
79 do { \
80 if (!(x)) { \
81 std::println("VERIFICATION FAILED at line {} in file {}", \
82 __LINE__, __FILE__); \
83 } \
84 } while (0)
85#endif
86#endif
87
95#ifdef DEBUG
96#define FUNC_AOV_EX(x, str) \
97 do { \
98 if (!(x)) { \
99 std::println("VERIFICATION FAILED: "); \
100 FUNC_INF(str); \
101 } \
102 } while (0)
103#else
104#ifdef NDEBUG
105#define FUNC_AOV_EX(x, str) \
106 do { \
107 if (!(x)) { \
108 FUNC_FATAL("VERIFICATION FAILED, description:"); \
109 FUNC_INF(str); \
110 } \
111 } while (0)
112#endif
113#endif
114
121#ifdef DEBUG
122#define FUNC_DASS(x) \
123 do { \
124 if (!(x)) { \
125 std::println("STRIPPED ASSERTION FAILED at line {} in file {}", \
126 __LINE__, __FILE__); \
127 } \
128 } while (0)
129#else
130#define FUNC_DASS(x)
131#endif
132
137#define PUSH_LOG(prefix, ...) \
138 do { \
139 s_Logs.emplace_back(std::string(prefix) + FUNC_FMT(__VA_ARGS__)); \
140 } while (0)
141
146#ifdef DEBUG
147#define FUNC_DBG(...) \
148 do { \
149 std::println("\033[36m[Debug]: {}\033[0m", FUNC_FMT(__VA_ARGS__)); \
150 PUSH_LOG("[Debug]: ", __VA_ARGS__); \
151 } while (0)
152#else
153#define FUNC_DBG(...)
154#endif
155
160#define FUNC_INF(...) \
161 do { \
162 std::println("\033[34m[Info]: {}\033[0m", FUNC_FMT(__VA_ARGS__)); \
163 PUSH_LOG("[Info]: ", __VA_ARGS__); \
164 } while (0)
165
170#define FUNC_WARN(...) \
171 do { \
172 std::println("\033[33m[Warn]: {}\033[0m", FUNC_FMT(__VA_ARGS__)); \
173 PUSH_LOG("[Warn]: ", __VA_ARGS__); \
174 } while (0)
175
180#define FUNC_GRAY(...) \
181 do { \
182 std::println("\033[90m[Note]: {}\033[0m", FUNC_FMT(__VA_ARGS__)); \
183 PUSH_LOG("[Note]: ", __VA_ARGS__); \
184 } while (0)
185
190#define FUNC_ERR(...) \
191 do { \
192 std::println("\033[1;35m[Error]: {}\033[0m", FUNC_FMT(__VA_ARGS__)); \
193 PUSH_LOG("[Error]: ", __VA_ARGS__); \
194 } while (0)
195
200#define FUNC_FATAL(...) \
201 do { \
202 std::println("\033[1;31m[FATAL]: {}\033[0m", FUNC_FMT(__VA_ARGS__)); \
203 PUSH_LOG("[FATAL]: ", __VA_ARGS__); \
204 std::exit(-1); \
205 } while (0)
206
207#ifdef _WIN32
208#ifndef WIN32_LEAN_AND_MEAN
209#define WIN32_LEAN_AND_MEAN
210#endif
211#include <shellapi.h>
212#include <shlwapi.h>
213#include <windows.h>
214#define strcasestr StrStrIA
215
216#undef LoadImage
217#undef PlaySound
218
219#define strncasecmp _strnicmp
220#define strcasecmp _stricmp
221#endif
222
227inline void OpenFileExplorer(const std::filesystem::path& path) {
228#if defined(_WIN32)
229 ShellExecuteA(
230 nullptr, "open", path.string().c_str(), nullptr, nullptr, SW_SHOW);
231#elif defined(__APPLE__)
232 std::system(("open " + path.string() + " &").c_str());
233#elif defined(__linux__)
234 std::system(("xdg-open " + path.string() + " &").c_str());
235#else
236 FUNC_ERR("Unsupported platform!");
237#endif
238}
#define FUNC_ERR(...)
A non-fatal, recoverable from error.
Definition FuncPCH.h:190
std::vector< std::string > s_Logs
Definition MacroUtils.cc:4
void OpenFileExplorer(const std::filesystem::path &path)
Definition FuncPCH.h:227