Enigma 3.2.2
A Simple, Reliable and Efficient Encryption Tool
Loading...
Searching...
No Matches
Macros.hpp
Go to the documentation of this file.
1#pragma once
2#ifndef ENIGMA_MACROS_H
3#define ENIGMA_MACROS_H
4
6#ifdef ENIGMA_DEBUG
7#define ENIGMA_ENABLE_ASSERTS true
8#endif
10
11
13#define NS_ENIGMA_BEGIN namespace Enigma {
14#define NS_ENIGMA_END }
16
17
19#define USING_NS_ENIGMA using namespace Enigma;
20#define enigma Enigma
22
23
25#define ENIGMA_BIND_FUN(fun) [this](auto&&...args) -> decltype(auto) { return this->fun(std::forward<decltype(args)>(args)...); }
26//
27
28
30#ifdef ENIGMA_ENABLE_ASSERTS
31#define ENIGMA_ASSERT(x, ...) \
32 if (!(x)) { \
33 ENIGMA_ERROR("Assertion Failed: {0}", __VA_ARGS__); \
34 ENIGMA_DEBUG_BREAK(); \
35 }
36#else
37#define ENIGMA_ASSERT(x, ...)
38#define ENIGMA_ASSERT(x, ...)
39#endif
40
41#define ENIGMA_ASSERT_OR_THROW(x, msg) \
42 if (!(x)) { \
43 throw std::runtime_error(msg); \
44 }
45
46#define ENIGMA_ASSERT_OR_RETURN(x, msg, ret) \
47 if (!(x)) { \
48 return ret; \
49 } \
50
51
52
54#define ENIGMA_SAFE_DELETE_PTR(ptr) \
55 if ((ptr)) { \
56 delete (ptr); \
57 (ptr) = nullptr; \
58 }
59
60#define ENIGMA_SAFE_DELETE_ARRAY_PTR(ptr) \
61 if ((ptr)) { \
62 delete[] (ptr); \
63 (ptr) = nullptr; \
64 }
65
66#define ENIGMA_SAFE_DELETE_LIST_PTR(list) \
67 if (((list)[0])) { \
68 for (auto& ptr: list) \
69 ENIGMA_SAFE_DELETE_PTR(ptr); \
70 } \
71
72
74#define BIT(x) (1 << x)
76
78#define ENIGMA_ARRAY_SIZE(arr) static_cast<::Enigma::std::size_t>(sizeof(arr) / sizeof((arr)[0]))
80
82#define ENIGMA_IS_BETWEEN(v, mi, ma) (v >= mi && v <= ma)
84
88#if defined(__GNUC__) || (defined(__MWERKS__) && (__MWERKS__ >= 0x3000)) || (defined(__ICC) && (__ICC >= 600)) || defined(__ghs__)
89#define ENIGMA_CURRENT_FUNCTION __PRETTY_FUNCTION__
90#elif defined(__DMC__) && (__DMC__ >= 0x810)
91#define ENIGMA_CURRENT_FUNCTION __PRETTY_FUNCTION__
92#elif defined(__FUNCSIG__)
93#define ENIGMA_CURRENT_FUNCTION __FUNCSIG__
94#elif (defined(__INTEL_COMPILER) && (__INTEL_COMPILER >= 600)) || (defined(__IBMCPP__) && (__IBMCPP__ >= 500))
95#define ENIGMA_CURRENT_FUNCTION __FUNCTION__
96#elif defined(__BORLANDC__) && (__BORLANDC__ >= 0x550)
97#define ENIGMA_CURRENT_FUNCTION __FUNC__
98#elif defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901)
99#define ENIGMA_CURRENT_FUNCTION __func__
100#elif defined(__cplusplus) && (__cplusplus >= 201103)
101#define ENIGMA_CURRENT_FUNCTION __func__
102#elif defined(_MSC_VER)
103#define ENIGMA_CURRENT_FUNCTION __FUNCTION__
104#else
105#define ENIGMA_CURRENT_FUNCTION "<unknown function>"
106#endif
108
109
111#define ENIGMA_NON_COPYABLE(Class) \
112 Class& operator=(const Class& obj) = delete; \
113 Class(const Class& obj) = delete;
114#define ENIGMA_NON_MOVEABLE(Class) \
115 Class& operator=(Class&& obj) = delete;
117
118
120#define ENIGMA_STATIC_CLASS(Class) \
121public: \
122 ENIGMA_NON_COPYABLE(Class) \
123 ENIGMA_NON_MOVEABLE(Class) \
124 Class() = delete; \
125 ~Class() = delete; \
126 \
127private:
129
130
132#define ENIGMA_BEGIN_TIMER(var) const auto var = std::chrono::steady_clock::now()
133#define ENIGMA_END_TIMER(var, type, unit) std::chrono::duration_cast<std::chrono::duration<type, unit>>(std::chrono::steady_clock::now() - var).count()
134// example: double ms = ENIGMA_END_TIMER(t1, double, std::milli);
136
137
139#if defined(ENIGMA_DEBUG)
140//#define ENIGMA_TRACE_CURRENT_FUNCTION() ENIGMA_TRACE(::Enigma::StringUtils::Cleanup(::Enigma::StringUtils::Cleanup(::Enigma::StringUtils::Cleanup(ENIGMA_CURRENT_FUNCTION, " __cdecl"), "struct"), "class"))
141#define ENIGMA_TRACE_CURRENT_FUNCTION() ENIGMA_TRACE(ENIGMA_CURRENT_FUNCTION)
142#else
143#define ENIGMA_TRACE_CURRENT_FUNCTION()
144#endif
146
148#define ENIGMA_ENUM_DECLARE_BEGIN_END(begin) \
149 __HALT__, \
150 BEGIN = begin, \
151 END = __HALT__ - 1
153
155#define ENIGMA_ENUM_CLASS_BITWISE_OPERATORS(_enum, _type) \
156 friend inline constexpr _enum operator~(const _enum i) noexcept { return static_cast<_enum>(~static_cast<const _type>(i)); } \
157 friend inline constexpr _enum operator|(const _enum a, const _enum b) noexcept { return static_cast<_enum>(static_cast<const _type>(a) | static_cast<const _type>(b)); } \
158 friend inline constexpr _enum operator&(const _enum a, const _enum b) noexcept { return static_cast<_enum>(static_cast<const _type>(a) & static_cast<const _type>(b)); } \
159 friend inline constexpr _enum operator^(const _enum a, const _enum b) noexcept { return static_cast<_enum>(static_cast<const _type>(a) ^ static_cast<const _type>(b)); } \
160 friend inline constexpr _enum& operator|=(_enum& a, const _enum b) noexcept { \
161 a = a | b; \
162 return a; \
163 } \
164 friend inline constexpr _enum& operator&=(_enum& a, const _enum b) noexcept { \
165 a = a & b; \
166 return a; \
167 } \
168 friend inline constexpr _enum& operator^=(_enum& a, const _enum b) noexcept { \
169 a = a ^ b; \
170 return a; \
171 }
172
173
175
176
177//static void TimedFunction(
178// const std::function<void()>& onStart,
179// const std::function<void()>& func,
180// const std::function<void(::Enigma::double)>& onFinish)
181//{
182// onStart();
183// ENIGMA_BEGIN_TIMER(t1);
184// func();
185// ::Enigma::double elapsed = ENIGMA_END_TIMER(t1, double, std::milli) / 1000.0;
186// onFinish(elapsed);
187//}
188
189
190#endif // !ENIGMA_MACROS_H