wowlib 0.0.0
Read & write World of Warcraft client files — a C++26 core
Loading...
Searching...
No Matches
wowlib::fs::CsvListfile Class Reference

The CSV-backed path<->FileDataID database ('fileDataId;filepath' per line, the community listfile format of github.com/wowdev/wow-listfile). More...

#include <wowlib/fs/csv_listfile.hpp>

Public Types

using Options = CsvListfileOptions

Public Member Functions

 CsvListfile ()=default
std::optional< FileDataID > pathToFdid (std::string_view path) const
 Look up the FileDataID of a path (any spelling; canonicalized here).
std::optional< std::string > fdidToPath (FileDataID fdid) const
 Look up the canonical path of a FileDataID.
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 file (in-memory only when the database was not loaded from a file).
bool contains (std::string_view path) const
 Whether a path is known.
Result< void > save () const
 Rewrite the whole working file canonically (ids ascending).
std::size_t size () const
const std::filesystem::path & source () const
 CsvListfile (const CsvListfile &)=delete
CsvListfile & operator= (const CsvListfile &)=delete
 CsvListfile (CsvListfile &&other) noexcept
CsvListfile & operator= (CsvListfile &&other) noexcept

Static Public Member Functions

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.

Detailed Description

The CSV-backed path<->FileDataID database ('fileDataId;filepath' per line, the community listfile format of github.com/wowdev/wow-listfile).

The supplied file is the working database: lookups read from it, registrations append to it, so customizations live right next to the community data and survive reloads. Thread-safe: concurrent lookups, exclusive registration. Not welded — target languages reach it through the FileSystem facade.

Definition at line 37 of file csv_listfile.hpp.

Member Typedef Documentation

◆ Options

Constructor & Destructor Documentation

◆ CsvListfile() [1/3]

wowlib::fs::CsvListfile::CsvListfile ( )
default

◆ CsvListfile() [2/3]

wowlib::fs::CsvListfile::CsvListfile ( const CsvListfile & )
delete

References CsvListfile().

◆ CsvListfile() [3/3]

wowlib::fs::CsvListfile::CsvListfile ( CsvListfile && other)
noexcept

Definition at line 36 of file csv_listfile.cpp.

References CsvListfile().

Member Function Documentation

◆ contains()

bool wowlib::fs::CsvListfile::contains ( std::string_view path) const

Whether a path is known.

Parameters
paththe client-internal file path.
Returns
true if the path has a FileDataID.

Definition at line 140 of file csv_listfile.cpp.

References wowlib::normalizePath().

◆ fdidToPath()

std::optional< std::string > wowlib::fs::CsvListfile::fdidToPath ( FileDataID fdid) const

Look up the canonical path of a FileDataID.

Parameters
fdidthe numeric file identifier.
Returns
the canonical path, or nothing on a miss.

Definition at line 96 of file csv_listfile.cpp.

References wowlib::FileDataID::value.

◆ load()

Result< CsvListfile > wowlib::fs::CsvListfile::load ( const std::filesystem::path & csv,
Options options = {} )
static

Load a listfile CSV; the file becomes the working database that registerPath appends to.

Later lines override earlier ones, and the custom-id allocator resumes after the highest custom id present.

Parameters
csvpath to the CSV on disk.
optionsloading options.
Returns
the loaded database, or ListfileIoError/ListfileParseError.

Definition at line 55 of file csv_listfile.cpp.

References CsvListfile(), wowlib::fs::CsvListfileOptions::customFdidStart, wowlib::ListfileIoError, wowlib::makeError(), and wowlib::fs::detail::FdidAllocator::noteExisting().

Referenced by wowlib::fs::FileSystem::open().

◆ operator=() [1/2]

CsvListfile & wowlib::fs::CsvListfile::operator= ( const CsvListfile & )
delete

References CsvListfile().

◆ operator=() [2/2]

CsvListfile & wowlib::fs::CsvListfile::operator= ( CsvListfile && other)
noexcept

Definition at line 44 of file csv_listfile.cpp.

References CsvListfile().

◆ pathToFdid()

std::optional< FileDataID > wowlib::fs::CsvListfile::pathToFdid ( std::string_view path) const

Look up the FileDataID of a path (any spelling; canonicalized here).

Parameters
paththe client-internal file path.
Returns
the id, or nothing on a miss.

Definition at line 89 of file csv_listfile.cpp.

References wowlib::normalizePath().

◆ registerPath()

Result< FileDataID > wowlib::fs::CsvListfile::registerPath ( std::string_view path)

Allocate a fresh custom FileDataID for a new path, remember the mapping and append it to the working file (in-memory only when the database was not loaded from a file).

Fails with DuplicatePath if the path is already known.

Parameters
paththe client-internal path of the new file.
Returns
the newly allocated id.

Definition at line 102 of file csv_listfile.cpp.

References wowlib::DuplicatePath, wowlib::InvalidPath, wowlib::ListfileIoError, wowlib::makeError(), wowlib::normalizePath(), size(), and wowlib::toNativeRelative().

◆ save()

Result< void > wowlib::fs::CsvListfile::save ( ) const

Rewrite the whole working file canonically (ids ascending).

Returns
nothing, or ListfileIoError.

Definition at line 146 of file csv_listfile.cpp.

References wowlib::ListfileIoError, wowlib::makeError(), and wowlib::toNativeRelative().

◆ size()

std::size_t wowlib::fs::CsvListfile::size ( ) const
Returns
the number of known mappings.

Definition at line 169 of file csv_listfile.cpp.

Referenced by registerPath().

◆ source()

const std::filesystem::path & wowlib::fs::CsvListfile::source ( ) const
inline
Returns
the working file registrations append to (empty if in-memory).

Definition at line 81 of file csv_listfile.hpp.


The documentation for this class was generated from the following files: