SourcePP
Several modern C++20 libraries for sanely parsing Valve's formats.
Loading...
Searching...
No Matches
Macros.h
Go to the documentation of this file.
1#pragma once
2
3#include <type_traits>
4
6#define SOURCEPP_CONCAT_DETAIL(a, b) a##b
7#define SOURCEPP_CONCAT(a, b) SOURCEPP_CONCAT_DETAIL(a, b)
8
10#define SOURCEPP_DEFAULT_COPY(Clazz) \
11 Clazz(const Clazz&) = default; \
12 Clazz& operator=(const Clazz&) = default
13
15#define SOURCEPP_DEFAULT_MOVE(Clazz) \
16 Clazz(Clazz&&) noexcept = default; \
17 Clazz& operator=(Clazz&&) noexcept = default
18
19// Defaults copy and move constructors
20#define SOURCEPP_DEFAULT_COPY_OR_MOVE(Clazz) \
21 SOURCEPP_DEFAULT_COPY(Clazz); \
22 SOURCEPP_DEFAULT_MOVE(Clazz)
23
25#define SOURCEPP_NO_COPY(Clazz) \
26 Clazz(const Clazz&) = delete; \
27 Clazz& operator=(const Clazz&) = delete
28
30#define SOURCEPP_NO_MOVE(Clazz) \
31 Clazz(Clazz&&) noexcept = delete; \
32 Clazz& operator=(Clazz&&) noexcept = delete
33
34// Deletes copy and move constructors
35#define SOURCEPP_NO_COPY_OR_MOVE(Clazz) \
36 SOURCEPP_NO_COPY(Clazz); \
37 SOURCEPP_NO_MOVE(Clazz)
38
40#ifdef DEBUG
41 #if defined(_MSC_VER)
42 #define SOURCEPP_DEBUG_BREAK __debugbreak()
43 #elif defined(__linux__)
44 #include <csignal>
45 #define SOURCEPP_DEBUG_BREAK std::raise(SIGINT)
46 #endif
47#endif
48#ifndef SOURCEPP_DEBUG_BREAK
49 #define SOURCEPP_DEBUG_BREAK
50#endif
51
53#define SOURCEPP_DEBUG_ASSERT(cond) do { if (!(cond)) { SOURCEPP_DEBUG_BREAK; } } while (false)
54
56#define SOURCEPP_UNIQUE_NAME(base) SOURCEPP_CONCAT(base, __LINE__)
57
59#define SOURCEPP_BITFLAGS_ENUM(Enum) \
60 template<typename T> \
61 requires std::is_same_v<T, Enum> || std::is_integral_v<T> \
62 inline constexpr Enum operator|(Enum lhs, T rhs) { \
63 return static_cast<Enum>( \
64 static_cast<std::underlying_type_t<Enum>>(lhs) | \
65 static_cast<std::underlying_type_t<Enum>>(rhs)); \
66 } \
67 template<typename T> \
68 requires std::is_same_v<T, Enum> || std::is_integral_v<T> \
69 inline constexpr Enum operator&(Enum lhs, T rhs) { \
70 return static_cast<Enum>( \
71 static_cast<std::underlying_type_t<Enum>>(lhs) & \
72 static_cast<std::underlying_type_t<Enum>>(rhs)); \
73 } \
74 template<typename T> \
75 requires std::is_same_v<T, Enum> || std::is_integral_v<T> \
76 inline constexpr Enum operator^(Enum lhs, T rhs) { \
77 return static_cast<Enum>( \
78 static_cast<std::underlying_type_t<Enum>>(lhs) ^ \
79 static_cast<std::underlying_type_t<Enum>>(rhs)); \
80 } \
81 inline constexpr Enum operator~(Enum e) { \
82 return static_cast<Enum>( \
83 ~static_cast<std::underlying_type_t<Enum>>(e)); \
84 } \
85 template<typename T> \
86 requires std::is_same_v<T, Enum> || std::is_integral_v<T> \
87 inline constexpr Enum& operator|=(Enum& lhs, T rhs) { \
88 return lhs = static_cast<Enum>( \
89 static_cast<std::underlying_type_t<Enum>>(lhs) | \
90 static_cast<std::underlying_type_t<Enum>>(rhs)); \
91 } \
92 template<typename T> \
93 requires std::is_same_v<T, Enum> || std::is_integral_v<T> \
94 inline constexpr Enum& operator&=(Enum& lhs, T rhs) { \
95 return lhs = static_cast<Enum>( \
96 static_cast<std::underlying_type_t<Enum>>(lhs) & \
97 static_cast<std::underlying_type_t<Enum>>(rhs)); \
98 } \
99 template<typename T> \
100 requires std::is_same_v<T, Enum> || std::is_integral_v<T> \
101 inline constexpr Enum& operator^=(Enum& lhs, T rhs) { \
102 return lhs = static_cast<Enum>( \
103 static_cast<std::underlying_type_t<Enum>>(lhs) ^ \
104 static_cast<std::underlying_type_t<Enum>>(rhs)); \
105 }