FuncDoodle
Loading...
Searching...
No Matches
MacroUtils.h
Go to the documentation of this file.
1
23
24#pragma once
25
26#include <algorithm>
27#include <filesystem>
28#include <print>
29#include <string>
30#include <vector>
31
32#include "UI/Gui.h"
33
39extern std::vector<std::string> s_Logs;
40
41#if __cplusplus >= 202002L && defined(__cpp_lib_format)
42#include <format>
47#define FUNC_FORMAT_AVAILABLE 1
48#else
53#define FUNC_FORMAT_AVAILABLE 0
54#endif
55
56#if __cplusplus < 202002L
57#error \
58 "std::format is not supported by your compiler configuration. Please consider using -std=c++20 or later."
59#else
60#define FUNC_FMT(...) std::format(__VA_ARGS__)
61#endif
62
71#ifdef DEBUG
72#define FUNC_AOV(x) \
73 do { \
74 if (!(x)) { \
75 std::println("ASSERTION FAILED(DEBUG) at line {} in file {}", \
76 __LINE__, __FILE__); \
77 } \
78 } while (0)
79#else
80#ifdef NDEBUG
81#define FUNC_AOV(x) \
82 do { \
83 if (!(x)) { \
84 std::println("VERIFICATION FAILED at line {} in file {}", \
85 __LINE__, __FILE__); \
86 } \
87 } while (0)
88#endif
89#endif
90
98#ifdef DEBUG
99#define FUNC_AOV_EX(x, str) \
100 do { \
101 if (!(x)) { \
102 std::println("VERIFICATION FAILED: "); \
103 FUNC_INF(str); \
104 } \
105 } while (0)
106#else
107#ifdef NDEBUG
108#define FUNC_AOV_EX(x, str) \
109 do { \
110 if (!(x)) { \
111 FUNC_FATAL("VERIFICATION FAILED, description:"); \
112 FUNC_INF(str); \
113 } \
114 } while (0)
115#endif
116#endif
117
124#ifdef DEBUG
125#define FUNC_DASS(x) \
126 do { \
127 if (!(x)) { \
128 std::println("STRIPPED ASSERTION FAILED at line {} in file {}", \
129 __LINE__, __FILE__); \
130 } \
131 } while (0)
132#else
133#define FUNC_DASS(x)
134#endif
135
140#define PUSH_LOG(prefix, ...) \
141 do { \
142 s_Logs.emplace_back(std::string(prefix) + FUNC_FMT(__VA_ARGS__)); \
143 } while (0)
144
149#ifdef DEBUG
150#define FUNC_DBG(...) \
151 do { \
152 std::println("\033[36m[Debug]: {}\033[0m", FUNC_FMT(__VA_ARGS__)); \
153 PUSH_LOG("[Debug]: ", __VA_ARGS__); \
154 } while (0)
155#else
156#define FUNC_DBG(...)
157#endif
158
163#define FUNC_INF(...) \
164 do { \
165 std::println("\033[34m[Info]: {}\033[0m", FUNC_FMT(__VA_ARGS__)); \
166 PUSH_LOG("[Info]: ", __VA_ARGS__); \
167 } while (0)
168
173#define FUNC_WARN(...) \
174 do { \
175 std::println("\033[33m[Warn]: {}\033[0m", FUNC_FMT(__VA_ARGS__)); \
176 PUSH_LOG("[Warn]: ", __VA_ARGS__); \
177 } while (0)
178
183#define FUNC_GRAY(...) \
184 do { \
185 std::println("\033[90m[Note]: {}\033[0m", FUNC_FMT(__VA_ARGS__)); \
186 PUSH_LOG("[Note]: ", __VA_ARGS__); \
187 } while (0)
188
193#define FUNC_ERR(...) \
194 do { \
195 std::println("\033[1;35m[Error]: {}\033[0m", FUNC_FMT(__VA_ARGS__)); \
196 PUSH_LOG("[Error]: ", __VA_ARGS__); \
197 } while (0)
198
203#define FUNC_FATAL(...) \
204 do { \
205 std::println("\033[1;31m[FATAL]: {}\033[0m", FUNC_FMT(__VA_ARGS__)); \
206 PUSH_LOG("[FATAL]: ", __VA_ARGS__); \
207 std::exit(-1); \
208 } while (0)
209
214inline ImGuiCol InvertedImCol(uint8_t r, uint8_t g, uint8_t b) {
215 return IM_COL32(255 - r, 255 - g, 255 - b, 255);
216}
217
218#ifdef _WIN32
219#ifndef WIN32_LEAN_AND_MEAN
220#define WIN32_LEAN_AND_MEAN
221#endif
222#include <shellapi.h>
223#include <windows.h>
224
225#undef LoadImage
226#undef PlaySound
227
228#define strncasecmp _strnicmp
229#define strcasecmp _stricmp
230#endif
231
236inline void OpenFileExplorer(const std::filesystem::path& path) {
237#if defined(_WIN32)
238 ShellExecuteA(
239 nullptr, "open", path.string().c_str(), nullptr, nullptr, SW_SHOW);
240#elif defined(__APPLE__)
241 std::system(("open " + path.string() + " &").c_str());
242#elif defined(__linux__)
243 std::system(("xdg-open " + path.string() + " &").c_str());
244#else
245 FUNC_ERR("Unsupported platform!");
246#endif
247}
ImGui/OpenGL/GLFW integration utilities and file dialog wrapper.
std::vector< std::string > s_Logs
Definition MacroUtils.cc:4
ImGuiCol InvertedImCol(uint8_t r, uint8_t g, uint8_t b)
Definition MacroUtils.h:214
#define FUNC_ERR(...)
A non-fatal, recoverable from error.
Definition MacroUtils.h:193
void OpenFileExplorer(const std::filesystem::path &path)
Definition MacroUtils.h:236