Porytiles
Loading...
Searching...
No Matches
primary_pairing_mode.hpp
Go to the documentation of this file.
1#pragma once
2
3#include <algorithm>
4#include <cctype>
5#include <format>
6#include <optional>
7#include <ostream>
8#include <string>
9
11
12// NOTE: DO NOT EDIT THIS FILE DIRECTLY. It is AUTO-GENERATED from config_schema.yaml.
13// To add new config values or make other changes, edit config_schema.yaml and regenerate via:
14//
15// uv run scripts/generate_config.py
16
17namespace porytiles {
18
28 off,
30 manual,
33};
34
48[[nodiscard]] inline std::optional<PrimaryPairingMode> primary_pairing_mode_from_str(const std::string &str)
49{
50 // Phase 1: Exact match against C++ constant names
51 if (str == "off") {
52 return std::optional{PrimaryPairingMode::off};
53 }
54 if (str == "manual") {
55 return std::optional{PrimaryPairingMode::manual};
56 }
57 if (str == "automatic") {
58 return std::optional{PrimaryPairingMode::automatic};
59 }
60
61 // Phase 2: Case-insensitive fuzzy match
62 std::string lower_str = str;
63 std::ranges::transform(
64 lower_str, lower_str.begin(), [](unsigned char c) { return static_cast<char>(std::tolower(c)); });
65
66 // Fuzzy names for off
67 if (lower_str == "off") {
68 return std::optional{PrimaryPairingMode::off};
69 }
70 if (lower_str == "none") {
71 return std::optional{PrimaryPairingMode::off};
72 }
73 if (lower_str == "disabled") {
74 return std::optional{PrimaryPairingMode::off};
75 }
76 // Fuzzy names for manual
77 if (lower_str == "manual") {
78 return std::optional{PrimaryPairingMode::manual};
79 }
80 // Fuzzy names for automatic
81 if (lower_str == "automatic") {
82 return std::optional{PrimaryPairingMode::automatic};
83 }
84 if (lower_str == "auto") {
85 return std::optional{PrimaryPairingMode::automatic};
86 }
87
88 return std::nullopt;
89}
90
99[[nodiscard]] inline std::string to_string(const PrimaryPairingMode m)
100{
101 switch (m) {
103 return "off";
105 return "manual";
107 return "automatic";
108 }
109 panic("unhandled PrimaryPairingMode value");
110}
111
117inline std::ostream &operator<<(std::ostream &os, const PrimaryPairingMode m)
118{
119 return os << to_string(m);
120}
121
122} // namespace porytiles
123
124template <>
125struct std::formatter<porytiles::PrimaryPairingMode> {
126 constexpr auto parse(std::format_parse_context &ctx)
127 {
128 return ctx.begin();
129 }
130
131 auto format(const porytiles::PrimaryPairingMode &value, auto &ctx) const
132 {
133 return std::format_to(ctx.out(), "{}", porytiles::to_string(value));
134 }
135};
PrimaryPairingMode
Controls how a secondary tileset finds its partner primary for compilation.
@ automatic
Scan layout metadata to find the partner primary automatically.
@ off
Skip primary loading entirely. Compile as a standalone secondary.
@ manual
Use the partner primary specified via primary_pairing_partners config.
void panic(const StringViewSourceLoc &s)
Unconditionally terminates the program with a panic message.
Definition panic.cpp:43
std::optional< PrimaryPairingMode > primary_pairing_mode_from_str(const std::string &str)
Parses a string into a PrimaryPairingMode with fuzzy matching.
std::ostream & operator<<(std::ostream &os, const PrimaryPairingMode m)
Stream insertion operator for PrimaryPairingMode.
std::string to_string(const PrimaryPairingMode m)
Converts a PrimaryPairingMode to its canonical string representation.
auto format(const porytiles::PrimaryPairingMode &value, auto &ctx) const
constexpr auto parse(std::format_parse_context &ctx)