R3BROOT
R3B analysis software
Loading...
Searching...
No Matches
Filterable.h
Go to the documentation of this file.
1/******************************************************************************
2 * Copyright (C) 2019 GSI Helmholtzzentrum für Schwerionenforschung GmbH *
3 * Copyright (C) 2019-2025 Members of R3B Collaboration *
4 * *
5 * This software is distributed under the terms of the *
6 * GNU General Public Licence (GPL) version 3, *
7 * copied verbatim in the file "LICENSE". *
8 * *
9 * In applying this license GSI does not waive the privileges and immunities *
10 * granted to it by virtue of its status as an Intergovernmental Organization *
11 * or submit itself to any jurisdiction. *
12 ******************************************************************************/
13
14#ifndef FILTERABLE
15#define FILTERABLE
16
17#include <functional>
18#include <vector>
19
20template <typename T>
22{
23 public:
24 using Filter = std::function<bool(const T)>;
25
26 private:
27 std::vector<Filter> filters;
28
29 public:
30 Filterable() = default;
31 explicit Filterable(const std::vector<Filter>& vf)
32 : filters(vf)
33 {
34 }
35 inline void Add(const Filter& f) { filters.push_back(f); }
36 inline bool IsValid(const T t) const
37 {
38 for (const auto& filter : filters)
39 {
40 if (filter(t) == false)
41 {
42 return false;
43 }
44 }
45 return true;
46 }
47};
48
49#endif // FILTERABLE
Filterable()=default
void Add(const Filter &f)
Definition Filterable.h:35
bool IsValid(const T t) const
Definition Filterable.h:36
Filterable(const std::vector< Filter > &vf)
Definition Filterable.h:31
std::function< bool(const T)> Filter
Definition Filterable.h:24