TTTT Analysis  0.1
filter.hpp
Go to the documentation of this file.
1 
37 #ifndef filter_h
38 #define filter_h
39 #include <iostream>
40 #include <functional>
41 #include "value.hpp"
42 namespace fv {
43 
44 class Filter : public DerivedValue<bool>{
45  private:
46  Function<bool()>& filter_function;
47 
48  void update_value(){
49  value = filter_function();
50  }
51  public:
52  Filter(const std::string& name, std::function<bool()> filter_function, const std::string& impl="")
54  filter_function(GenFunction::register_function<bool()>("filter::"+name, filter_function, impl)){ }
55 
60  auto new_name = this->get_name() + "&&" + f->get_name();
61  return new Filter(new_name, [this, f](){return this->get_value() && f->get_value();});
62  }
63 
68  auto new_name = this->get_name() + "||" + f->get_name();
69  return new Filter(new_name, [this, f](){return this->get_value() || f->get_value();});
70  }
71 
75  auto new_name = std::string("!(") + this->get_name() + std::string(")");
76  return new Filter(new_name, [this](){return !this->get_value();});
77  }
78 };
79 
80 template <typename T>
81 class RangeFilter : public Filter{
82  private:
83  public:
84  RangeFilter(const std::string name, Value<T>* test_value, T range_low, T range_high):
85  Filter(name, [test_value, range_low, range_high]{
86  T val = test_value->get_value();
87  return (val >= range_low) && (val < range_high);
88  }) { }
89 };
90 }
91 #endif // filter_h
bool & get_value()
Definition: value.hpp:372
std::string name
The name of the value.
Definition: value.hpp:191
Definition: filter.hpp:44
The namespace containing all filval classes and functions.
Filter * operator+(Filter *f)
Return a new filter that is the disjunction of the two source filters.
Definition: filter.hpp:67
A generic value.
Definition: value.hpp:299
Definition: filter.hpp:81
A generic, derived, value.
Definition: value.hpp:349
Filter * operator*(Filter *f)
Return a new filter that is the conjuction of the two source filters.
Definition: filter.hpp:59
void update_value()
Updates the internal value.
Definition: filter.hpp:48
Filter * operator!()
Return a new filter that is the negation of the source filter.
Definition: filter.hpp:74
virtual T & get_value()=0
Calculate, if necessary, and return the value held by this object.