wowlib 0.0.0
Read & write World of Warcraft client files — a C++26 core
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>
12
21 public:
25 explicit FdidAllocator(FileDataID start = FileDataID{1'000'000'000}, FileDataID max = FileDataID{0xFFFFFFFE})
26 : _next(start.value), _max(max.value) {}
27
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
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}
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...
FileDataID peek() const
The id the next successful call to next() would return.
Result< FileDataID > next()
Allocate the next id.
FdidAllocator(FileDataID start=FileDataID{1 '000 '000 '000}, FileDataID max=FileDataID{0xFFFFFFFE})
The error-handling vocabulary: ErrorCode, Error and the Result<T> alias every fallible wowlib operati...
File identity types: the strong FileDataID and the FileKey a read request travels as.
std::expected< T, Error > Result
Every fallible wowlib operation returns Result<T>; bindings translate the error branch into a target-...
Definition error.hpp:100
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
@ FdidSpaceExhausted
The custom FileDataID allocator ran out of u32 space.
Definition error.hpp:27