TPIE

2362a60
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 {
29 
30 namespace pipelining {
31 
32 namespace bits {
33 
34 template <typename dest_t>
35 class scanf_ints_t : public node {
36 public:
37  typedef int item_type;
38 
39  inline scanf_ints_t(dest_t dest) : dest(std::move(dest)) {
40  add_push_destination(this->dest);
41  }
42 
43  virtual void go() override {
44  int in;
45  while (scanf("%d", &in) == 1) {
46  dest.push(in);
47  }
48  }
49 
50 private:
51  dest_t dest;
52 };
53 
54 class printf_ints_t : public node {
55 public:
56  typedef int item_type;
57 
58  inline printf_ints_t() {
59  }
60 
61  inline void push(item_type i) {
62  printf("%d\n", i);
63  }
64 };
65 
66 } // namespace bits
67 
72 
77 
78 } // namespace pipelining
79 
80 } // namespace tpie
81 
82 #endif
Base class of all nodes.
Definition: node.h:78
void add_push_destination(const node_token &dest)
Called by implementers to declare a push destination.
virtual void go() override
For initiator nodes, execute this phase by pushing all items to be pushed.
Definition: stdio.h:43
pipe_begin< factory< bits::scanf_ints_t > > scanf_ints
A pipelining node that pushes the integers it reads using scanf.
Definition: stdio.h:71
pipe_end< termfactory< bits::printf_ints_t > > printf_ints
A pipelining node that prints the items that are pushed to it.
Definition: stdio.h:76