123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108 |
- #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();
- }
- void verify_integrity(){ };
- public:
- ObsFilter(const std::string& name, std::function<bool()> filter_function, const std::string& impl="")
- :DerivedValue<bool>(name),
- filter_function(GenFunction::register_function<bool()>("filter::"+name, filter_function, impl)){ }
-
- static ObsFilter* conj(ObsFilter *f1, ObsFilter *f2){
- auto new_name = f1->get_name() + "&&" + f2->get_name();
- return new ObsFilter(new_name, [f1,f2](){return f1->get_value() && f2->get_value();});
- }
-
- static ObsFilter* disj(ObsFilter *f1, ObsFilter *f2){
- auto new_name = f1->get_name() + "||" + f2->get_name();
- return new ObsFilter(new_name, [f1, f2](){return f1->get_value() && f2->get_value();});
- }
-
- ObsFilter* operator*(ObsFilter *f){
- auto new_name = this->get_name() + "&&" + f->get_name();
- return new ObsFilter(new_name, [this, f](){return this->get_value() && f->get_value();});
- }
-
- ObsFilter* operator+(ObsFilter *f){
- auto new_name = this->get_name() + "||" + f->get_name();
- return new ObsFilter(new_name, [this, f](){return this->get_value() || f->get_value();});
- }
-
- ObsFilter* operator!(){
- auto new_name = std::string("!(") + this->get_name() + std::string(")");
- return new ObsFilter(new_name, [this](){return !this->get_value();});
- }
- };
- template <typename T>
- class RangeObsFilter : public ObsFilter{
- private:
- public:
- RangeObsFilter(const std::string name, Value<T>* test_value, T range_low, T range_high):
- ObsFilter(name, [test_value, range_low, range_high]{
- T val = test_value->get_value();
- return (val >= range_low) && (val < range_high);
- }) { }
- };
- }
- #endif
|