In this example, we set up a graph with three generators. Each of these generators operate on the same timer. Every time the timer fires, the generators produce a packet of data. The data they produce is dictated by the functors given to them at construction time. In this case, the functors are just functions that return strings.
The produced packets are then fed to an adder transformer node. This adder uses operator+= internally. Thus, for strings, it concatenates its input.
Finally, the adder's output is connected to an ostreamer. This node simply streams the data packets it receives to a std::ostream of our choice, std::cout in this case.
#include <chrono>
#include <iostream>
#include <string>
#include <thread>
using namespace std;
string hello()
{
return "Hello";
}
string space()
{
return ", ";
}
string world()
{
return "world!";
}
int main()
{
auto sp_g1 = make_shared<flow::samples::generic::generator<string>>(mt, hello, "g1");
auto sp_g2 = make_shared<flow::samples::generic::generator<string>>(mt, space, "g2");
auto sp_g3 = make_shared<flow::samples::generic::generator<string>>(mt, world, "g3");
auto sp_a1 = make_shared<flow::samples::math::adder<string>>(3, "a1");
auto sp_o1 = make_shared<flow::samples::generic::ostreamer<string>>(cout, "o1");
g.
connect<
string>(sp_g1, 0, sp_a1, 0);
g.
connect<
string>(sp_g2, 0, sp_a1, 1);
g.
connect<
string>(sp_g3, 0, sp_a1, 2);
g.
connect<
string>(sp_a1, 0, sp_o1, 0);
thread mt_t(ref(mt));
char c;
cin >> c;
cin >> c;
cin >> c;
mt.stop();
mt_t.join();
return 0;
}