12#ifndef MODDEF_DOCUMENT_HPP
13#define MODDEF_DOCUMENT_HPP
26#include "moddef/doc.h"
38 if (
auto e = md_doc_init(&d.doc_, bytes.data(), bytes.size()); e != MD_OK)
39 return std::unexpected(
from_c(e));
46 d.storage_ = std::move(bytes);
47 if (
auto e = md_doc_init(&d.doc_, d.storage_.data(), d.storage_.size()); e != MD_OK)
48 return std::unexpected(
from_c(e));
52 std::string_view
doc_id() const noexcept {
return from_c(md_doc_id(&doc_)); }
54 const md_doc_t*
c_doc() const noexcept {
return &doc_; }
59 if (!storage_.empty()) {
60 doc_.raw.p = storage_.data();
61 doc_.raw.len =
static_cast<std::uint32_t
>(storage_.size());
65 storage_ = std::move(o.storage_);
67 if (!storage_.empty()) {
68 doc_.raw.p = storage_.data();
69 doc_.raw.len =
static_cast<std::uint32_t
>(storage_.size());
79 std::vector<std::uint8_t> storage_;
A parsed ModDef document.
Definition document.hpp:33
Document & operator=(Document &&o) noexcept
Definition document.hpp:64
static Result< Document > view(std::span< const std::uint8_t > bytes)
View over external bytes (no copy).
Definition document.hpp:36
static Result< Document > own(std::vector< std::uint8_t > bytes)
Take ownership of a byte buffer (host-side convenience).
Definition document.hpp:44
std::string_view doc_id() const noexcept
Definition document.hpp:52
Document(const Document &)=delete
Document(Document &&o) noexcept
Definition document.hpp:58
const md_doc_t * c_doc() const noexcept
Definition document.hpp:54
Document & operator=(const Document &)=delete
Error type and Result<T> (spec §26.3/§26.4, §32).
std::expected< T, Error > Result
The canonical result type across the API; Result<void> for actions.
Definition error.hpp:53
Error from_c(md_err_t e) noexcept
Definition error.hpp:46
std::string_view <-> md_str_t bridging.