summaryrefslogtreecommitdiff
path: root/src/common/range_sets.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/common/range_sets.h')
-rw-r--r--src/common/range_sets.h73
1 files changed, 73 insertions, 0 deletions
diff --git a/src/common/range_sets.h b/src/common/range_sets.h
new file mode 100644
index 000000000..f8fcee483
--- /dev/null
+++ b/src/common/range_sets.h
@@ -0,0 +1,73 @@
1// SPDX-FileCopyrightText: 2024 yuzu Emulator Project
2// SPDX-License-Identifier: GPL-2.0-or-later
3
4#pragma once
5
6#include <memory>
7
8#include "common/common_types.h"
9
10namespace Common {
11
12template <typename AddressType>
13class RangeSet {
14public:
15 RangeSet();
16 ~RangeSet();
17
18 RangeSet(RangeSet const&) = delete;
19 RangeSet& operator=(RangeSet const&) = delete;
20
21 RangeSet(RangeSet&& other);
22 RangeSet& operator=(RangeSet&& other);
23
24 void Add(AddressType base_address, size_t size);
25 void Subtract(AddressType base_address, size_t size);
26 void Clear();
27 bool Empty() const;
28
29 template <typename Func>
30 void ForEach(Func&& func) const;
31
32 template <typename Func>
33 void ForEachInRange(AddressType device_addr, size_t size, Func&& func) const;
34
35private:
36 struct RangeSetImpl;
37 std::unique_ptr<RangeSetImpl> m_impl;
38};
39
40template <typename AddressType>
41class OverlapRangeSet {
42public:
43 OverlapRangeSet();
44 ~OverlapRangeSet();
45
46 OverlapRangeSet(OverlapRangeSet const&) = delete;
47 OverlapRangeSet& operator=(OverlapRangeSet const&) = delete;
48
49 OverlapRangeSet(OverlapRangeSet&& other);
50 OverlapRangeSet& operator=(OverlapRangeSet&& other);
51
52 void Add(AddressType base_address, size_t size);
53 void Subtract(AddressType base_address, size_t size);
54
55 template <typename Func>
56 void Subtract(AddressType base_address, size_t size, Func&& on_delete);
57
58 void DeleteAll(AddressType base_address, size_t size);
59 void Clear();
60 bool Empty() const;
61
62 template <typename Func>
63 void ForEach(Func&& func) const;
64
65 template <typename Func>
66 void ForEachInRange(AddressType device_addr, size_t size, Func&& func) const;
67
68private:
69 struct OverlapRangeSetImpl;
70 std::unique_ptr<OverlapRangeSetImpl> m_impl;
71};
72
73} // namespace Common