8#define TRAP() __debugbreak()
9#elif defined(__GNUC__) || defined(__clang__)
10#define TRAP() __builtin_trap()
12#error Unknown trap intrinsic for compiler.
14#define ASSERT_ALWAYS(x) \
22#define ASSERT(x) ASSERT_ALWAYS(x)
24#define ASSERT(x) (void)(x)
26#define INVALID_PATH ASSERT(!"Invalid Path!")
27#define NOT_IMPLEMENTED ASSERT(!"Not Implemented!")
28#define NO_OP ((void)0)
30#if defined(__GNUC__) || defined(__clang__)
31#define FORCE_INLINE [[gnu::always_inline]] inline
33#error "Not defined for your compiler"
42#define BITMASK_ENUM(Type) \
43 static_assert(std::is_enum_v<Type>, "BITMASK_ENUM can only be used on enum types"); \
45 struct sdIsBitmaskEnum<Type> : std::true_type {};
47template<BitmaskEnum T>
49 using U = std::underlying_type_t<T>;
52 FORCE_INLINE
constexpr operator bool() const noexcept {
return value != 0; }
53 FORCE_INLINE
constexpr operator T() const noexcept {
return static_cast<T
>(
value); }
55template<BitmaskEnum T>
57 using U = std::underlying_type_t<T>;
58 return {
static_cast<U
>(lhs) &
static_cast<U
>(rhs)};
61template<BitmaskEnum T>
63 using U = std::underlying_type_t<T>;
64 return {
static_cast<U
>(lhs) |
static_cast<U
>(rhs)};
67template<BitmaskEnum T>
69 using U = std::underlying_type_t<T>;
70 return {
static_cast<U
>(~static_cast<U>(rhs))};
73template<BitmaskEnum T>
75 using U = std::underlying_type_t<T>;
76 lhs =
static_cast<T
>(
static_cast<U
>(lhs) |
static_cast<U
>(rhs));
80template<BitmaskEnum T>
82 using U = std::underlying_type_t<T>;
83 lhs =
static_cast<T
>(
static_cast<U
>(lhs) &
static_cast<U
>(rhs));
93 using U = std::underlying_type_t<T>;
94 U numeric_value =
static_cast<U
>(wrapper.
value);
96 if (numeric_value == 0) {
100 static constexpr auto enumerators = std::define_static_array(std::meta::enumerators_of(^^T));
103 template for (
constexpr auto e : enumerators) {
104 constexpr U flag_val =
static_cast<U
>([:e:]);
105 if constexpr (flag_val != 0) {
106 if ((numeric_value & flag_val) == flag_val) {
110 os << std::meta::identifier_of(e);
120[[nodiscard]] FORCE_INLINE
constexpr std::string_view
enum_to_string(T value)
noexcept {
121 static constexpr auto enumerators = std::define_static_array(std::meta::enumerators_of(^^T));
123 template for (
constexpr auto e : enumerators) {
124 if (value == [:e:]) {
125 return std::meta::identifier_of(e);
139#if defined(__GNUC__) || defined(__clang__) || (defined(_MSC_VER) && (_MSC_VER >= 1926))
140#define SD_FILE __builtin_FILE()
141#define SD_LINE __builtin_LINE()
143#error "__buitin_FILE() not defined for your compiler"
153 unsigned line = __builtin_LINE()) {
FORCE_INLINE constexpr BitmaskResult< T > operator~(T rhs)
Definition base.hpp:68
FORCE_INLINE constexpr T & operator|=(T &lhs, T rhs)
Definition base.hpp:74
FORCE_INLINE constexpr BitmaskResult< T > operator&(T lhs, T rhs)
Definition base.hpp:56
FORCE_INLINE constexpr BitmaskResult< T > operator|(T lhs, T rhs)
Definition base.hpp:62
FORCE_INLINE constexpr std::string_view enum_to_string(T value) noexcept
Definition base.hpp:120
FORCE_INLINE constexpr T & operator&=(T &lhs, T rhs)
Definition base.hpp:81
Definition Application.hpp:22
U value
Definition base.hpp:50
std::underlying_type_t< T > U
Definition base.hpp:49
friend std::ostream & operator<<(std::ostream &os, BitmaskStreamer wrapper)
Definition base.hpp:92
T value
Definition base.hpp:90
unsigned line
Definition base.hpp:150
const char * file
Definition base.hpp:149
static consteval SourceLocation current(const char *file=__builtin_FILE(), unsigned line=__builtin_LINE())
Definition base.hpp:152