Blender V5.3
BKE_attribute_filters.hh
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2023 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
8
9#pragma once
10
12
13#include "BLI_set.hh"
14
15namespace blender::bke {
16
20template<typename Fn> struct AttributeFilterFromFunc : public AttributeFilter {
21 private:
22 Fn fn_;
23
24 static_assert(std::is_invocable_r_v<Result, Fn, StringRef>);
25
26 public:
27 constexpr AttributeFilterFromFunc(Fn fn) : fn_(std::move(fn)) {}
28
29 Result filter(const StringRef name) const override
30 {
31 return fn_(name);
32 }
33};
34
40 const Span<StringRef> skip)
41{
42 return AttributeFilterFromFunc([&filter, skip](const StringRef name) {
43 if (skip.contains(name)) {
45 }
46 return filter.filter(name);
47 });
48}
49
51template<typename StringT>
53{
54 return AttributeFilterFromFunc([&filter, &skip](const StringRef name) {
55 if (skip.contains_as(name)) {
57 }
58 return filter.filter(name);
59 });
60}
61
67{
68 return AttributeFilterFromFunc([skip](const StringRef name) {
69 if (skip.contains(name)) {
71 }
73 });
74}
75
77template<typename StringT> inline auto attribute_filter_from_skip_ref(const Set<StringT> &skip)
78{
79 return AttributeFilterFromFunc([&skip](const StringRef name) {
80 if (skip.contains_as(name)) {
82 }
84 });
85}
86
87} // namespace blender::bke
bool contains_as(const ForwardKey &key) const
Definition BLI_set.hh:314
constexpr bool contains(const T &value) const
Definition BLI_span.hh:281
auto attribute_filter_with_skip_ref(const AttributeFilter &filter, const Span< StringRef > skip)
auto attribute_filter_from_skip_ref(const Span< StringRef > skip)
Result filter(const StringRef name) const override