Porytiles
Loading...
Searching...
No Matches
role_pin_definition.hpp
Go to the documentation of this file.
1#pragma once
2
3#include <format>
4#include <ostream>
5#include <string>
6#include <vector>
7
9
10namespace porytiles {
11
22
23 bool operator==(const RolePinDefinition &) const = default;
24};
25
27using RolePinDefinitions = std::vector<RolePinDefinition>;
28
34[[nodiscard]] inline const RolePinDefinition *find_role_pin(const RolePinDefinitions &definitions, FieldRole role)
35{
36 for (const auto &definition : definitions) {
37 if (definition.role == role) {
38 return &definition;
39 }
40 }
41 return nullptr;
42}
43
45[[nodiscard]] inline std::string to_string(const RolePinDefinition &definition)
46{
47 return std::format("{{role={}}}", to_string(definition.role));
48}
49
51[[nodiscard]] inline std::string to_string(const RolePinDefinitions &definitions)
52{
53 if (definitions.empty()) {
54 return "[]";
55 }
56 std::string result = "[";
57 bool first = true;
58 for (const auto &definition : definitions) {
59 if (!first) {
60 result += ", ";
61 }
62 result += to_string(definition);
63 first = false;
64 }
65 result += "]";
66 return result;
67}
68
69inline std::ostream &operator<<(std::ostream &os, const RolePinDefinitions &definitions)
70{
71 return os << to_string(definitions);
72}
73
74} // namespace porytiles
75
76template <>
77struct std::formatter<porytiles::RolePinDefinitions> {
78 constexpr auto parse(std::format_parse_context &ctx)
79 {
80 return ctx.begin();
81 }
82
83 auto format(const porytiles::RolePinDefinitions &value, auto &ctx) const
84 {
85 return std::format_to(ctx.out(), "{}", porytiles::to_string(value));
86 }
87};
const RolePinDefinition * find_role_pin(const RolePinDefinitions &definitions, FieldRole role)
Finds the role pin definition for a given role, or nullptr when the role is not pinned.
std::vector< RolePinDefinition > RolePinDefinitions
An ordered list of role pin definitions; order is display/declaration order (also CSV column order).
std::ostream & operator<<(std::ostream &os, const PrimaryPairingMode m)
Stream insertion operator for PrimaryPairingMode.
FieldRole
Semantic roles a schema field can carry beyond holding a plain per-metatile value.
std::string to_string(const PrimaryPairingMode m)
Converts a PrimaryPairingMode to its canonical string representation.
A user request to emit a trailing pin column for one schema role in attributes.csv.
bool operator==(const RolePinDefinition &) const =default
auto format(const porytiles::RolePinDefinitions &value, auto &ctx) const
constexpr auto parse(std::format_parse_context &ctx)