wowlib
0.0.0
Read & write World of Warcraft client files — a C++26 core
Toggle main menu visibility
Loading...
Searching...
No Matches
fdid_allocator.hpp
Go to the documentation of this file.
1
#pragma once
2
6
7
#include <cstdint>
8
#include <format>
9
10
#include <
wowlib/core/error.hpp
>
11
#include <
wowlib/core/file_key.hpp
>
12
13
namespace
wowlib::fs::detail
{
20
class
FdidAllocator
{
21
public
:
25
explicit
FdidAllocator
(
FileDataID
start =
FileDataID
{1'000'000'000},
FileDataID
max =
FileDataID
{0xFFFFFFFE})
26
: _next(start.value), _max(max.value) {}
27
30
Result<FileDataID>
next
() {
31
if
(_next > _max)
32
return
makeError
(
ErrorCode::FdidSpaceExhausted
, std::format(
"custom FileDataID space exhausted at {}"
, _max));
33
return
FileDataID
{
static_cast<
std::uint32_t
>
(_next++)};
34
}
35
39
void
noteExisting
(
FileDataID
id
) {
40
if
(
id
.value >= _next &&
id
.value <= _max) _next =
id
.value + 1;
41
}
42
45
FileDataID
peek
()
const
{
46
return
FileDataID
{
static_cast<
std::uint32_t
>
(_next)};
47
}
48
49
private
:
50
std::uint64_t _next;
51
// u64 internally so _next can pass _max without wrapping
52
std::uint64_t _max;
53
};
54
}
wowlib::fs::detail::FdidAllocator::noteExisting
void noteExisting(FileDataID id)
Bump the allocator past an id seen in a loaded listfile, so re-opening a project never re-hands-out a...
Definition
fdid_allocator.hpp:39
wowlib::fs::detail::FdidAllocator::peek
FileDataID peek() const
The id the next successful call to next() would return.
Definition
fdid_allocator.hpp:45
wowlib::fs::detail::FdidAllocator::next
Result< FileDataID > next()
Allocate the next id.
Definition
fdid_allocator.hpp:30
wowlib::fs::detail::FdidAllocator::FdidAllocator
FdidAllocator(FileDataID start=FileDataID{1 '000 '000 '000}, FileDataID max=FileDataID{0xFFFFFFFE})
Definition
fdid_allocator.hpp:25
error.hpp
The error-handling vocabulary: ErrorCode, Error and the Result<T> alias every fallible wowlib operati...
file_key.hpp
File identity types: the strong FileDataID and the FileKey a read request travels as.
wowlib::fs::detail
Definition
fdid_allocator.hpp:13
wowlib::Result
std::expected< T, Error > Result
Every fallible wowlib operation returns Result<T>; bindings translate the error branch into a target-...
Definition
error.hpp:100
wowlib::makeError
std::unexpected< Error > makeError(ErrorCode code, std::string message, std::uint32_t nativeError=0)
Shorthand for constructing the error branch of a Result.
Definition
error.hpp:107
wowlib::ErrorCode::FdidSpaceExhausted
@ FdidSpaceExhausted
The custom FileDataID allocator ran out of u32 space.
Definition
error.hpp:27
wowlib::FileDataID
Definition
file_key.hpp:19
src
wowlib
fs
fdid_allocator.hpp
Generated by
1.17.0