123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990 |
- #ifndef filter_h
- #define filter_h
- #include <iostream>
- #include <functional>
- #include "value.hpp"
- namespace fv {
- class ObsFilter : public DerivedValue<bool>{
- private:
- Function<bool()>& filter_function;
- void update_value(){
- value = filter_function();
- }
- public:
- ObsFilter(const std::string& name, std::function<bool()> filter_function, const std::string& impl="")
- :DerivedValue<bool>(name),
- filter_function(GenFunction::reg_func<bool()>("filter::"+name, filter_function, impl)){ }
- };
- ObsFilter* all(const std::vector<ObsFilter*>&& fs){
- if(fs.size() == 0){
- return nullptr;
- } else{
- std::stringstream ss;
- ss << fs[0]->get_name();
- for(size_t i=1; i<fs.size(); i++) ss << "AND" << fs[i]->get_name();
- return new ObsFilter(ss.str(), [fs](){
- return std::all_of(std::begin(fs), std::end(fs), [](ObsFilter* f){return f->get_value();});
- });
- }
- }
- ObsFilter* any(const std::vector<ObsFilter*>&& fs){
- if(fs.size() == 0){
- return nullptr;
- } else{
- std::stringstream ss;
- ss << fs[0]->get_name();
- for(size_t i=1; i<fs.size(); i++) ss << "OR" << fs[i]->get_name();
- return new ObsFilter(ss.str(), [fs](){
- return std::any_of(std::begin(fs), std::end(fs), [](ObsFilter* f){return f->get_value();});
- });
- }
- }
- }
- #endif
|