TPIE

2362a60
visit.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 2016 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_VISIT_H__
21 #define __TPIE_PIPELINING_VISIT_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 F>
33 class visit_t {
34 public:
35  template <typename dest_t>
36  class type: public node {
37  private:
38  F functor;
39  dest_t dest;
40  public:
41  typedef typename std::decay<typename unary_traits<F>::argument_type>::type item_type;
42  type(dest_t dest, const F & functor):
43  functor(functor), dest(std::move(dest)) {
44  set_name(bits::extract_pipe_name(typeid(F).name()), PRIORITY_NO_NAME);
45  }
46 
47  void push(const item_type & item) {
48  functor(item);
49  dest.push(item);
50  }
51  };
52 };
53 
54 } //namespace bits
55 
60 template <typename F>
62  return tempfactory<bits::visit_t<F>, F >(functor);
63 }
64 
65 } //namespace pipelining
66 } //namespace terrastream
67 
68 #endif //__TPIE_PIPELINING_VISIT_H__
Base class of all nodes.
Definition: node.h:78
pipe_middle< tempfactory< bits::visit_t< F >, F > > visit(const F &functor)
A pipelining node that applies a functor to elements pushed to it.
Definition: visit.h:61
Node factory for variadic argument templated generators.
void set_name(const std::string &name, priority_type priority=PRIORITY_USER)
Set this node's name.
A pipe_middle class pushes input down the pipeline.
Definition: pipe_base.h:241