yaze 0.2.2
Link to the Past ROM Editor
 
Loading...
Searching...
No Matches
macro.h
Go to the documentation of this file.
1#ifndef YAZE_UTIL_MACRO_H
2#define YAZE_UTIL_MACRO_H
3
4#define TAB_ITEM(w) if (ImGui::BeginTabItem(w)) {
5#define END_TAB_ITEM() \
6 ImGui::EndTabItem(); \
7 }
8
9#define BEGIN_TABLE(l, n, f) if (ImGui::BeginTable(l, n, f, ImVec2(0, 0))) {
10#define SETUP_COLUMN(l) ImGui::TableSetupColumn(l);
11
12#define TABLE_HEADERS() \
13 ImGui::TableHeadersRow(); \
14 ImGui::TableNextRow();
15
16#define NEXT_COLUMN() ImGui::TableNextColumn();
17
18#define END_TABLE() \
19 ImGui::EndTable(); \
20 }
21
22#define HOVER_HINT(string) \
23 if (ImGui::IsItemHovered()) ImGui::SetTooltip(string);
24
25#define PRINT_IF_ERROR(expression) \
26 { \
27 auto error = expression; \
28 if (!error.ok()) { \
29 std::cout << error.ToString() << std::endl; \
30 } \
31 }
32
33#define EXIT_IF_ERROR(expression) \
34 { \
35 auto error = expression; \
36 if (!error.ok()) { \
37 std::cout << error.ToString() << std::endl; \
38 return EXIT_FAILURE; \
39 } \
40 }
41
42#define RETURN_VOID_IF_ERROR(expression) \
43 { \
44 auto error = expression; \
45 if (!error.ok()) { \
46 std::cout << error.ToString() << std::endl; \
47 return; \
48 } \
49 }
50
51#define RETURN_IF_ERROR(expression) \
52 { \
53 auto error = expression; \
54 if (!error.ok()) { \
55 return error; \
56 } \
57 }
58
59#define ASSIGN_OR_RETURN(type_variable_name, expression) \
60 ASSIGN_OR_RETURN_IMPL(APPEND_NUMBER(error_or_value, __LINE__), \
61 type_variable_name, expression)
62
63#define ASSIGN_OR_RETURN_IMPL(error_or_value, type_variable_name, expression) \
64 auto error_or_value = expression; \
65 if (!error_or_value.ok()) { \
66 return error_or_value.status(); \
67 } \
68 type_variable_name = std::move(*error_or_value);
69
70#define ASSIGN_OR_LOG_ERROR(type_variable_name, expression) \
71 ASSIGN_OR_LOG_ERROR_IMPL(APPEND_NUMBER(error_or_value, __LINE__), \
72 type_variable_name, expression)
73
74#define ASSIGN_OR_LOG_ERROR_IMPL(error_or_value, type_variable_name, \
75 expression) \
76 auto error_or_value = expression; \
77 if (!error_or_value.ok()) { \
78 std::cout << error_or_value.status().ToString() << std::endl; \
79 } \
80 type_variable_name = std::move(*error_or_value);
81
82#define APPEND_NUMBER(expression, number) \
83 APPEND_NUMBER_INNER(expression, number)
84
85#define APPEND_NUMBER_INNER(expression, number) expression##number
86
87#define TEXT_WITH_SEPARATOR(text) \
88 ImGui::Text(text); \
89 ImGui::Separator();
90
91#define TABLE_BORDERS_RESIZABLE \
92 ImGuiTableFlags_Borders | ImGuiTableFlags_Resizable
93
94#define CLEAR_AND_RETURN_STATUS(status) \
95 if (!status.ok()) { \
96 auto temp = status; \
97 status = absl::OkStatus(); \
98 return temp; \
99 }
100
101#define RETURN_IF_EXCEPTION(expression) \
102 try { \
103 expression; \
104 } catch (const std::exception &e) { \
105 std::cerr << e.what() << std::endl; \
106 return EXIT_FAILURE; \
107 }
108
109#define SDL_RETURN_IF_ERROR() \
110 if (SDL_GetError() != nullptr) { \
111 return absl::InternalError(SDL_GetError()); \
112 }
113
114#endif // YAZE_UTIL_MACRO_H