main.cpp 1.19 KB
Newer Older
1
// Headers are available because we added the pls target
2 3
#include <string>
#include <cstdio>
4
#include <tuple>
5
#include <array>
6

7 8
#include <pls/dataflow/internal/inputs.h>
#include <pls/dataflow/internal/outputs.h>
9
#include <pls/dataflow/internal/function_node.h>
10
#include <pls/dataflow/internal/graph.h>
11
#include <pls/dataflow/internal/out_port.h>
12

13
int main() {
14
  using namespace pls::dataflow;
15 16
  using namespace pls::dataflow::internal;

17 18
  // Define
  graph<inputs<int, int>, outputs<int>> graph;
19

20
  auto func1 = [](const int &i1, const int &i2, int &o1) {
21
    std::cout << "Add up " << i1 << " and " << i2 << "..." << std::endl;
22 23 24
    o1 = i1 + i2;
  };
  function_node<inputs<int, int>, outputs<int>, decltype(func1)> node1{func1};
25

26
  auto func2 = [](const int &i1, int &o1) {
27 28
    std::cout << "Print Result " << i1 << std::endl;
    o1 = i1;
29 30
  };
  function_node<inputs<int>, outputs<int>, decltype(func2)> node2{func2};
31

32 33 34 35
  // Connect
  graph.input<0>() >> node1.in_port<0>();
  graph.input<1>() >> node1.in_port<1>();

36
  node1.out_port<0>() >> node2.in_port<0>();
37

38 39 40 41 42 43 44 45 46
  node2.out_port<0>() >> graph.output<0>();

  // Build
  graph.build();

  // Execute
  graph.run({1, 2});
  graph.run({1, 1});
  graph.run({5, 6});
47
}