|
13 | 13 | #include "mex.h"
|
14 | 14 | #include "datatypes.h"
|
15 | 15 |
|
| 16 | +// filter function templates |
16 | 17 | template<typename T, typename FN>
|
17 | 18 | std::vector<T> filterFullEntity(const extractor &input, FN ff) {
|
18 | 19 | std::vector<T> res;
|
@@ -118,4 +119,67 @@ std::vector<T> filterEntity(const extractor &input, FN ff) {
|
118 | 119 | return res;
|
119 | 120 | }
|
120 | 121 |
|
| 122 | +// find filter function templates |
| 123 | +template<typename T, typename FN> |
| 124 | +std::vector<T> filterFullEntity(const extractor &input, |
| 125 | + uint8_t filter_id, size_t val_pos, size_t max_depth, FN ff) { |
| 126 | + std::vector<T> res; |
| 127 | + |
| 128 | + switch (filter_id) { |
| 129 | + case switchFilter::AcceptAll: |
| 130 | + res = ff(nix::util::AcceptAll<T>(), max_depth); |
| 131 | + break; |
| 132 | + case switchFilter::Id: |
| 133 | + res = ff(nix::util::IdFilter<T>(input.str(val_pos)), max_depth); |
| 134 | + break; |
| 135 | + case switchFilter::Ids: |
| 136 | + // this will crash matlab, if its not a vector of strings... |
| 137 | + res = ff(nix::util::IdsFilter<T>(input.vec<std::string>(val_pos)), max_depth); |
| 138 | + break; |
| 139 | + case switchFilter::Type: |
| 140 | + res = ff(nix::util::TypeFilter<T>(input.str(val_pos)), max_depth); |
| 141 | + break; |
| 142 | + case switchFilter::Name: |
| 143 | + res = ff(nix::util::NameFilter<T>(input.str(val_pos)), max_depth); |
| 144 | + break; |
| 145 | + case switchFilter::Metadata: |
| 146 | + res = ff(nix::util::MetadataFilter<T>(input.str(val_pos)), max_depth); |
| 147 | + break; |
| 148 | + case switchFilter::Source: |
| 149 | + res = ff(nix::util::SourceFilter<T>(input.str(val_pos)), max_depth); |
| 150 | + break; |
| 151 | + default: throw std::invalid_argument("unknown or unsupported filter"); |
| 152 | + } |
| 153 | + |
| 154 | + return res; |
| 155 | +} |
| 156 | + |
| 157 | +template<typename T, typename FN> |
| 158 | +std::vector<T> filterNameTypeEntity(const extractor &input, |
| 159 | + uint8_t filter_id, size_t val_pos, size_t max_depth, FN ff) { |
| 160 | + std::vector<T> res; |
| 161 | + |
| 162 | + switch (filter_id) { |
| 163 | + case switchFilter::AcceptAll: |
| 164 | + res = ff(nix::util::AcceptAll<T>(), max_depth); |
| 165 | + break; |
| 166 | + case switchFilter::Id: |
| 167 | + res = ff(nix::util::IdFilter<T>(input.str(val_pos)), max_depth); |
| 168 | + break; |
| 169 | + case switchFilter::Ids: |
| 170 | + // this will crash matlab, if its not a vector of strings... |
| 171 | + res = ff(nix::util::IdsFilter<T>(input.vec<std::string>(val_pos)), max_depth); |
| 172 | + break; |
| 173 | + case switchFilter::Type: |
| 174 | + res = ff(nix::util::TypeFilter<T>(input.str(val_pos)), max_depth); |
| 175 | + break; |
| 176 | + case switchFilter::Name: |
| 177 | + res = ff(nix::util::NameFilter<T>(input.str(val_pos)), max_depth); |
| 178 | + break; |
| 179 | + default: throw std::invalid_argument("unknown or unsupported filter"); |
| 180 | + } |
| 181 | + |
| 182 | + return res; |
| 183 | +} |
| 184 | + |
121 | 185 | #endif
|
0 commit comments