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
33std::vector<int> parseMaterialIdString(
34 std::string const& material_id_string,
35 MeshLib::PropertyVector<int> const* const material_ids);
36
40template <typename T, typename CreateMedium>
41 requires std::convertible_to<
42 decltype(std::declval<CreateMedium>()(std::declval<int>())),
43 std::shared_ptr<T>>
44void createMediumForId(int const id,
45 std::map<int, std::shared_ptr<T>>& media,
46 std::vector<int> const& material_ids_of_this_medium,
47 CreateMedium&& create_medium)
48{
49 if (media.find(id) != end(media))
50 {
52 "Multiple media were specified for the same material id '{:d}'. "
53 "Keep in mind, that if no material id is specified, it is assumed "
54 "to be 0 by default.",
55 id);
56 }
57
58 if (id == material_ids_of_this_medium[0])
59 {
60 media[id] = create_medium(id);
61 }
62 else
63 {
64 media[id] = media[material_ids_of_this_medium[0]];
65 }
66}
67
68} // namespace MaterialLib
#define OGS_FATAL(...)
Definition Error.h:19
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)
std::vector< int > parseMaterialIdString(std::string const &material_id_string, MeshLib::PropertyVector< int > const *const material_ids)