Files
wfassoc/example/qwfassoc/src/manifest.h

56 lines
1.7 KiB
C++

#pragma once
#ifndef QWFASSOC_MANIFEST_H_
#define QWFASSOC_MANIFEST_H_
#include <map>
#include <optional>
#include <string>
#include <wfassoc++.h>
namespace qwfassoc {
// Description of a single extension declared in the manifest.
//
// For a given extension (e.g. "jpg"), the manifest references one entry from
// each of the `strs`, `icons` and `behaviors` tables by its token name.
struct ManifestExt {
std::string name;
std::string icon;
std::string behavior;
};
// In-memory representation of a wfassoc manifest TOML file.
//
// This struct mirrors the Rust `Manifest` type defined in
// `wfassoc-exec/src/manifest.rs`. All validation that requires the wfassoc
// library itself (identifier regex, dangling references, etc.) is deferred to
// `wfassocpp::Program` construction; this struct only performs TOML parsing.
struct Manifest {
std::string identifier;
std::string path;
std::string clsid;
std::optional<std::string> name;
std::optional<std::string> icon;
std::optional<std::string> behavior;
std::map<std::string, std::string> strs;
std::map<std::string, std::string> icons;
std::map<std::string, std::string> behaviors;
std::map<std::string, ManifestExt> exts;
// Parse a manifest TOML file from disk.
// Throws std::runtime_error on any IO or TOML syntax error.
static Manifest fromFile(const std::string& path);
// Build a wfassocpp::Schema from this manifest.
// Throws std::runtime_error (originating from wfassocpp::_Check) when the
// wfassoc library rejects an operation, e.g. on duplicate keys.
wfassocpp::Schema toSchema() const;
};
} // namespace qwfassoc
#endif // QWFASSOC_MANIFEST_H_