TPIE

11a2c2d
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::pipelining {
29 namespace bits {
30 
31 template <typename dest_t>
32 class Forwarder: public node {
33 public:
34  typedef typename push_type<dest_t>::type item_type;
35  typedef std::vector<std::pair<std::string, any_noncopyable> > values_t;
36 
37  Forwarder(dest_t dest, values_t values)
38  : values(std::move(values)), dest(std::move(dest)) {}
39 
40  void prepare() override {
41  for (typename values_t::iterator i=values.begin(); i != values.end(); ++i)
42  forward_any(i->first, std::move(i->second));
43  }
44 
45  template <typename T>
46  void push(T && t) {dest.push(std::forward<T>(t));}
47 private:
48  std::vector<std::pair<std::string, any_noncopyable> > values;
49  dest_t dest;
50 };
51 
52 } //namespace bits
53 
56 // pass though items on push
58 inline pipe_middle<factory<bits::Forwarder, std::vector<std::pair<std::string, any_noncopyable> > > > forwarder(std::vector<std::pair<std::string, any_noncopyable> > items) {
60 }
61 
64 // pass though items on push
66 template <typename VT>
68  std::vector<std::pair<std::string, any_noncopyable> > v;
69  v.push_back(std::make_pair(name, any_noncopyable(value)));
70  return forwarder(std::move(v));
71 }
72 
73 } //namespace terrastream::pipelining
74 
75 #endif //__TPIE_PIPELINING_FORWARDER_H__
76 
tpie::pipelining
pipelining/factory_base.h Base class of pipelining factories
Definition: ami_glue.h:23
tpie::pipelining::factory
Definition: factory_helpers.h:35
tpie::pipelining::node::forward_any
void forward_any(std::string key, any_noncopyable value, memory_size_type k=std::numeric_limits< memory_size_type >::max())
See node::forward.
tpie::pipelining::push_type
Class to deduce the item_type of a node of type T.
Definition: node_traits.h:158
tpie::pipelining::pipe_middle
Definition: pipe_base.h:243
tpie::pipelining::bits::Forwarder::prepare
void prepare() override
Called before memory assignment but after depending phases have executed and ended.
Definition: forwarder.h:40
tpie::pipelining::bits::Forwarder
Definition: forwarder.h:32
tpie::pipelining::forwarder
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:58
tpie::pipelining::node
Base class of all nodes.
Definition: node.h:77
tpie::pipelining::any_noncopyable
Definition: container.h:195