filter.hpp
Go to the documentation of this file.
#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 // filter_h
fv::DerivedValue< bool >::get_value
bool & get_value()
Definition: value.hpp:518
fv
The namespace containing all filval classes and functions.
Definition: api.hpp:46