ORIGINAL
Loading...
Searching...
No Matches
filter.h
Go to the documentation of this file.
1#ifndef FILTER_H
2#define FILTER_H
3#include "cloneable.h"
4
19
20namespace original {
21
30 template<typename TYPE>
31 class filter : public cloneable {
32 protected:
38 virtual bool match(const TYPE& t) const;
39
40 public:
44 ~filter() override = default;
45
50 filter* clone() const override;
51
57 bool operator()(const TYPE& t) const;
58 };
59
67 template<typename TYPE>
68 class equalFilter final : public filter<TYPE> {
69 TYPE target;
70
76 bool match(const TYPE& t) const override;
77
78 public:
83 explicit equalFilter(const TYPE& target);
84
89 equalFilter* clone() const override;
90 };
91
99 template<typename TYPE>
100 class notEqualFilter final : public filter<TYPE> {
101 TYPE target;
102
108 bool match(const TYPE& t) const override;
109
110 public:
115 explicit notEqualFilter(const TYPE& target);
116
121 notEqualFilter* clone() const override;
122 };
123
131 template<typename TYPE>
132 class lessFilter final : public filter<TYPE> {
133 TYPE low;
134
140 bool match(const TYPE& t) const override;
141
142 public:
147 explicit lessFilter(const TYPE& low);
148
153 lessFilter* clone() const override;
154 };
155
163 template<typename TYPE>
164 class greaterFilter final : public filter<TYPE> {
165 TYPE high;
166
172 bool match(const TYPE& t) const override;
173
174 public:
179 explicit greaterFilter(const TYPE& high);
180
185 greaterFilter* clone() const override;
186 };
187
195 template<typename TYPE>
196 class notLessFilter final : public filter<TYPE> {
197 TYPE high;
198
204 bool match(const TYPE& t) const override;
205
206 public:
211 explicit notLessFilter(const TYPE& high);
212
217 notLessFilter* clone() const override;
218 };
219
227 template<typename TYPE>
228 class notGreaterFilter final : public filter<TYPE> {
229 TYPE low;
230
236 bool match(const TYPE& t) const override;
237
238 public:
243 explicit notGreaterFilter(const TYPE& low);
244
249 notGreaterFilter* clone() const override;
250 };
251
259 template<typename TYPE>
260 class rangeFilter final : public filter<TYPE> {
261 TYPE low;
262 TYPE high;
263
269 bool match(const TYPE& t) const override;
270
271 public:
277 explicit rangeFilter(const TYPE& low, const TYPE& high);
278
283 rangeFilter* clone() const override;
284 };
285
286} // namespace original
287
288 template<typename TYPE>
289 bool original::filter<TYPE>::match(const TYPE&) const {
290 return true;
291 }
292
293 template <typename TYPE>
295 {
296 return new filter(*this);
297 }
298
299 template<typename TYPE>
300 bool original::filter<TYPE>::operator()(const TYPE& t) const {
301 return this->match(t);
302 }
303
304 template<typename TYPE>
305 bool original::equalFilter<TYPE>::match(const TYPE& t) const {
306 return t == target;
307 }
308
309 template<typename TYPE>
311 : target(target) {}
312
313 template <typename TYPE>
315 {
316 return new equalFilter(*this);
317 }
318
319 template<typename TYPE>
320 bool original::notEqualFilter<TYPE>::match(const TYPE& t) const {
321 return t != target;
322 }
323
324 template<typename TYPE>
326 : target(target) {}
327
328 template <typename TYPE>
330 {
331 return new notEqualFilter(*this);
332 }
333
334 template<typename TYPE>
335 bool original::lessFilter<TYPE>::match(const TYPE& t) const {
336 return t < low;
337 }
338
339 template<typename TYPE>
341 : low(low) {}
342
343 template <typename TYPE>
345 {
346 return new lessFilter(*this);
347 }
348
349 template<typename TYPE>
350 bool original::greaterFilter<TYPE>::match(const TYPE& t) const {
351 return t > high;
352 }
353
354 template<typename TYPE>
356 : high(high) {}
357
358 template <typename TYPE>
360 {
361 return new greaterFilter(*this);
362 }
363
364 template<typename TYPE>
365 bool original::notLessFilter<TYPE>::match(const TYPE& t) const {
366 return t >= high;
367 }
368
369 template<typename TYPE>
371 : high(high) {}
372
373 template <typename TYPE>
375 {
376 return new notLessFilter(*this);
377 }
378
379 template<typename TYPE>
380 bool original::notGreaterFilter<TYPE>::match(const TYPE& t) const {
381 return t <= low;
382 }
383
384 template<typename TYPE>
386 : low(low) {}
387
388 template <typename TYPE>
390 {
391 return new notGreaterFilter(*this);
392 }
393
394 template<typename TYPE>
395 bool original::rangeFilter<TYPE>::match(const TYPE& t) const {
396 return t >= low && t <= high;
397 }
398
399 template<typename TYPE>
400 original::rangeFilter<TYPE>::rangeFilter(const TYPE& low, const TYPE& high)
401 : low(low), high(high) {}
402
403 template <typename TYPE>
405 {
406 return new rangeFilter(*this);
407 }
408
409#endif // FILTER_H
cloneable()=default
Default constructor for cloneable.
equalFilter(const TYPE &target)
Constructs an equalFilter with the target value.
Definition filter.h:310
equalFilter * clone() const override
Clones the equalFilter object.
Definition filter.h:314
Base class for filter operations.
Definition filter.h:31
bool operator()(const TYPE &t) const
Applies the filter to the element.
Definition filter.h:300
~filter() override=default
Virtual destructor for the filter class.
filter * clone() const override
Clones the filter object.
Definition filter.h:294
virtual bool match(const TYPE &t) const
Determines if an element matches the filter condition.
Definition filter.h:289
greaterFilter * clone() const override
Clones the greaterFilter object.
Definition filter.h:359
greaterFilter(const TYPE &high)
Constructs a greaterFilter with the target value.
Definition filter.h:355
lessFilter * clone() const override
Clones the lessFilter object.
Definition filter.h:344
lessFilter(const TYPE &low)
Constructs a lessFilter with the target value.
Definition filter.h:340
notEqualFilter * clone() const override
Clones the notEqualFilter object.
Definition filter.h:329
notEqualFilter(const TYPE &target)
Constructs a notEqualFilter with the target value.
Definition filter.h:325
notGreaterFilter * clone() const override
Clones the notGreaterFilter object.
Definition filter.h:389
notGreaterFilter(const TYPE &low)
Constructs a notGreaterFilter with the target value.
Definition filter.h:385
notLessFilter(const TYPE &high)
Constructs a notLessFilter with the target value.
Definition filter.h:370
notLessFilter * clone() const override
Clones the notLessFilter object.
Definition filter.h:374
rangeFilter(const TYPE &low, const TYPE &high)
Constructs a rangeFilter with the specified range.
Definition filter.h:400
rangeFilter * clone() const override
Clones the rangeFilter object.
Definition filter.h:404
Abstract base class for cloneable objects.
Main namespace for the project Original.
Definition algorithms.h:21