4#include <spdlog/fmt/ranges.h>
6#include <range/v3/action/sort.hpp>
7#include <range/v3/action/unique.hpp>
8#include <range/v3/range/conversion.hpp>
9#include <range/v3/view/iota.hpp>
10#include <range/v3/view/unique.hpp>
24 if (std::ranges::any_of(
26 [](
char c) {
return std::isspace(
static_cast<unsigned char>(c)); }))
29 "Whitespace is not allowed in ranges. Use 'start:end' without "
30 "spaces around the colon.");
41 "Invalid range '{}:{}'. The end must be greater than or equal "
45 return ranges::views::iota(start, end + 1);
54 "Invalid separator ':'. Character ':' is reserved for range "
57 auto const material_ids_strings =
61 std::vector<int> material_ids;
62 material_ids.reserve(material_ids_strings.size());
64 for (std::string mid_str : material_ids_strings)
71 if (parts.size() == 2)
77 OGS_FATAL(
"Could not parse material ID: {}", start_id.error());
83 OGS_FATAL(
"Could not parse material ID: {}", end_id.error());
86 std::back_inserter(material_ids));
88 else if (parts.size() == 1)
93 OGS_FATAL(
"Could not parse material ID: {}",
96 material_ids.push_back(*material_id);
101 "Could not parse material ID from '{}'. Invalid range format. "
102 "Use 'start:end' for ranges or a single integer.",
111 std::string
const& material_id_string,
113 char const separator,
bool const validate)
115 if (material_id_string ==
"*")
117 if (material_ids ==
nullptr)
120 "MaterialIDs property is not defined in the mesh but it is "
121 "required to parse '*' definition.");
124 std::vector<int>
const material_ids_of_this_medium =
125 *material_ids | ranges::views::unique | ranges::to_vector |
126 ranges::actions::sort | ranges::actions::unique |
127 ranges::to<std::vector>;
128 DBUG(
"Catch all medium definition for material ids {}.",
129 fmt::join(material_ids_of_this_medium,
", "));
130 return material_ids_of_this_medium;
134 auto const parsed_ids =
137 if (material_ids ==
nullptr || !validate)
143 std::set<int>
const valid_material_ids(material_ids->
begin(),
144 material_ids->
end());
146 for (
int id : parsed_ids)
148 if (valid_material_ids.find(
id) == valid_material_ids.end())
151 "Material ID {} specified in material_id_string '{}' does "
152 "not exist in the mesh. Available material IDs are: {}.",
153 id, material_id_string, fmt::join(valid_material_ids,
", "));
void DBUG(fmt::format_string< Args... > fmt, Args &&... args)
constexpr PROP_VAL_TYPE * begin()
constexpr PROP_VAL_TYPE * end()
void trim(std::string &str, char ch)
std::expected< int, std::string > parseInteger(std::string_view const str)
std::vector< std::string > splitString(std::string const &str)
std::vector< int > parseMaterialIdString(std::string const &material_id_string, MeshLib::PropertyVector< int > const *const material_ids, char const separator, bool const validate)
auto expandRange(int const start, int const end)
std::vector< int > splitMaterialIdString(std::string const &material_id_string, char const separator)
void checkForWhitespaces(std::string_view const part)