TPIE

v1.1rc1-6-g0c97303
merge.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_MERGE_H__
21 #define __TPIE_PIPELINING_MERGE_H__
22 
23 #include <tpie/pipelining/pipe_base.h>
24 #include <tpie/pipelining/factory_helpers.h>
25 
26 namespace tpie {
27 
28 namespace pipelining {
29 
30 namespace bits {
31 
38 
39 template <typename fact_t>
40 class merge_t {
41 public:
42  typedef typename fact_t::constructed_type pull_t;
43 
44  template <typename dest_t>
45  class type : public node {
46  public:
47  typedef typename dest_t::item_type item_type;
48 
49  inline type(const dest_t & dest, const fact_t & fact) : dest(dest), with(fact.construct()) {
51  add_pull_source(with);
52  set_name("Merge", PRIORITY_INSIGNIFICANT);
53  }
54 
55  inline void push(const item_type & item) {
56  dest.push(item);
57  dest.push(with.pull());
58  }
59 
60  dest_t dest;
61  pull_t with;
62  };
63 };
64 
65 } // namespace bits
66 
67 template <typename pull_t>
69 merge(const pullpipe_begin<pull_t> & with) {
70  return factory_1<bits::merge_t<pull_t>::template type, pull_t>(with.factory);
71 }
72 
73 } // namespace pipelining
74 
75 } // namespace tpie
76 
77 #endif
void add_pull_source(const node_token &dest)
Called by implementers to declare a pull source.
Definition: node.h:370
Merge a pull pipeline into a push pipeline.
Definition: merge.h:40
Base class of all nodes.
Definition: node.h:58
void add_push_destination(const node_token &dest)
Called by implementers to declare a push destination.
Definition: node.h:352
void set_name(const std::string &name, priority_type priority=PRIORITY_USER)
Set this node's name.
Definition: node.h:241
Node factory for 1-argument generator.
A pipe_middle class pushes input down the pipeline.
Definition: pipe_base.h:119