TTTT Analysis  0.1
filter.hpp
1 #ifndef filter_h
2 #define filter_h
3 #include <iostream>
4 #include <functional>
5 #include "value.hpp"
6 /* A Filter is a special type of derived value that can only return a boolean.
7  * Container objects have a vector of filters that control if a "fill" call
8  * actually places data into the container or not.
9  */
10 namespace filval {
11 
12 class Filter : public DerivedValue<bool>{
13  private:
14  std::function<bool()> filter_function;
15  void update_value(){
16  value = filter_function();
17  }
18  public:
19  Filter(const std::string& name, std::function<bool()> filter_function)
21  filter_function(filter_function){ }
22 
23  Filter* operator*(Filter *f){
24  auto new_name = this->get_name() + "&&" + f->get_name();
25  return new Filter(new_name, [this, f](){return this->get_value() && f->get_value();});
26  }
27 
28  Filter* operator+(Filter *f){
29  auto new_name = this->get_name() + "||" + f->get_name();
30  return new Filter(new_name, [this, f](){return this->get_value() || f->get_value();});
31  }
32 
33  Filter* operator!(){
34  std::cout << std::string("!") << std::endl;
35  std::cout << this << this->get_name() << std::endl;
36  auto new_name = std::string("!(") + this->get_name() + std::string(")");
37  std::cout << new_name << std::endl;
38  return new Filter(new_name, [this](){return !this->get_value();});
39  }
40 };
41 
42 template <typename T>
43 class RangeFilter : public Filter{
44  private:
45  public:
46  RangeFilter(const std::string name, Value<T>* test_value, T range_low, T range_high):
47  Filter(name, [test_value, range_low, range_high]{
48  T val = test_value->get_value();
49  return (val >= range_low) && (val < range_high);
50  }){ }
51 };
52 }
53 #endif // filter_h
std::string name
The name of the value.
Definition: value.hpp:71
virtual T & get_value()=0
Calculate, if necessary, and return the value held by this object.
A generic, derived, value.
Definition: value.hpp:174
Definition: filter.hpp:43
The namespace containing all filval classes and functions.
Definition: container.hpp:7
void update_value()
Updates the internal value.
Definition: filter.hpp:15
A generic value.
Definition: value.hpp:124
Definition: filter.hpp:12
bool & get_value()
Definition: value.hpp:197