Line | Count | Source |
1 | | /* |
2 | | * Copyright (c) 2021, Jesse Buhagiar <jooster669@gmail.com> |
3 | | * |
4 | | * SPDX-License-Identifier: BSD-2-Clause |
5 | | */ |
6 | | |
7 | | #pragma once |
8 | | |
9 | | #include <AK/Vector.h> |
10 | | |
11 | | namespace AK { |
12 | | |
13 | | template<typename T, size_t stack_size> |
14 | | class Stack { |
15 | | public: |
16 | 0 | Stack() = default; Unexecuted instantiation: AK::Stack<regex::Regex<regex::PosixBasicParser>::attempt_rewrite_loops_as_atomic_groups(AK::Vector<regex::Detail::Block, 0ul> const&)::Patch, 2ul>::Stack() Unexecuted instantiation: AK::Stack<regex::Regex<regex::PosixExtendedParser>::attempt_rewrite_loops_as_atomic_groups(AK::Vector<regex::Detail::Block, 0ul> const&)::Patch, 2ul>::Stack() Unexecuted instantiation: AK::Stack<regex::Regex<regex::ECMA262Parser>::attempt_rewrite_loops_as_atomic_groups(AK::Vector<regex::Detail::Block, 0ul> const&)::Patch, 2ul>::Stack() |
17 | 0 | ~Stack() = default; Unexecuted instantiation: AK::Stack<regex::Regex<regex::PosixBasicParser>::attempt_rewrite_loops_as_atomic_groups(AK::Vector<regex::Detail::Block, 0ul> const&)::Patch, 2ul>::~Stack() Unexecuted instantiation: AK::Stack<regex::Regex<regex::PosixExtendedParser>::attempt_rewrite_loops_as_atomic_groups(AK::Vector<regex::Detail::Block, 0ul> const&)::Patch, 2ul>::~Stack() Unexecuted instantiation: AK::Stack<regex::Regex<regex::ECMA262Parser>::attempt_rewrite_loops_as_atomic_groups(AK::Vector<regex::Detail::Block, 0ul> const&)::Patch, 2ul>::~Stack() |
18 | | |
19 | | bool push(T const& item) |
20 | | { |
21 | | if (m_stack.size() >= stack_size) |
22 | | return false; |
23 | | |
24 | | m_stack.unchecked_append(item); |
25 | | return true; |
26 | | } |
27 | | |
28 | | bool push(T&& item) |
29 | 0 | { |
30 | 0 | if (m_stack.size() >= stack_size) |
31 | 0 | return false; |
32 | | |
33 | 0 | m_stack.unchecked_append(move(item)); |
34 | 0 | return true; |
35 | 0 | } Unexecuted instantiation: AK::Stack<regex::Regex<regex::PosixBasicParser>::attempt_rewrite_loops_as_atomic_groups(AK::Vector<regex::Detail::Block, 0ul> const&)::Patch, 2ul>::push(regex::Regex<regex::PosixBasicParser>::attempt_rewrite_loops_as_atomic_groups(AK::Vector<regex::Detail::Block, 0ul> const&)::Patch&&) Unexecuted instantiation: AK::Stack<regex::Regex<regex::PosixExtendedParser>::attempt_rewrite_loops_as_atomic_groups(AK::Vector<regex::Detail::Block, 0ul> const&)::Patch, 2ul>::push(regex::Regex<regex::PosixExtendedParser>::attempt_rewrite_loops_as_atomic_groups(AK::Vector<regex::Detail::Block, 0ul> const&)::Patch&&) Unexecuted instantiation: AK::Stack<regex::Regex<regex::ECMA262Parser>::attempt_rewrite_loops_as_atomic_groups(AK::Vector<regex::Detail::Block, 0ul> const&)::Patch, 2ul>::push(regex::Regex<regex::ECMA262Parser>::attempt_rewrite_loops_as_atomic_groups(AK::Vector<regex::Detail::Block, 0ul> const&)::Patch&&) |
36 | | |
37 | | bool is_empty() const |
38 | 0 | { |
39 | 0 | return m_stack.is_empty(); |
40 | 0 | } Unexecuted instantiation: AK::Stack<regex::Regex<regex::PosixBasicParser>::attempt_rewrite_loops_as_atomic_groups(AK::Vector<regex::Detail::Block, 0ul> const&)::Patch, 2ul>::is_empty() const Unexecuted instantiation: AK::Stack<regex::Regex<regex::PosixExtendedParser>::attempt_rewrite_loops_as_atomic_groups(AK::Vector<regex::Detail::Block, 0ul> const&)::Patch, 2ul>::is_empty() const Unexecuted instantiation: AK::Stack<regex::Regex<regex::ECMA262Parser>::attempt_rewrite_loops_as_atomic_groups(AK::Vector<regex::Detail::Block, 0ul> const&)::Patch, 2ul>::is_empty() const |
41 | | |
42 | | size_t size() const |
43 | | { |
44 | | return m_stack.size(); |
45 | | } |
46 | | |
47 | | bool pop() |
48 | 0 | { |
49 | 0 | if (is_empty()) |
50 | 0 | return false; |
51 | | |
52 | 0 | m_stack.shrink(m_stack.size() - 1, true); |
53 | 0 | return true; |
54 | 0 | } Unexecuted instantiation: AK::Stack<regex::Regex<regex::PosixBasicParser>::attempt_rewrite_loops_as_atomic_groups(AK::Vector<regex::Detail::Block, 0ul> const&)::Patch, 2ul>::pop() Unexecuted instantiation: AK::Stack<regex::Regex<regex::PosixExtendedParser>::attempt_rewrite_loops_as_atomic_groups(AK::Vector<regex::Detail::Block, 0ul> const&)::Patch, 2ul>::pop() Unexecuted instantiation: AK::Stack<regex::Regex<regex::ECMA262Parser>::attempt_rewrite_loops_as_atomic_groups(AK::Vector<regex::Detail::Block, 0ul> const&)::Patch, 2ul>::pop() |
55 | | |
56 | | T& top() |
57 | 0 | { |
58 | 0 | return m_stack.last(); |
59 | 0 | } Unexecuted instantiation: AK::Stack<regex::Regex<regex::PosixBasicParser>::attempt_rewrite_loops_as_atomic_groups(AK::Vector<regex::Detail::Block, 0ul> const&)::Patch, 2ul>::top() Unexecuted instantiation: AK::Stack<regex::Regex<regex::PosixExtendedParser>::attempt_rewrite_loops_as_atomic_groups(AK::Vector<regex::Detail::Block, 0ul> const&)::Patch, 2ul>::top() Unexecuted instantiation: AK::Stack<regex::Regex<regex::ECMA262Parser>::attempt_rewrite_loops_as_atomic_groups(AK::Vector<regex::Detail::Block, 0ul> const&)::Patch, 2ul>::top() |
60 | | |
61 | | T const& top() const |
62 | | { |
63 | | return m_stack.last(); |
64 | | } |
65 | | |
66 | | bool contains_slow(T const& value) const |
67 | | { |
68 | | return m_stack.contains_slow(value); |
69 | | } |
70 | | |
71 | | private: |
72 | | Vector<T, stack_size> m_stack; |
73 | | }; |
74 | | |
75 | | } |
76 | | |
77 | | #if USING_AK_GLOBALLY |
78 | | using AK::Stack; |
79 | | #endif |