4#ifndef DASMIG_CORE_RESOURCES_HPP
5#define DASMIG_CORE_RESOURCES_HPP
16#include <system_error>
33 return tier == dataset::full ?
"full" :
"lite";
45 std::span<const std::string_view>
chunks;
49 [[nodiscard]] std::string
text()
const
52 for (
const auto chunk :
chunks) size += chunk.size();
55 for (
const auto chunk :
chunks) out += chunk;
65 std::string_view path)
noexcept
67 for (
const auto& file : files)
69 if (file.path == path)
return &file;
85 std::string_view library,
const std::filesystem::path& base = std::filesystem::current_path())
87 const std::filesystem::path lib{library};
88 return {base /
"resources", base /
".." /
"resources", base / lib /
"resources",
89 base /
".." / lib /
"resources"};
104 std::string_view library, std::string_view marker,
105 const std::filesystem::path& base = std::filesystem::current_path())
110 if (std::filesystem::is_regular_file(dir / marker, ec))
return dir;
130 std::string_view path, std::span<const embedded_file> embedded,
131 const std::optional<std::filesystem::path>& root, std::vector<std::string> columns = {})
133 if (
const auto* file = find_embedded(embedded, path))
135 std::string source =
"embedded:" + std::string{path};
139 if (!root)
return std::nullopt;
140 const auto file = *root / path;
142 if (!std::filesystem::is_regular_file(file, ec))
return std::nullopt;
static tsv_document load(const std::filesystem::path &path, std::vector< std::string > columns={})
Read and parse a file.
static tsv_document parse(std::string_view text, std::string source)
Parse text whose first line names the columns.
The data tier enum shared by every generator library.
dataset
Which tier of a library's bundled data to load.
std::optional< tsv_document > load_resource(std::string_view path, std::span< const embedded_file > embedded, const std::optional< std::filesystem::path > &root, std::vector< std::string > columns={})
Load a data file, compiled-in if available, otherwise from disk.
constexpr const embedded_file * find_embedded(std::span< const embedded_file > files, std::string_view path) noexcept
Find a compiled-in file by path.
constexpr std::string_view tier_name(dataset tier) noexcept
The directory name of a data tier.
std::vector< std::filesystem::path > resource_candidates(std::string_view library, const std::filesystem::path &base=std::filesystem::current_path())
The directories searched for a library's resources/, in order.
std::optional< std::filesystem::path > find_resources(std::string_view library, std::string_view marker, const std::filesystem::path &base=std::filesystem::current_path())
The first candidate directory that contains a marker file.
A data file compiled into the program.
std::string_view path
Path below resources/, e.g. lite/biodata.tsv.
std::string text() const
The whole content.
std::span< const std::string_view > chunks
The content, in order.
Tab-separated data files with typed access and located errors.