5
5
#include < netaddress.h>
6
6
7
7
#include < string>
8
+ #include < type_traits>
8
9
#include < vector>
9
10
10
11
#ifndef BITCOIN_NET_PERMISSIONS_H
@@ -14,7 +15,7 @@ struct bilingual_str;
14
15
15
16
extern const std::vector<std::string> NET_PERMISSIONS_DOC;
16
17
17
- enum NetPermissionFlags {
18
+ enum class NetPermissionFlags : uint32_t {
18
19
PF_NONE = 0 ,
19
20
// Can query bloomfilter even if -peerbloomfilters is false
20
21
PF_BLOOMFILTER = (1U << 1 ),
@@ -37,6 +38,11 @@ enum NetPermissionFlags {
37
38
PF_ISIMPLICIT = (1U << 31 ),
38
39
PF_ALL = PF_BLOOMFILTER | PF_FORCERELAY | PF_RELAY | PF_NOBAN | PF_MEMPOOL | PF_DOWNLOAD | PF_ADDR,
39
40
};
41
+ static inline constexpr NetPermissionFlags operator |(NetPermissionFlags a, NetPermissionFlags b)
42
+ {
43
+ using t = typename std::underlying_type<NetPermissionFlags>::type;
44
+ return static_cast <NetPermissionFlags>(static_cast <t>(a) | static_cast <t>(b));
45
+ }
40
46
41
47
class NetPermissions
42
48
{
@@ -45,11 +51,12 @@ class NetPermissions
45
51
static std::vector<std::string> ToStrings (NetPermissionFlags flags);
46
52
static inline bool HasFlag (NetPermissionFlags flags, NetPermissionFlags f)
47
53
{
48
- return (flags & f) == f;
54
+ using t = typename std::underlying_type<NetPermissionFlags>::type;
55
+ return (static_cast <t>(flags) & static_cast <t>(f)) == static_cast <t>(f);
49
56
}
50
57
static inline void AddFlag (NetPermissionFlags& flags, NetPermissionFlags f)
51
58
{
52
- flags = static_cast <NetPermissionFlags>( flags | f) ;
59
+ flags = flags | f;
53
60
}
54
61
// ! ClearFlag is only called with `f` == NetPermissionFlags::PF_ISIMPLICIT.
55
62
// ! If that should change in the future, be aware that ClearFlag should not
@@ -59,7 +66,8 @@ class NetPermissions
59
66
static inline void ClearFlag (NetPermissionFlags& flags, NetPermissionFlags f)
60
67
{
61
68
assert (f == NetPermissionFlags::PF_ISIMPLICIT);
62
- flags = static_cast <NetPermissionFlags>(flags & ~f);
69
+ using t = typename std::underlying_type<NetPermissionFlags>::type;
70
+ flags = static_cast <NetPermissionFlags>(static_cast <t>(flags) & ~static_cast <t>(f));
63
71
}
64
72
};
65
73
0 commit comments