TPIE

11a2c2d
stdio.h
1 // -*- mode: c++; tab-width: 4; indent-tabs-mode: t; eval: (progn (c-set-style "stroustrup") (c-set-offset 'innamespace 0)); -*-
2 // vi:set ts=4 sts=4 sw=4 noet :
3 // Copyright 2011, 2012, The TPIE development team
4 //
5 // This file is part of TPIE.
6 //
7 // TPIE is free software: you can redistribute it and/or modify it under
8 // the terms of the GNU Lesser General Public License as published by the
9 // Free Software Foundation, either version 3 of the License, or (at your
10 // option) any later version.
11 //
12 // TPIE is distributed in the hope that it will be useful, but WITHOUT ANY
13 // WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 // FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
15 // License for more details.
16 //
17 // You should have received a copy of the GNU Lesser General Public License
18 // along with TPIE. If not, see <http://www.gnu.org/licenses/>
19 
20 #ifndef __TPIE_PIPELINING_STDIO_H__
21 #define __TPIE_PIPELINING_STDIO_H__
22 
23 #include <tpie/pipelining/node.h>
24 #include <tpie/pipelining/pipe_base.h>
25 #include <tpie/pipelining/factory_helpers.h>
26 #include <cstdio>
27 
28 namespace tpie::pipelining {
29 namespace bits {
30 
31 template <typename dest_t>
32 class scanf_ints_t : public node {
33 public:
34  typedef int item_type;
35 
36  scanf_ints_t(dest_t dest) : dest(std::move(dest)) {
37  add_push_destination(this->dest);
38  }
39 
40  void go() override {
41  int in;
42  while (scanf("%d", &in) == 1) {
43  dest.push(in);
44  }
45  }
46 
47 private:
48  dest_t dest;
49 };
50 
51 class printf_ints_t : public node {
52 public:
53  typedef int item_type;
54 
55  printf_ints_t() {
56  }
57 
58  void push(item_type i) {
59  printf("%d\n", i);
60  }
61 };
62 
63 } // namespace bits
64 
69 
74 
75 } // namespace tpie::pipelining
76 
77 #endif //__TPIE_PIPELINING_STDIO_H__
tpie::pipelining
pipelining/factory_base.h Base class of pipelining factories
Definition: ami_glue.h:23
tpie::pipelining::pipe_begin
Definition: pipe_base.h:331
tpie::pipelining::pipe_end
Definition: pipe_base.h:212
tpie::pipelining::bits::scanf_ints_t
Definition: stdio.h:32
tpie::pipelining::node::add_push_destination
void add_push_destination(const node_token &dest)
Called by implementers to declare a push destination.
tpie::pipelining::bits::scanf_ints_t::go
void go() override
For initiator nodes, execute this phase by pushing all items to be pushed.
Definition: stdio.h:40
tpie::pipelining::bits::printf_ints_t
Definition: stdio.h:51
tpie::pipelining::printf_ints
pipe_end< termfactory< bits::printf_ints_t > > printf_ints
A pipelining node that prints the items that are pushed to it.
Definition: stdio.h:73
tpie::pipelining::node
Base class of all nodes.
Definition: node.h:77
tpie::pipelining::scanf_ints
pipe_begin< factory< bits::scanf_ints_t > > scanf_ints
A pipelining node that pushes the integers it reads using scanf.
Definition: stdio.h:68