wowlib 0.0.0
Read & write World of Warcraft client files — a C++26 core
Loading...
Searching...
No Matches
csv_listfile.hpp
Go to the documentation of this file.
1#pragma once
2
6
7#include <filesystem>
8#include <optional>
9#include <shared_mutex>
10#include <string>
11#include <string_view>
12#include <unordered_map>
13
14#include <wowlib/core/error.hpp>
19
20namespace wowlib::fs {
26 };
27
28 // (namespace-scope rather than nested: gcc late-parses nested-class NSDMIs, so a
29 // `= {}` default argument cannot aggregate-initialize a nested struct)
30
38 public:
40
41 CsvListfile() = default;
42
49 static Result<CsvListfile> load(const std::filesystem::path& csv, Options options = {});
50
54 std::optional<FileDataID> pathToFdid(std::string_view path) const;
55
59 std::optional<std::string> fdidToPath(FileDataID fdid) const;
60
66 Result<FileDataID> registerPath(std::string_view path);
67
71 bool contains(std::string_view path) const;
72
75 Result<void> save() const;
76
78 std::size_t size() const;
79
81 const std::filesystem::path& source() const { return _source; }
82
83 CsvListfile(const CsvListfile&) = delete;
85 CsvListfile(CsvListfile&& other) noexcept;
86 CsvListfile& operator=(CsvListfile&& other) noexcept;
87
88 private:
89 std::filesystem::path _source;
90 mutable SharedMutex _mtx;
91 std::unordered_map<std::string, FileDataID> _pathToId;
92 std::unordered_map<std::uint32_t, std::string> _idToPath;
93 detail::FdidAllocator _allocator;
94 };
95
96 static_assert(ListfileProvider<CsvListfile>);
97}
std::optional< std::string > fdidToPath(FileDataID fdid) const
Look up the canonical path of a FileDataID.
CsvListfile(const CsvListfile &)=delete
static Result< CsvListfile > load(const std::filesystem::path &csv, Options options={})
Load a listfile CSV; the file becomes the working database that registerPath appends to.
Result< void > save() const
Rewrite the whole working file canonically (ids ascending).
const std::filesystem::path & source() const
CsvListfileOptions Options
Result< FileDataID > registerPath(std::string_view path)
Allocate a fresh custom FileDataID for a new path, remember the mapping and append it to the working ...
CsvListfile & operator=(const CsvListfile &)=delete
std::optional< FileDataID > pathToFdid(std::string_view path) const
Look up the FileDataID of a path (any spelling; canonicalized here).
std::size_t size() const
bool contains(std::string_view path) const
Whether a path is known.
Monotonic allocator for custom (non-Blizzard) FileDataIDs.
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...
The monotonic allocator behind custom (non-Blizzard) FileDataIDs.
File identity types: the strong FileDataID and the FileKey a read request travels as.
The pluggable listfile-provider contract and the no-database provider for clients that need none.
std::shared_mutex SharedMutex
std::expected< T, Error > Result
Every fallible wowlib operation returns Result<T>; bindings translate the error branch into a target-...
Definition error.hpp:100
Reader/writer mutex used across the library.
Tuning knobs for loading a listfile.
FileDataID customFdidStart
First FileDataID handed to newly registered files; keep far above Blizzard's ~6-7M so future official...