TPIE

2362a60
forwarder.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 2015 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_FORWARDER_H__
21 #define __TPIE_PIPELINING_FORWARDER_H__
22 
23 #include <tpie/pipelining/node.h>
24 #include <tpie/pipelining/pipe_base.h>
25 #include <tpie/pipelining/factory_helpers.h>
26 #include <tpie/pipelining/node_name.h>
27 
28 namespace tpie {
29 namespace pipelining {
30 namespace bits {
31 
32 template <typename dest_t>
33 class Forwarder: public node {
34 public:
35  typedef typename push_type<dest_t>::type item_type;
36  typedef std::vector<std::pair<std::string, any_noncopyable> > values_t;
37 
38  Forwarder(dest_t dest, values_t values)
39  : values(std::move(values)), dest(std::move(dest)) {}
40 
41  void prepare() override {
42  for (typename values_t::iterator i=values.begin(); i != values.end(); ++i)
43  forward_any(i->first, std::move(i->second));
44  }
45 
46  template <typename T>
47  void push(T && t) {dest.push(std::forward<T>(t));}
48 private:
49  std::vector<std::pair<std::string, any_noncopyable> > values;
50  dest_t dest;
51 };
52 
53 } //namespace bits
54 
57 // pass though items on push
59 inline pipe_middle<factory<bits::Forwarder, std::vector<std::pair<std::string, any_noncopyable> > > > forwarder(std::vector<std::pair<std::string, any_noncopyable> > items) {
61 }
62 
65 // pass though items on push
67 template <typename VT>
69  std::vector<std::pair<std::string, any_noncopyable> > v;
70  v.push_back(std::make_pair(name, any_noncopyable(value)));
71  return forwarder(std::move(v));
72 }
73 
74 } //namespace pipelining
75 } //namespace terrastream
76 
77 #endif //__TPIE_PIPELINING_FORWARDER_H__
78 
pipe_middle< factory< bits::Forwarder, std::vector< std::pair< std::string, any_noncopyable > > > > forwarder(std::vector< std::pair< std::string, any_noncopyable > > items)
A pipelining node that will forward values on prepare, and.
Definition: forwarder.h:59
void forward_any(std::string key, any_noncopyable value, memory_size_type k=std::numeric_limits< memory_size_type >::max())
See node::forward.
void prepare() override
Called before memory assignment but after depending phases have executed and ended.
Definition: forwarder.h:41
Base class of all nodes.
Definition: node.h:78
Class to deduce the item_type of a node of type T.
Definition: node_traits.h:152
Node factory for variadic argument generators.
A pipe_middle class pushes input down the pipeline.
Definition: pipe_base.h:241