Bitcoin ABC 0.26.3
P2P Digital Currency
Loading...
Searching...
No Matches
conditionstack.h
Go to the documentation of this file.
1// Copyright (c) 2024 The Bitcoin developers
2// Distributed under the MIT software license, see the accompanying
3// file COPYING or http://www.opensource.org/licenses/mit-license.php.
4
5#ifndef BITCOIN_SCRIPT_CONDITIONSTACK_H
6#define BITCOIN_SCRIPT_CONDITIONSTACK_H
7
8#include <cassert>
9#include <cstdint>
10#include <limits>
11
29private:
31 static constexpr uint32_t NO_FALSE = std::numeric_limits<uint32_t>::max();
32
38
39public:
40 bool empty() const { return m_stack_size == 0; }
41 bool all_true() const { return m_first_false_pos == NO_FALSE; }
42 void push_back(bool f) {
43 if (m_first_false_pos == NO_FALSE && !f) {
44 // The stack consists of all true values, and a false is added.
45 // The first false value will appear at the current size.
47 }
49 }
50 void pop_back() {
54 // When popping off the first false value, everything becomes true.
56 }
57 }
58 void toggle_top() {
61 // The current stack is all true values; the first false will be the
62 // top.
64 } else if (m_first_false_pos == m_stack_size - 1) {
65 // The top is the first false value; toggling it will make
66 // everything true.
68 } else {
69 // There is a false value, but not on top. No action is needed as
70 // toggling anything but the first false value is unobservable.
71 }
72 }
73};
74
75#endif // BITCOIN_SCRIPT_CONDITIONSTACK_H
A data type to abstract out the condition stack during script execution.
void push_back(bool f)
bool empty() const
uint32_t m_first_false_pos
The position of the first false value on the implied stack, or NO_FALSE if all true.
uint32_t m_stack_size
The size of the implied stack.
static constexpr uint32_t NO_FALSE
A constant for m_first_false_pos to indicate there are no falses.
bool all_true() const
T GetRand(T nMax=std::numeric_limits< T >::max()) noexcept
Generate a uniform random integer of type T in the range [0..nMax) nMax defaults to std::numeric_limi...
Definition random.h:85
assert(!tx.IsCoinBase())