Skip to content

Commit e7427bc

Browse files
committed
feat: Offset2ID support for v5
1 parent 875005e commit e7427bc

3 files changed

Lines changed: 24 additions & 15 deletions

File tree

include/REL/IDDB.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,8 @@ namespace REL
5050
void unpack_file(STREAM& a_stream, const HEADER_V2& a_header);
5151

5252
protected:
53+
friend class Offset2ID;
54+
5355
// clang-format off
5456
template <class T> std::span<T> get_id2offset() const noexcept;
5557
template <> std::span<MAPPING> get_id2offset() const noexcept { return m_v0; }

include/REL/Offset2ID.h

Lines changed: 21 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -6,32 +6,42 @@
66

77
namespace REL
88
{
9-
template <class T>
10-
class Offset2ID
9+
class Offset2ID :
10+
public REX::Singleton<Offset2ID>
1111
{
1212
public:
13-
using value_type = T;
13+
using value_type = IDDB::MAPPING;
1414
using container_type = std::vector<value_type>;
1515
using size_type = typename container_type::size_type;
1616
using const_iterator = typename container_type::const_iterator;
1717
using const_reverse_iterator = typename container_type::const_reverse_iterator;
1818

19-
template <class ExecutionPolicy>
20-
explicit Offset2ID(ExecutionPolicy&& a_policy) // NOLINT(bugprone-forwarding-reference-overload)
21-
requires(std::is_execution_policy_v<std::decay_t<ExecutionPolicy>>)
19+
void load(std::span<IDDB::MAPPING> a_span)
2220
{
2321
const auto iddb = IDDB::GetSingleton();
24-
const auto id2offset = iddb->get_id2offset<T>();
22+
const auto id2offset = iddb->get_id2offset<IDDB::MAPPING>();
2523
_offset2id.reserve(id2offset.size());
2624
_offset2id.insert(_offset2id.begin(), id2offset.begin(), id2offset.end());
27-
std::sort(a_policy, _offset2id.begin(), _offset2id.end(), [](auto&& a_lhs, auto&& a_rhs) {
25+
std::sort(std::execution::sequenced_policy{}, _offset2id.begin(), _offset2id.end(), [](auto&& a_lhs, auto&& a_rhs) {
2826
return a_lhs.offset < a_rhs.offset;
2927
});
3028
}
3129

32-
Offset2ID() :
33-
Offset2ID(std::execution::sequenced_policy{})
34-
{}
30+
void load(std::span<std::uint32_t> a_span)
31+
{
32+
const auto iddb = IDDB::GetSingleton();
33+
const auto id2offset = iddb->get_id2offset<std::uint32_t>();
34+
_offset2id.reserve(id2offset.size());
35+
36+
std::uint64_t id{ 0 };
37+
for (auto offset : id2offset) {
38+
value_type map{ id++, offset };
39+
_offset2id.emplace_back(map);
40+
}
41+
std::sort(std::execution::sequenced_policy{}, _offset2id.begin(), _offset2id.end(), [](auto&& a_lhs, auto&& a_rhs) {
42+
return a_lhs.offset < a_rhs.offset;
43+
});
44+
}
3545

3646
[[nodiscard]] std::uint64_t operator()(std::size_t a_offset) const
3747
{
@@ -74,9 +84,6 @@ namespace REL
7484

7585
[[nodiscard]] size_type size() const noexcept { return _offset2id.size(); }
7686

77-
protected:
78-
friend class IDDB;
79-
8087
private:
8188
container_type _offset2id;
8289
};

include/REL/Relocation.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -374,7 +374,7 @@ namespace REL
374374

375375
private:
376376
// clang-format off
377-
[[nodiscard]] static std::uintptr_t base() { return Module::get().base(); }
377+
[[nodiscard]] static std::uintptr_t base() { return Module::GetSingleton()->base(); }
378378
// clang-format on
379379

380380
std::uintptr_t _impl{ 0 };

0 commit comments

Comments
 (0)