wowlib
0.0.0
Read & write World of Warcraft client files — a C++26 core
Toggle main menu visibility
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
>
15
#include <
wowlib/core/file_key.hpp
>
16
#include <
wowlib/core/shared_mutex.hpp
>
17
#include <
wowlib/fs/fdid_allocator.hpp
>
18
#include <
wowlib/fs/listfile.hpp
>
19
20
namespace
wowlib::fs
{
22
struct
CsvListfileOptions
{
25
FileDataID
customFdidStart
{1'000'000'000};
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
37
class
CsvListfile
{
38
public
:
39
using
Options
=
CsvListfileOptions
;
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
;
84
CsvListfile
&
operator=
(
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
}
wowlib::fs::CsvListfile::fdidToPath
std::optional< std::string > fdidToPath(FileDataID fdid) const
Look up the canonical path of a FileDataID.
Definition
csv_listfile.cpp:96
wowlib::fs::CsvListfile::CsvListfile
CsvListfile(const CsvListfile &)=delete
wowlib::fs::CsvListfile::load
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.
Definition
csv_listfile.cpp:55
wowlib::fs::CsvListfile::save
Result< void > save() const
Rewrite the whole working file canonically (ids ascending).
Definition
csv_listfile.cpp:146
wowlib::fs::CsvListfile::CsvListfile
CsvListfile()=default
wowlib::fs::CsvListfile::source
const std::filesystem::path & source() const
Definition
csv_listfile.hpp:81
wowlib::fs::CsvListfile::Options
CsvListfileOptions Options
Definition
csv_listfile.hpp:39
wowlib::fs::CsvListfile::registerPath
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 ...
Definition
csv_listfile.cpp:102
wowlib::fs::CsvListfile::operator=
CsvListfile & operator=(const CsvListfile &)=delete
wowlib::fs::CsvListfile::pathToFdid
std::optional< FileDataID > pathToFdid(std::string_view path) const
Look up the FileDataID of a path (any spelling; canonicalized here).
Definition
csv_listfile.cpp:89
wowlib::fs::CsvListfile::size
std::size_t size() const
Definition
csv_listfile.cpp:169
wowlib::fs::CsvListfile::contains
bool contains(std::string_view path) const
Whether a path is known.
Definition
csv_listfile.cpp:140
wowlib::fs::detail::FdidAllocator
Monotonic allocator for custom (non-Blizzard) FileDataIDs.
Definition
fdid_allocator.hpp:20
wowlib::fs::ListfileProvider
The pluggable path<->FileDataID database contract (CSV today, SQL later).
Definition
listfile.hpp:23
error.hpp
The error-handling vocabulary: ErrorCode, Error and the Result<T> alias every fallible wowlib operati...
fdid_allocator.hpp
The monotonic allocator behind custom (non-Blizzard) FileDataIDs.
file_key.hpp
File identity types: the strong FileDataID and the FileKey a read request travels as.
listfile.hpp
The pluggable listfile-provider contract and the no-database provider for clients that need none.
wowlib::fs
Definition
table_core.hpp:46
wowlib::SharedMutex
std::shared_mutex SharedMutex
Definition
shared_mutex.hpp:47
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
shared_mutex.hpp
Reader/writer mutex used across the library.
wowlib::FileDataID
Definition
file_key.hpp:19
wowlib::fs::CsvListfileOptions
Tuning knobs for loading a listfile.
Definition
csv_listfile.hpp:22
wowlib::fs::CsvListfileOptions::customFdidStart
FileDataID customFdidStart
First FileDataID handed to newly registered files; keep far above Blizzard's ~6-7M so future official...
Definition
csv_listfile.hpp:25
src
wowlib
fs
csv_listfile.hpp
Generated by
1.17.0