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
25
29 [[nodiscard]] bool has_any() const
30 {
33 }
34};
35
45
49 [[nodiscard]] bool has_any() const
50 {
52 }
53};
54
64};
65
70[[nodiscard]] inline std::string to_string(const PackingStrategyParams &params)
71{
72 std::string result = "{backtracking={";
73 if (params.backtracking.has_any()) {
74 bool first = true;
76 result += "search_algorithm=" + to_string(*params.backtracking.search_algorithm);
77 first = false;
78 }
79 if (params.backtracking.node_cutoff.has_value()) {
80 if (!first) {
81 result += ", ";
82 }
83 result += "node_cutoff=" + std::to_string(*params.backtracking.node_cutoff);
84 first = false;
85 }
87 if (!first) {
88 result += ", ";
89 }
90 result += "best_branches=" + std::to_string(*params.backtracking.best_branches);
91 first = false;
92 }
93 if (params.backtracking.smart_prune.has_value()) {
94 if (!first) {
95 result += ", ";
96 }
97 result += "smart_prune=";
98 result += (*params.backtracking.smart_prune ? "true" : "false");
99 }
100 }
101 result += "}, overload_and_remove={";
102 if (params.overload_and_remove.has_any()) {
103 bool first = true;
105 result += "max_attempts=" + std::to_string(*params.overload_and_remove.max_attempts);
106 first = false;
107 }
108 if (params.overload_and_remove.seed.has_value()) {
109 if (!first) {
110 result += ", ";
111 }
112 result += "seed=" + std::to_string(*params.overload_and_remove.seed);
113 first = false;
114 }
116 if (!first) {
117 result += ", ";
118 }
119 result += "shuffle_strategy=" + to_string(*params.overload_and_remove.shuffle_strategy);
120 }
121 }
122 result += "}}";
123 return result;
124}
125
131inline std::ostream &operator<<(std::ostream &os, const PackingStrategyParams &params)
132{
133 return os << to_string(params);
134}
135
136} // namespace porytiles
137
138template <>
139struct std::formatter<porytiles::PackingStrategyParams> {
140 constexpr auto parse(std::format_parse_context &ctx)
141 {
142 return ctx.begin();
143 }
144
145 auto format(const porytiles::PackingStrategyParams &value, auto &ctx) const
146 {
147 return std::format_to(ctx.out(), "{}", porytiles::to_string(value));
148 }
149};
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)