Skip to content

Commit 8b42758

Browse files
committed
[c++] Add Feature filter template
1 parent 2824f7d commit 8b42758

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

src/filters.h

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,4 +74,25 @@ std::vector<T> filterEntity(const extractor &input, FN ff) {
7474
return res;
7575
}
7676

77+
template<typename T, typename FN>
78+
std::vector<T> filterFeature(const extractor &input, FN ff) {
79+
std::vector<T> res;
80+
81+
switch (input.num<uint8_t>(2)) {
82+
case switchFilter::AcceptAll:
83+
res = ff(nix::util::AcceptAll<T>());
84+
break;
85+
case switchFilter::Id:
86+
res = ff(nix::util::IdFilter<T>(input.str(3)));
87+
break;
88+
case switchFilter::Ids:
89+
// this will crash matlab, if its not a vector of strings...
90+
res = ff(nix::util::IdsFilter<T>(input.vec<std::string>(3)));
91+
break;
92+
default: throw std::invalid_argument("unknown or unsupported filter");
93+
}
94+
95+
return res;
96+
}
97+
7798
#endif

0 commit comments

Comments
 (0)