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
#ifdef DEBUG
11
#if defined(_MSC_VER)
12
#define SOURCEPP_DEBUG_BREAK __debugbreak()
13
#elif defined(__linux__)
14
#include <csignal>
15
#define SOURCEPP_DEBUG_BREAK std::raise(SIGINT)
16
#endif
17
#endif
18
#ifndef SOURCEPP_DEBUG_BREAK
19
#define SOURCEPP_DEBUG_BREAK
20
#endif
21
23
#define SOURCEPP_DEBUG_ASSERT(cond) do { if (!(cond)) { SOURCEPP_DEBUG_BREAK; } } while (false)
24
26
#define SOURCEPP_UNIQUE_NAME(base) SOURCEPP_CONCAT(base, __LINE__)
27
29
#define SOURCEPP_BITFLAGS_ENUM(Enum) \
30
template<typename T> \
31
requires std::is_same_v<T, Enum> || std::is_integral_v<T> \
32
inline constexpr Enum operator|(Enum lhs, T rhs) { \
33
return static_cast<Enum>( \
34
static_cast<std::underlying_type_t<Enum>>(lhs) | \
35
static_cast<std::underlying_type_t<Enum>>(rhs)); \
36
} \
37
template<typename T> \
38
requires std::is_same_v<T, Enum> || std::is_integral_v<T> \
39
inline constexpr Enum operator&(Enum lhs, T rhs) { \
40
return static_cast<Enum>( \
41
static_cast<std::underlying_type_t<Enum>>(lhs) & \
42
static_cast<std::underlying_type_t<Enum>>(rhs)); \
43
} \
44
template<typename T> \
45
requires std::is_same_v<T, Enum> || std::is_integral_v<T> \
46
inline constexpr Enum operator^(Enum lhs, T rhs) { \
47
return static_cast<Enum>( \
48
static_cast<std::underlying_type_t<Enum>>(lhs) ^ \
49
static_cast<std::underlying_type_t<Enum>>(rhs)); \
50
} \
51
inline constexpr Enum operator~(Enum e) { \
52
return static_cast<Enum>( \
53
~static_cast<std::underlying_type_t<Enum>>(e)); \
54
} \
55
template<typename T> \
56
requires std::is_same_v<T, Enum> || std::is_integral_v<T> \
57
inline constexpr Enum& operator|=(Enum& lhs, T rhs) { \
58
return lhs = static_cast<Enum>( \
59
static_cast<std::underlying_type_t<Enum>>(lhs) | \
60
static_cast<std::underlying_type_t<Enum>>(rhs)); \
61
} \
62
template<typename T> \
63
requires std::is_same_v<T, Enum> || std::is_integral_v<T> \
64
inline constexpr Enum& operator&=(Enum& lhs, T rhs) { \
65
return lhs = static_cast<Enum>( \
66
static_cast<std::underlying_type_t<Enum>>(lhs) & \
67
static_cast<std::underlying_type_t<Enum>>(rhs)); \
68
} \
69
template<typename T> \
70
requires std::is_same_v<T, Enum> || std::is_integral_v<T> \
71
inline constexpr Enum& operator^=(Enum& lhs, T rhs) { \
72
return lhs = static_cast<Enum>( \
73
static_cast<std::underlying_type_t<Enum>>(lhs) ^ \
74
static_cast<std::underlying_type_t<Enum>>(rhs)); \
75
}
include
sourcepp
Macros.h
Generated on
for SourcePP by
1.16.1