OGS
MediaCreation.h
Go to the documentation of this file.
1// SPDX-FileCopyrightText: Copyright (c) OpenGeoSys Community (opengeosys.org)
2// SPDX-License-Identifier: BSD-3-Clause
3
4#include <map>
5#include <memory>
6#include <string>
7#include <vector>
8
9#include "BaseLib/Error.h"
10
11namespace MeshLib
12{
13template <typename PROP_VAL_TYPE>
14class PropertyVector;
15} // namespace MeshLib
16
17namespace MaterialLib
18{
19
26std::vector<int> splitMaterialIdString(std::string const& material_id_string,
27 char const separator = ',');
28
39std::vector<int> parseMaterialIdString(
40 std::string const& material_id_string,
41 MeshLib::PropertyVector<int> const* const material_ids,
42 char const separator = ',', bool const validate = false);
43
47template <typename T, typename CreateMedium>
48 requires std::convertible_to<
49 decltype(std::declval<CreateMedium>()(std::declval<int>())),
50 std::shared_ptr<T>>
51void createMediumForId(int const id,
52 std::map<int, std::shared_ptr<T>>& media,
53 std::vector<int> const& material_ids_of_this_medium,
54 CreateMedium&& create_medium)
55{
56 if (media.find(id) != end(media))
57 {
59 "Multiple media were specified for the same material id '{:d}'. "
60 "Keep in mind, that if no material id is specified, it is assumed "
61 "to be 0 by default.",
62 id);
63 }
64
65 if (id == material_ids_of_this_medium[0])
66 {
67 media[id] = create_medium(id);
68 }
69 else
70 {
71 media[id] = media[material_ids_of_this_medium[0]];
72 }
73}
74
75} // namespace MaterialLib
#define OGS_FATAL(...)
Definition Error.h:10
std::vector< int > parseMaterialIdString(std::string const &material_id_string, MeshLib::PropertyVector< int > const *const material_ids, char const separator, bool const validate)
void createMediumForId(int const id, std::map< int, std::shared_ptr< T > > &media, std::vector< int > const &material_ids_of_this_medium, CreateMedium &&create_medium)
std::vector< int > splitMaterialIdString(std::string const &material_id_string, char const separator)