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>
23 if (std::ranges::any_of(
25 [](
char c) {
return std::isspace(
static_cast<unsigned char>(c)); }))
28 "Whitespace is not allowed in ranges. Use 'start:end' without "
29 "spaces around the colon.");
40 "Invalid range '{}:{}'. The end must be greater than or equal "
44 return ranges::views::iota(start, end + 1);
49 auto const material_ids_strings =
53 std::vector<int> material_ids;
54 material_ids.reserve(material_ids_strings.size());
56 for (std::string mid_str : material_ids_strings)
63 if (parts.size() == 2)
69 OGS_FATAL(
"Could not parse material ID: {}", start_id.error());
75 OGS_FATAL(
"Could not parse material ID: {}", end_id.error());
78 std::back_inserter(material_ids));
80 else if (parts.size() == 1)
85 OGS_FATAL(
"Could not parse material ID: {}",
88 material_ids.push_back(*material_id);
93 "Could not parse material ID from '{}'. Invalid range format. "
94 "Use 'start:end' for ranges or a single integer.",
103 std::string
const& material_id_string,
106 if (material_id_string ==
"*")
108 if (material_ids ==
nullptr)
111 "MaterialIDs property is not defined in the mesh but it is "
112 "required to parse '*' definition.");
115 std::vector<int>
const material_ids_of_this_medium =
116 *material_ids | ranges::views::unique | ranges::to_vector |
117 ranges::actions::sort | ranges::actions::unique |
118 ranges::to<std::vector>;
119 DBUG(
"Catch all medium definition for material ids {}.",
120 fmt::join(material_ids_of_this_medium,
", "));
121 return material_ids_of_this_medium;
void DBUG(fmt::format_string< Args... > fmt, Args &&... args)
std::expected< int, std::string > parseInteger(std::string_view str)
void trim(std::string &str, char ch)
std::vector< std::string > splitString(std::string const &str)
void checkForWhitespaces(std::string_view part)
auto expandRange(int start, int end)
std::vector< int > splitMaterialIdString(std::string const &material_id_string)
std::vector< int > parseMaterialIdString(std::string const &material_id_string, MeshLib::PropertyVector< int > const *const material_ids)