Bitcoin Core
31.1.0
P2P Digital Currency
Toggle main menu visibility
Loading...
Searching...
No Matches
src
script
verify_flags.h
Go to the documentation of this file.
1
// Copyright (c) 2009-2010 Satoshi Nakamoto
2
// Copyright (c) 2009-present The Bitcoin Core developers
3
// Distributed under the MIT software license, see the accompanying
4
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
5
6
#ifndef BITCOIN_SCRIPT_VERIFY_FLAGS_H
7
#define BITCOIN_SCRIPT_VERIFY_FLAGS_H
8
9
#include <compare>
10
#include <cstdint>
11
12
enum class
script_verify_flag_name
: uint8_t;
13
14
class
script_verify_flags
15
{
16
public
:
17
using
value_type
= uint64_t;
18
19
consteval
script_verify_flags
() =
default
;
20
21
// also allow construction with hard-coded 0 (but not other integers)
22
consteval
explicit
(
false
)
script_verify_flags
(
value_type
f) :
m_value
{f} {
if
(f != 0)
throw
0; }
23
24
// implicit construction from a hard-coded SCRIPT_VERIFY_* constant is also okay
25
constexpr
explicit
(
false
)
script_verify_flags
(
script_verify_flag_name
f) :
m_value
{
value_type
{1} <<
static_cast<
uint8_t
>
(f)} { }
26
27
// rule of 5
28
constexpr
script_verify_flags
(
const
script_verify_flags
&) =
default
;
29
constexpr
script_verify_flags
(
script_verify_flags
&&) =
default
;
30
constexpr
script_verify_flags
&
operator=
(
const
script_verify_flags
&) =
default
;
31
constexpr
script_verify_flags
&
operator=
(
script_verify_flags
&&) =
default
;
32
constexpr
~script_verify_flags
() =
default
;
33
34
// integer conversion needs to be very explicit
35
static
constexpr
script_verify_flags
from_int
(
value_type
f) {
script_verify_flags
r; r.
m_value
= f;
return
r; }
36
constexpr
value_type
as_int
()
const
{
return
m_value
; }
37
38
// bitwise operations
39
constexpr
script_verify_flags
operator~
()
const
{
return
from_int
(~
m_value
); }
40
friend
constexpr
script_verify_flags
operator|
(
script_verify_flags
a,
script_verify_flags
b) {
return
from_int
(a.
m_value
| b.
m_value
); }
41
friend
constexpr
script_verify_flags
operator&
(
script_verify_flags
a,
script_verify_flags
b) {
return
from_int
(a.
m_value
& b.
m_value
); }
42
43
// in-place bitwise operations
44
constexpr
script_verify_flags
&
operator|=
(
script_verify_flags
vf) {
m_value
|= vf.
m_value
;
return
*
this
; }
45
constexpr
script_verify_flags
&
operator&=
(
script_verify_flags
vf) {
m_value
&= vf.
m_value
;
return
*
this
; }
46
47
// tests
48
constexpr
explicit
operator
bool()
const
{
return
m_value
!= 0; }
49
constexpr
bool
operator==
(
script_verify_flags
other)
const
{
return
m_value
== other.
m_value
; }
50
52
friend
constexpr
std::strong_ordering
operator<=>
(
const
script_verify_flags
& a,
const
script_verify_flags
& b)
noexcept
53
{
54
return
a.m_value <=> b.m_value;
55
}
56
57
private
:
58
value_type
m_value
{0};
// default value is SCRIPT_VERIFY_NONE
59
};
60
61
inline
constexpr
script_verify_flags
operator~
(
script_verify_flag_name
f)
62
{
63
return
~script_verify_flags
{f};
64
}
65
66
inline
constexpr
script_verify_flags
operator|
(
script_verify_flag_name
f1,
script_verify_flag_name
f2)
67
{
68
return
script_verify_flags
{f1} | f2;
69
}
70
71
#endif
// BITCOIN_SCRIPT_VERIFY_FLAGS_H
script_verify_flags
Definition
verify_flags.h:15
script_verify_flags::operator=
constexpr script_verify_flags & operator=(const script_verify_flags &)=default
script_verify_flags::operator|
friend constexpr script_verify_flags operator|(script_verify_flags a, script_verify_flags b)
Definition
verify_flags.h:40
script_verify_flags::script_verify_flags
constexpr script_verify_flags(const script_verify_flags &)=default
script_verify_flags::operator~
constexpr script_verify_flags operator~() const
Definition
verify_flags.h:39
script_verify_flags::operator|=
constexpr script_verify_flags & operator|=(script_verify_flags vf)
Definition
verify_flags.h:44
script_verify_flags::operator<=>
friend constexpr std::strong_ordering operator<=>(const script_verify_flags &a, const script_verify_flags &b) noexcept
Compare two script_verify_flags.
Definition
verify_flags.h:52
script_verify_flags::operator==
constexpr bool operator==(script_verify_flags other) const
Definition
verify_flags.h:49
script_verify_flags::as_int
constexpr value_type as_int() const
Definition
verify_flags.h:36
script_verify_flags::operator&=
constexpr script_verify_flags & operator&=(script_verify_flags vf)
Definition
verify_flags.h:45
script_verify_flags::script_verify_flags
constexpr script_verify_flags(script_verify_flags &&)=default
script_verify_flags::operator&
friend constexpr script_verify_flags operator&(script_verify_flags a, script_verify_flags b)
Definition
verify_flags.h:41
script_verify_flags::script_verify_flags
consteval script_verify_flags()=default
script_verify_flags::~script_verify_flags
constexpr ~script_verify_flags()=default
script_verify_flags::operator=
constexpr script_verify_flags & operator=(script_verify_flags &&)=default
script_verify_flags::value_type
uint64_t value_type
Definition
verify_flags.h:17
script_verify_flags::m_value
value_type m_value
Definition
verify_flags.h:58
script_verify_flags::from_int
static constexpr script_verify_flags from_int(value_type f)
Definition
verify_flags.h:35
script_verify_flag_name
script_verify_flag_name
Definition
interpreter.h:49
operator|
constexpr script_verify_flags operator|(script_verify_flag_name f1, script_verify_flag_name f2)
Definition
verify_flags.h:66
operator~
constexpr script_verify_flags operator~(script_verify_flag_name f)
Definition
verify_flags.h:61
Generated on
for Bitcoin Core by
1.17.0