_test_hydra.cxx
Go to the documentation of this file.
1 #include <tbb/flow_graph.hpp>
2 #include <boost/any.hpp>
3 
4 typedef std::deque<boost::any> AnyQueue;
5 typedef std::vector<AnyQueue> AnyPorts;
6 
7 class Hydra {
8 public:
9  virtual ~Hydra() {}
10  bool insert(AnyPorts& input) = 0;
11  bool extract(AnyPorts& output) = 0;
12 };
13 
14 template<typename OutputType>
15 class Source : public Hydra {
16 public:
17  virtual ~Source() {}
18 
19  typedef std::shared_ptr<const OutputType> output_pointer;
20 
21  virtual bool insert(AnyPorts& input) { return false; }
22  virtual bool extract(AnyPorts& output) {
23  output_pointer out;
24  bool ok = this->extract(out);
25  if (!ok) return false;
26  output[0].push_back(out);
27  return true;
28  }
29 
30  virtual bool extract(output_pointer& out) = 0;
31 };
32 
33 template<typename InputType>
34 class Sink : public Hydra {
35 public:
36  virtual ~Sink() {}
37 
38  typedef std::shared_ptr<const InputType> input_pointer;
39 
40  virtual bool extract(AnyPorts& output) { return false; }
41  virtual bool insert(AnyPorts& input) {
42  for (auto anyin : input[0]) {
43  input_pointer in = any_cast<input_pointer>(anyin);
44  bool ok = this->insert(in);
45  if (!ok) return false;
46  }
47  return true;
48  }
49 
50  virtual bool insert(const input_pointer& in) = 0;
51 };
52 
53 
54 
55 class IntSource : public Source<int> {
56  int m_count;
57  const int m_max;
58 public:
59  IntSource(int maxcount = 10) : m_count(0), m_max(maxcount) {}
60  virtual ~IntSource() {}
61 
62  virtual bool extract(output_pointer& out) {
63  ++m_count;
64  if (m_count > m_max) { return false; }
65  out = new int(m_count);
66  return true;
67  }
68 };
69 
70 class IntSink : public Sink<int> {
71 public:
72  virtual ~IntSink() {}
73  virtual bool insert(const input_pointer& in) {
74  return true;
75  }
76 };
77 
78 
79 
80 int main()
81 {
82 
83 }
std::vector< AnyQueue > AnyPorts
Definition: _test_hydra.cxx:5
virtual bool extract(output_pointer &out)
Definition: _test_hydra.cxx:62
virtual ~Source()
Definition: _test_hydra.cxx:17
std::shared_ptr< const OutputType > output_pointer
Definition: _test_hydra.cxx:19
int main()
Definition: _test_hydra.cxx:80
virtual bool insert(const input_pointer &in)
Definition: _test_hydra.cxx:73
virtual ~IntSource()
Definition: _test_hydra.cxx:60
bool extract(AnyPorts &output)=0
virtual ~Hydra()
Definition: _test_hydra.cxx:9
IntSource(int maxcount=10)
Definition: _test_hydra.cxx:59
static int input(void)
Definition: code.cpp:15695
virtual ~Sink()
Definition: _test_hydra.cxx:36
virtual bool extract(AnyPorts &output)
Definition: _test_hydra.cxx:40
std::shared_ptr< const InputType > input_pointer
Definition: _test_hydra.cxx:38
bool insert(AnyPorts &input)=0
virtual bool extract(AnyPorts &output)
Definition: _test_hydra.cxx:22
virtual bool insert(AnyPorts &input)
Definition: _test_hydra.cxx:41
virtual bool insert(AnyPorts &input)
Definition: _test_hydra.cxx:21
std::deque< boost::any > AnyQueue
Definition: _test_hydra.cxx:4
const int m_max
Definition: _test_hydra.cxx:57
virtual ~IntSink()
Definition: _test_hydra.cxx:72