wowlib 0.0.0
Read & write World of Warcraft client files — a C++26 core
Loading...
Searching...
No Matches
schema_catalog.hpp
Go to the documentation of this file.
1#pragma once
2
20
21#include <cstddef>
22#include <cstdint>
23#include <filesystem>
24#include <span>
25#include <string_view>
26#include <vector>
27
29#include <wowlib/core/error.hpp>
30#include <wowlib/db/schema.hpp>
31
32#ifndef WOWLIB_DB_SCHEMA_EMBEDDED
33#define WOWLIB_DB_SCHEMA_EMBEDDED 1
34#endif
35#ifndef WOWLIB_DB_SCHEMA_RUNTIME
36#define WOWLIB_DB_SCHEMA_RUNTIME 1
37#endif
38
39namespace wowlib::db {
42 struct TableSchema {
43 std::string_view name;
44 std::string_view diskName;
45 std::span<const Column> columns;
46 };
47
51 public:
52#if WOWLIB_DB_SCHEMA_EMBEDDED
55 static const SchemaCatalog& embedded();
56#endif
57
58#if WOWLIB_DB_SCHEMA_RUNTIME
62 static Result<SchemaCatalog> fromBlob(std::vector<unsigned char> bytes);
63
67 static Result<SchemaCatalog> fromBlobFile(const std::filesystem::path& path);
68
80 static Result<SchemaCatalog> fromDbdDir(const std::filesystem::path& definitions);
81#endif
82
83 SchemaCatalog(SchemaCatalog&&) noexcept = default;
84 SchemaCatalog& operator=(SchemaCatalog&&) noexcept = default;
85 SchemaCatalog(const SchemaCatalog&) = delete;
86 SchemaCatalog& operator=(const SchemaCatalog&) = delete;
87
94 Result<TableSchema> lookup(std::string_view table, ClientVersion version) const;
95
97 std::size_t tableCount() const { return _tables.size(); }
98
103 std::string_view tableName(std::size_t i) const { return _tables[i].name; }
104
107 std::span<const ClientVersion> eras() const { return _eras; }
108
109 private:
110 SchemaCatalog() = default;
111
113 struct RangeIndex {
114 std::uint32_t firstColumn = 0;
115 std::uint32_t columnCount = 0;
116 std::uint16_t eraMask = 0;
117 };
118
120 struct TableIndex {
121 std::string_view name;
122 std::string_view diskName;
123 std::uint32_t firstRange = 0;
124 std::uint32_t rangeCount = 0;
125 };
126
130 static SchemaCatalog _materialize(std::span<const unsigned char> bytes, std::vector<unsigned char> owned);
131
133 Result<std::size_t> _eraIndexOf(ClientVersion version) const;
134
135 std::vector<unsigned char> _owned;
136 std::vector<ClientVersion> _eras;
137 std::vector<TableIndex> _tables;
138 std::vector<RangeIndex> _ranges;
139 std::vector<Column> _columns;
140 };
141}
std::string_view tableName(std::size_t i) const
The identifier name of table i (name-sorted order) — enumeration for tooling and the bindings' listin...
std::size_t tableCount() const
std::span< const ClientVersion > eras() const
The era table the blob was built against (index = mask bit).
SchemaCatalog(SchemaCatalog &&) noexcept=default
Result< TableSchema > lookup(std::string_view table, ClientVersion version) const
Resolve the schema of table for client version.
Client version identity, the flavor axis that separates a client's CONTENT version from the engine ge...
The error-handling vocabulary: ErrorCode, Error and the Result<T> alias every fallible wowlib operati...
std::expected< T, Error > Result
Every fallible wowlib operation returns Result<T>; bindings translate the error branch into a target-...
Definition error.hpp:100
Schema reflection over generated client-database record structs: the column list, record stride and f...
One resolved (table, client version) schema: what SchemaCatalog::lookup hands the engine.
std::string_view name
The identifier name ("ItemSparseLegacy").
std::span< const Column > columns
The era's column list, WoWDBDefs order.
std::string_view diskName
The on-disk truth ("Item-sparse").