TPIE

2362a60
filter.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_FILTER_H__
21 #define __TPIE_PIPELINING_FILTER_H__
22 
23 #include <tpie/pipelining/map.h>
24 #include <tpie/pipelining/node.h>
25 #include <tpie/pipelining/pipe_base.h>
26 #include <tpie/pipelining/factory_helpers.h>
27 #include <tpie/pipelining/node_name.h>
28 
29 namespace tpie {
30 namespace pipelining {
31 namespace bits {
32 
33 template <typename F>
34 class filter_t {
35 public:
36  template <typename dest_t>
37  class type: public node {
38  private:
39  F functor;
40  dest_t dest;
41  public:
42  typedef typename std::decay<typename unary_traits<F>::argument_type>::type funct_arg_type;
43  typedef typename push_type<dest_t, funct_arg_type>::type item_type;
44  type(dest_t dest, const F & functor):
45  functor(functor), dest(std::move(dest)) {
46  set_name(bits::extract_pipe_name(typeid(F).name()), PRIORITY_NO_NAME);
47  }
48 
49  void push(const item_type & item) {
50  if (functor(item))
51  dest.push(item);
52  }
53  };
54 };
55 
56 } //namespace bits
57 
63 template <typename F>
65  return tempfactory<bits::filter_t<F>, F >(functor);
66 }
67 
68 } //namespace pipelining
69 } //namespace terrastream
70 
71 #endif //__TPIE_PIPELINING_FILTER_H__
Base class of all nodes.
Definition: node.h:78
Node factory for variadic argument templated generators.
void set_name(const std::string &name, priority_type priority=PRIORITY_USER)
Set this node's name.
pipe_middle< tempfactory< bits::filter_t< F >, F > > filter(const F &functor)
A pipelining node that keeps only elements where functor evaluates to true.
Definition: filter.h:64
A pipe_middle class pushes input down the pipeline.
Definition: pipe_base.h:241