OGS
MediaCreation.h
Go to the documentation of this file.
1
10#include <map>
11#include <memory>
12#include <string>
13#include <vector>
14
15#include "BaseLib/Error.h"
16
17namespace MeshLib
18{
19template <typename PROP_VAL_TYPE>
20class PropertyVector;
21} // namespace MeshLib
22
23namespace MaterialLib
24{
25
29std::vector<int> splitMaterialIdString(std::string const& material_id_string);
30
35std::vector<int> parseMaterialIdString(
36 std::string const& material_id_string,
37 MeshLib::PropertyVector<int> const* const material_ids);
38
42template <typename T, typename CreateMedium>
43 requires std::convertible_to<
44 decltype(std::declval<CreateMedium>()(std::declval<int>())),
45 std::shared_ptr<T>>
46void createMediumForId(int const id,
47 std::map<int, std::shared_ptr<T>>& media,
48 std::vector<int> const& material_ids_of_this_medium,
49 CreateMedium&& create_medium)
50{
51 if (media.find(id) != end(media))
52 {
54 "Multiple media were specified for the same material id '{:d}'. "
55 "Keep in mind, that if no material id is specified, it is assumed "
56 "to be 0 by default.",
57 id);
58 }
59
60 if (id == material_ids_of_this_medium[0])
61 {
62 media[id] = create_medium(id);
63 }
64 else
65 {
66 media[id] = media[material_ids_of_this_medium[0]];
67 }
68}
69
70} // namespace MaterialLib
#define OGS_FATAL(...)
Definition Error.h:26
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)