Wildmeshing Toolkit
local_switch_tuple.hpp
Go to the documentation of this file.
1 #pragma once
2 #include <wmtk/Primitive.hpp>
3 #include <wmtk/Tuple.hpp>
4 #if defined(__cpp_concepts) && defined(__cpp_lib_ranges)
5 #include <ranges>
6 #endif
7 
8 namespace wmtk::multimesh::utils {
9 
10 // Maps the tuple source according to the operation sequence
11 // std::vector<PrimitiveType> operations where operations satisfies
12 // base_target = switch_tuples(base_source, operations)
13 Tuple local_switch_tuple(
14  PrimitiveType mesh_primitive_type,
15  const Tuple& source,
16  PrimitiveType primitive_type);
17 
18 
19 // Performs a sequence of switch_tuple operations in the order specified in sequence.
20 // in debug mode this will assert a failure, in release this will return a null tuple
21 #if defined(__cpp_concepts) && defined(__cpp_lib_ranges)
22  template <std::ranges::forward_range ContainerType>
23 #else
24 template <typename ContainerType>
25 #endif
27  PrimitiveType mesh_primitive_type,
28  const Tuple& tuple,
29  const ContainerType& sequence);
30 // annoying initializer list prototype to catch switch_tuples(t, {PV,PE})
32  PrimitiveType mesh_primitive_type,
33  const Tuple& tuple,
34  const std::initializer_list<PrimitiveType>& sequence);
35 
36 
37 // IMPLEMENTATION of above declaration
38 #if defined(__cpp_concepts) && defined(__cpp_lib_ranges)
39  template <std::ranges::forward_range ContainerType>
40 #else
41 template <typename ContainerType>
42 #endif
44  PrimitiveType mesh_primitive_type,
45  const Tuple& tuple,
46  const ContainerType& sequence)
47 {
48  static_assert(std::is_same_v<typename ContainerType::value_type, PrimitiveType>);
49  Tuple r = tuple;
50  for (const PrimitiveType primitive : sequence) {
51  r = local_switch_tuple(mesh_primitive_type, r, primitive);
52  }
53  return r;
54 }
55 
56 } // namespace wmtk::multimesh::utils
Tuple local_switch_tuples(PrimitiveType mesh_primitive_type, const Tuple &tuple, const std::initializer_list< PrimitiveType > &op_sequence)
Tuple local_switch_tuple(PrimitiveType mesh_primitive_type, const Tuple &source, PrimitiveType primitive_type)