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
23std::vector<int> splitMaterialIdString(std::string const& material_id_string);
24
29std::vector<int> parseMaterialIdString(
30 std::string const& material_id_string,
31 MeshLib::PropertyVector<int> const* const material_ids);
32
36template <typename T, typename CreateMedium>
37 requires std::convertible_to<
38 decltype(std::declval<CreateMedium>()(std::declval<int>())),
39 std::shared_ptr<T>>
40void createMediumForId(int const id,
41 std::map<int, std::shared_ptr<T>>& media,
42 std::vector<int> const& material_ids_of_this_medium,
43 CreateMedium&& create_medium)
44{
45 if (media.find(id) != end(media))
46 {
48 "Multiple media were specified for the same material id '{:d}'. "
49 "Keep in mind, that if no material id is specified, it is assumed "
50 "to be 0 by default.",
51 id);
52 }
53
54 if (id == material_ids_of_this_medium[0])
55 {
56 media[id] = create_medium(id);
57 }
58 else
59 {
60 media[id] = media[material_ids_of_this_medium[0]];
61 }
62}
63
64} // 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)