Porytiles
Loading...
Searching...
No Matches
base_game.hpp
Go to the documentation of this file.
1#pragma once
2
3#include <format>
4#include <optional>
5#include <ostream>
6#include <string>
7
9
10namespace porytiles {
11
21
28[[nodiscard]] inline std::optional<BaseGame> base_game_from_str(const std::string &s)
29{
30 if (s == "pokeemerald") {
32 }
33 if (s == "pokefirered") {
35 }
36 if (s == "pokeruby") {
37 return BaseGame::pokeruby;
38 }
39 if (s == "pokeemerald-expansion") {
41 }
42 return std::nullopt;
43}
44
51[[nodiscard]] inline std::string to_string(BaseGame game)
52{
53 switch (game) {
55 return "pokeemerald";
57 return "pokefirered";
59 return "pokeruby";
61 return "pokeemerald-expansion";
62 }
63 panic("unhandled BaseGame value");
64}
65
73inline std::ostream &operator<<(std::ostream &os, const BaseGame game)
74{
75 return os << to_string(game);
76}
77
78} // namespace porytiles
79
80template <>
81struct std::formatter<porytiles::BaseGame> {
82 constexpr auto parse(std::format_parse_context &ctx)
83 {
84 return ctx.begin();
85 }
86
87 auto format(const porytiles::BaseGame &value, auto &ctx) const
88 {
89 return std::format_to(ctx.out(), "{}", porytiles::to_string(value));
90 }
91};
std::optional< BaseGame > base_game_from_str(const std::string &s)
Converts a string to BaseGame.
Definition base_game.hpp:28
BaseGame
Identifies the target base game for a decompilation project.
Definition base_game.hpp:20
void panic(const StringViewSourceLoc &s)
Unconditionally terminates the program with a panic message.
Definition panic.cpp:43
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::BaseGame &value, auto &ctx) const
Definition base_game.hpp:87
constexpr auto parse(std::format_parse_context &ctx)
Definition base_game.hpp:82