wowlib 0.0.0
Read & write World of Warcraft client files — a C++26 core
Loading...
Searching...
No Matches
listfile.hpp
Go to the documentation of this file.
1#pragma once
2
6
7#include <concepts>
8#include <optional>
9#include <string>
10#include <string_view>
11
12#include <wowlib/core/error.hpp>
14
15namespace wowlib::fs {
23 template <typename L> concept ListfileProvider = requires(L l, const L cl, std::string_view path, FileDataID id) {
24 { cl.pathToFdid(path) } -> std::same_as<std::optional<FileDataID>>; {
25 cl.fdidToPath(id)
26 } -> std::same_as<std::optional<std::string>>; { l.registerPath(path) } -> std::same_as<Result<FileDataID>>; {
27 cl.contains(path)
28 } -> std::same_as<bool>;
29 };
30
33 struct NullListfile {
35 std::optional<FileDataID> pathToFdid(std::string_view) const {
36 return std::nullopt;
37 }
38
40 std::optional<std::string> fdidToPath(FileDataID) const {
41 return std::nullopt;
42 }
43
45 Result<FileDataID> registerPath(std::string_view) {
47 "NullListfile cannot register paths; this client has no " "FileDataID space");
48 }
49
51 bool contains(std::string_view) const { return false; }
52 };
53
54 static_assert(ListfileProvider<NullListfile>);
55}
The pluggable path<->FileDataID database contract (CSV today, SQL later).
Definition listfile.hpp:23
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
@ NotSupported
Operation not supported by this backend/provider.
Definition error.hpp:32
The no-database provider for clients that need none (MPQ-era).
Definition listfile.hpp:33
Result< FileDataID > registerPath(std::string_view)
Never supported.
Definition listfile.hpp:45
bool contains(std::string_view) const
Never contained.
Definition listfile.hpp:51
std::optional< std::string > fdidToPath(FileDataID) const
Always misses.
Definition listfile.hpp:40
std::optional< FileDataID > pathToFdid(std::string_view) const
Always misses.
Definition listfile.hpp:35