42LayerValue<std::size_t> parse_size_t(
const std::optional<std::string> &raw_value,
const std::string &option_name)
44 if (!raw_value.has_value()) {
48 const auto &str = raw_value.value();
51 std::size_t value = 0;
52 const auto *begin = str.data();
53 const auto *
end = str.data() + str.size();
54 auto [ptr, ec] = std::from_chars(begin,
end, value);
56 if (ec == std::errc{} && ptr ==
end) {
60 if (ec == std::errc::result_out_of_range) {
61 const auto error = std::format(
"Invalid value '{}' for '{}': value out of range.", str, option_name);
66 const auto error = std::format(
"Invalid value '{}' for '{}': not a valid integer.", str, option_name);
81parse_optional_size_t(
const std::optional<std::string> &raw_value,
const std::string &option_name)
83 if (!raw_value.has_value()) {
87 const auto &str = raw_value.value();
89 std::size_t value = 0;
90 const auto *begin = str.data();
91 const auto *
end = str.data() + str.size();
92 auto [ptr, ec] = std::from_chars(begin,
end, value);
94 if (ec == std::errc{} && ptr ==
end) {
98 if (ec == std::errc::result_out_of_range) {
99 const auto error = std::format(
"Invalid value '{}' for '{}': value out of range.", str, option_name);
103 const auto error = std::format(
"Invalid value '{}' for '{}': not a valid integer.", str, option_name);
116LayerValue<bool> parse_bool(
const std::optional<std::string> &raw_value,
const std::string &option_name)
118 if (!raw_value.has_value()) {
122 const auto &str = raw_value.value();
127 if (str ==
"false") {
131 const auto error = std::format(
"Invalid value '{}' for '{}': expected 'true' or 'false'.", str, option_name);
144LayerValue<Rgba32> parse_rgba32(
const std::optional<std::string> &raw_value,
const std::string &option_name)
146 if (!raw_value.has_value()) {
150 const auto &input = raw_value.value();
151 std::istringstream iss{input};
153 std::vector<int> values;
155 while (std::getline(iss, token,
',')) {
158 const auto *begin = token.data();
159 const auto *
end = token.data() + token.size();
160 auto [ptr, ec] = std::from_chars(begin,
end, val);
162 if (ec != std::errc{} || ptr !=
end) {
164 std::format(
"Invalid value '{}' for '{}': '{}' is not a valid integer.", input, option_name, token);
168 if (val < 0 || val > 255) {
169 const auto error = std::format(
170 "Invalid value '{}' for '{}': component {} is out of range (must be 0-255).", input, option_name, val);
174 values.push_back(val);
177 if (values.size() == 3) {
179 static_cast<std::uint8_t
>(values[0]),
180 static_cast<std::uint8_t
>(values[1]),
181 static_cast<std::uint8_t
>(values[2]),
186 if (values.size() == 4) {
188 static_cast<std::uint8_t
>(values[0]),
189 static_cast<std::uint8_t
>(values[1]),
190 static_cast<std::uint8_t
>(values[2]),
191 static_cast<std::uint8_t
>(values[3])};
195 const auto error = std::format(
196 "Invalid value '{}' for '{}': expected R,G,B or R,G,B,A format (got {} components).",
211LayerValue<std::string> parse_string(
const std::optional<std::string> &raw_value,
const std::string &option_name)
213 if (!raw_value.has_value()) {
233parse_string_vector(
const std::vector<std::string> &raw_values,
const std::string &option_name)
235 if (raw_values.empty()) {
252parse_artifact_edit_mode(
const std::optional<std::string> &raw_value,
const std::string &option_name)
254 if (!raw_value.has_value()) {
258 const auto &str = raw_value.value();
261 if (result.has_value()) {
265 const auto error = std::format(
"Invalid value '{}' for '{}'.", str, option_name);
279parse_tiles_palette_mode(
const std::optional<std::string> &raw_value,
const std::string &option_name)
281 if (!raw_value.has_value()) {
285 const auto &str = raw_value.value();
288 if (result.has_value()) {
292 const auto error = std::format(
"Invalid value '{}' for '{}'.", str, option_name);
306parse_anim_palette_resolution_strategy(
const std::optional<std::string> &raw_value,
const std::string &option_name)
308 if (!raw_value.has_value()) {
312 const auto &str = raw_value.value();
315 if (result.has_value()) {
319 const auto error = std::format(
"Invalid value '{}' for '{}'.", str, option_name);
333parse_anim_key_frame_resolution_strategy(
const std::optional<std::string> &raw_value,
const std::string &option_name)
335 if (!raw_value.has_value()) {
339 const auto &str = raw_value.value();
342 if (result.has_value()) {
346 const auto error = std::format(
"Invalid value '{}' for '{}'.", str, option_name);
360 const std::optional<std::string> &raw_value,
const std::string &option_name)
362 if (!raw_value.has_value()) {
366 const auto &str = raw_value.value();
369 if (result.has_value()) {
373 const auto error = std::format(
"Invalid value '{}' for '{}'.", str, option_name);
387parse_frame_linking(
const std::optional<std::string> &raw_value,
const std::string &option_name)
389 if (!raw_value.has_value()) {
393 const auto &str = raw_value.value();
396 if (result.has_value()) {
400 const auto error = std::format(
"Invalid value '{}' for '{}'.", str, option_name);
414parse_tile_sharing_packing(
const std::optional<std::string> &raw_value,
const std::string &option_name)
416 if (!raw_value.has_value()) {
420 const auto &str = raw_value.value();
423 if (result.has_value()) {
427 const auto error = std::format(
"Invalid value '{}' for '{}'.", str, option_name);
441parse_tile_sharing_alignment(
const std::optional<std::string> &raw_value,
const std::string &option_name)
443 if (!raw_value.has_value()) {
447 const auto &str = raw_value.value();
450 if (result.has_value()) {
454 const auto error = std::format(
"Invalid value '{}' for '{}'.", str, option_name);
459parse_packing_strategy_type(
const std::optional<std::string> &raw_value,
const std::string &option_name)
461 if (!raw_value.has_value()) {
465 const auto &str = raw_value.value();
468 if (result.has_value()) {
472 const auto error = std::format(
"Invalid value '{}' for '{}'.", str, option_name);
477parse_primary_pairing_mode(
const std::optional<std::string> &raw_value,
const std::string &option_name)
479 if (!raw_value.has_value()) {
483 const auto &str = raw_value.value();
486 if (result.has_value()) {
490 const auto error = std::format(
"Invalid value '{}' for '{}'.", str, option_name);
Represents a 32-bit RGBA color.
std::optional< ArtifactEditMode > artifact_edit_mode_from_str(const std::string &str)
Parses a string into a ArtifactEditMode with fuzzy matching.
std::optional< PackingStrategyType > packing_strategy_type_from_str(const std::string &str)
Parses a string into a PackingStrategyType with fuzzy matching.
std::optional< FrameLinking > frame_linking_from_str(const std::string &str)
Parses a string into a FrameLinking with fuzzy matching.
std::optional< PrimaryPairingMode > primary_pairing_mode_from_str(const std::string &str)
Parses a string into a PrimaryPairingMode with fuzzy matching.
std::optional< AnimMultiPaletteSubtileResolutionStrategy > anim_multi_palette_subtile_resolution_strategy_from_str(const std::string &str)
Parses a string into a AnimMultiPaletteSubtileResolutionStrategy with fuzzy matching.
@ not_provided
nothing attribute-related was found; other providers should be consulted
@ valid
one or more usable candidate sets were inferred
@ invalid
no layout could be determined from what the project declares (fatal at resolution time)
@ error
Emit a formatted error and fail decompilation.
std::optional< TileSharingPacking > tile_sharing_packing_from_str(const std::string &str)
Parses a string into a TileSharingPacking with fuzzy matching.
std::optional< TileSharingAlignment > tile_sharing_alignment_from_str(const std::string &str)
Parses a string into a TileSharingAlignment with fuzzy matching.
std::optional< AnimPaletteResolutionStrategy > anim_palette_resolution_strategy_from_str(const std::string &str)
Parses a string into a AnimPaletteResolutionStrategy with fuzzy matching.
std::optional< TilesPaletteMode > tiles_palette_mode_from_str(const std::string &str)
Parses a string into a TilesPaletteMode with fuzzy matching.
std::optional< AnimKeyFrameResolutionStrategy > anim_key_frame_resolution_strategy_from_str(const std::string &str)
Parses a string into a AnimKeyFrameResolutionStrategy with fuzzy matching.
A small container that holds an optional-wrapped value, validation state, and metadata about the valu...
static LayerValue valid(T val, std::string source_key, std::string source_info)
Creates a LayerValue representing a valid configuration value.
static LayerValue not_provided()
Creates a LayerValue representing that the provider does not supply this configuration.
static LayerValue invalid(std::string error, std::string source_info)
Creates a LayerValue representing an invalid configuration value.