wowlib 0.0.0
Read & write World of Warcraft client files — a C++26 core
Loading...
Searching...
No Matches
typed.hpp File Reference

Typed C++ access to the generic client-database engine: DECLARE YOUR OWN row struct, validated at COMPILE TIME against the same WoWDBDefs data the runtime engine uses. More...

#include <algorithm>
#include <bit>
#include <cstddef>
#include <cstdint>
#include <meta>
#include <span>
#include <string>
#include <string_view>
#include <type_traits>
#include <vector>
#include <wowlib/core/error.hpp>
#include <wowlib/db/dyn_table.hpp>
#include <wowlib/db/record_bridge.hpp>
#include <wowlib/db/schema.hpp>
#include <wowlib/db/schema_blob.hpp>
Include dependency graph for typed.hpp:

Go to the source code of this file.

Classes

struct  wowlib::db::detail::TypedMismatch
 The consteval-validation failure carrier: throwing it inside constant evaluation aborts compilation with the message in the diagnostic. More...
struct  wowlib::db::detail::FixedString< N >
 A compile-time string NTTP (the column<"id">() spelling). More...
class  wowlib::db::TypedTable< Record >
 A typed, consteval-validated face over one DynTable: the table itself stays fully generic (every column decodes, byte-perfect round-trip holds); this projects rows into Record values, copies edits back, and hands out zero-copy typed column spans. More...

Namespaces

namespace  wowlib
namespace  wowlib::db
namespace  wowlib::db::detail

Functions

consteval blob::RangeEntry wowlib::db::detail::typedRangeOf (std::string_view table, ClientVersion version)
 The blob's column list for (table, version)'s era, as blob-global column indexes [first, first+count), or a thrown TypedMismatch.
consteval std::size_t wowlib::db::detail::typedColumnIndex (std::string_view table, ClientVersion version, std::string_view name)
 The era-schema column index whose name is name, or a thrown TypedMismatch.
template<typename Record>
consteval bool wowlib::db::detail::typedValidate ()
 Validate Record against the blob (see the file note for the rules); also the projection builder's precondition.
template<typename Record>
consteval auto wowlib::db::detail::typedProjection ()
 The projection map of Record: member position -> era-schema column index, as a static (never-dangling) array.

Variables

constexpr unsigned char wowlib::db::detail::TypedSchemaBlob []
 The blob, again, for CONSTANT EVALUATION in consumer TUs (the runtime catalog's copy lives inside schema_catalog.cpp).

Detailed Description

Typed C++ access to the generic client-database engine: DECLARE YOUR OWN row struct, validated at COMPILE TIME against the same WoWDBDefs data the runtime engine uses.

The struct names its table and client version like every generated record does (the wowlib::db::TableRecord shape) and lists the columns it wants as ordinary members — a SUBSET is a projection:

struct MapRow
{
static constexpr ClientVersion version = versions::wotlk;
static constexpr std::string_view TableName = "Map";
std::int32_t id = 0;
std::string directory; // any subset of the DBD's columns, by name
};
auto table = db::TypedTable<MapRow>::open(); // consteval-validated
table->read(bytes);
for (const MapRow& row : table->load()) use(row);
auto ids = table->column<"id">(); // zero-copy span

Validation happens in constant evaluation against the #embeded schema blob (schema_blob.hpp — the identical bytes SchemaCatalog serves at runtime): every member must match a column of the struct's era BY NAME and BY SHAPE (value class, integer width and signedness, array length, locale count). A mismatch aborts compilation with a thrown diagnostic naming what disagreed. Member ROLES (id/relation/noninline) are not validated — the blob's full schema drives the codecs; the struct is only a projection over it. writeBack is consteval-gated to structs covering EVERY column (a projection cannot author a lossless table).

Requires an embedded-capable build (WOWLIB_DB_SCHEMA embedded/both); a runtime-schema-only build has no bytes to validate against.

Definition in file typed.hpp.