Porytiles
Loading...
Searching...
No Matches
packing_strategy_params.hpp
Go to the documentation of this file.
1#pragma once
2
3#include <cstddef>
4#include <cstdint>
5#include <format>
6#include <ostream>
7#include <string>
8
12
13namespace porytiles {
14
27
33 [[nodiscard]] bool has_any() const
34 {
37 }
38};
39
51
57 [[nodiscard]] bool has_any() const
58 {
60 }
61};
62
74};
75
82[[nodiscard]] inline std::string to_string(const PackingStrategyParams &params)
83{
84 std::string result = "{backtracking={";
85 if (params.backtracking.has_any()) {
86 bool first = true;
88 result += "search_algorithm=" + to_string(*params.backtracking.search_algorithm);
89 first = false;
90 }
91 if (params.backtracking.node_cutoff.has_value()) {
92 if (!first) {
93 result += ", ";
94 }
95 result += "node_cutoff=" + std::to_string(*params.backtracking.node_cutoff);
96 first = false;
97 }
99 if (!first) {
100 result += ", ";
101 }
102 result += "best_branches=" + std::to_string(*params.backtracking.best_branches);
103 first = false;
104 }
105 if (params.backtracking.smart_prune.has_value()) {
106 if (!first) {
107 result += ", ";
108 }
109 result += "smart_prune=";
110 result += (*params.backtracking.smart_prune ? "true" : "false");
111 }
112 }
113 result += "}, overload_and_remove={";
114 if (params.overload_and_remove.has_any()) {
115 bool first = true;
117 result += "max_attempts=" + std::to_string(*params.overload_and_remove.max_attempts);
118 first = false;
119 }
120 if (params.overload_and_remove.seed.has_value()) {
121 if (!first) {
122 result += ", ";
123 }
124 result += "seed=" + std::to_string(*params.overload_and_remove.seed);
125 first = false;
126 }
128 if (!first) {
129 result += ", ";
130 }
131 result += "shuffle_strategy=" + to_string(*params.overload_and_remove.shuffle_strategy);
132 }
133 }
134 result += "}}";
135 return result;
136}
137
145inline std::ostream &operator<<(std::ostream &os, const PackingStrategyParams &params)
146{
147 return os << to_string(params);
148}
149
150} // namespace porytiles
151
152template <>
153struct std::formatter<porytiles::PackingStrategyParams> {
154 constexpr auto parse(std::format_parse_context &ctx)
155 {
156 return ctx.begin();
157 }
158
159 auto format(const porytiles::PackingStrategyParams &value, auto &ctx) const
160 {
161 return std::format_to(ctx.out(), "{}", porytiles::to_string(value));
162 }
163};
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.
Per-strategy parameters for the BacktrackingStrategy packing algorithm.
ConfigPODField< std::size_t > best_branches
ConfigPODField< std::size_t > node_cutoff
ConfigPODField< SearchAlgorithm > search_algorithm
bool has_any() const
Checks whether any parameter has been explicitly set.
A lightweight wrapper for per-field configuration values with source metadata.
bool has_value() const
Checks whether this field has a value set.
Per-strategy parameters for the OverloadAndRemoveStrategy packing algorithm.
ConfigPODField< ShuffleStrategy > shuffle_strategy
bool has_any() const
Checks whether any parameter has been explicitly set.
ConfigPODField< std::uint64_t > seed
ConfigPODField< std::size_t > max_attempts
Container for per-strategy packing parameters.
auto format(const porytiles::PackingStrategyParams &value, auto &ctx) const
constexpr auto parse(std::format_parse_context &ctx)