Blender V5.3
BLI_enum_flags.hh
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2025 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
5#pragma once
6
10
11#include <cstdint>
12
13namespace blender {
14
19template<typename T> struct BitwiseNotEnumValue {
21 operator uint64_t() const
22 {
23 return value;
24 }
25};
26
27} // namespace blender
28
29/* Use for enum classes that represent bit flags.
30 * Defines logical operators to combine and mask the flag values.
31 *
32 * Note that negation/inversion operator (~) flips all the bits, so the result can contain
33 * set bits that are not part of the enum values. However that is fine in typical
34 * inversion operator usage, which is often for masking out bits (`a & ~b`). */
35#define ENUM_OPERATORS(_enum_type) \
36 [[maybe_unused]] [[nodiscard]] inline constexpr _enum_type operator|(_enum_type a, \
37 _enum_type b) \
38 { \
39 return (_enum_type)(uint64_t(a) | uint64_t(b)); \
40 } \
41 [[maybe_unused]] [[nodiscard]] inline constexpr _enum_type operator&(_enum_type a, \
42 _enum_type b) \
43 { \
44 return (_enum_type)(uint64_t(a) & uint64_t(b)); \
45 } \
46 [[maybe_unused]] [[nodiscard]] inline constexpr _enum_type operator&( \
47 _enum_type a, ::blender::BitwiseNotEnumValue<_enum_type> b) \
48 { \
49 return (_enum_type)(uint64_t(a) & uint64_t(b.value)); \
50 } \
51 [[maybe_unused]] [[nodiscard]] inline constexpr ::blender::BitwiseNotEnumValue<_enum_type> \
52 operator~(_enum_type a) \
53 { \
54 ::blender::BitwiseNotEnumValue<_enum_type> result = {~uint64_t(a)}; \
55 return result; \
56 } \
57 [[maybe_unused]] inline _enum_type &operator|=(_enum_type &a, _enum_type b) \
58 { \
59 return a = (_enum_type)(uint64_t(a) | uint64_t(b)); \
60 } \
61 [[maybe_unused]] inline _enum_type &operator&=(_enum_type &a, _enum_type b) \
62 { \
63 return a = (_enum_type)(uint64_t(a) & uint64_t(b)); \
64 } \
65 [[maybe_unused]] inline _enum_type &operator&=(_enum_type &a, \
66 ::blender::BitwiseNotEnumValue<_enum_type> b) \
67 { \
68 return a = (_enum_type)(uint64_t(a) & uint64_t(b.value)); \
69 } \
70 [[maybe_unused]] inline _enum_type &operator^=(_enum_type &a, _enum_type b) \
71 { \
72 return a = (_enum_type)(uint64_t(a) ^ uint64_t(b)); \
73 } \
74 [[maybe_unused]] [[nodiscard]] inline constexpr bool flag_is_set(_enum_type flags, \
75 _enum_type flag_to_test) \
76 { \
77 return (uint64_t(flags) & uint64_t(flag_to_test)) != 0; \
78 }
BMesh Iterators.
unsigned __int64 uint64_t
Definition BKE_text.h:91