TPIE

11a2c2d
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::pipelining {
30 namespace bits {
31 
32 template <typename dest_t, typename F>
33 class filter_t: public node {
34 private:
35  F functor;
36  dest_t dest;
37 public:
38  typedef typename std::decay<typename unary_traits<F>::argument_type>::type funct_arg_type;
39  typedef typename push_type<dest_t, funct_arg_type>::type item_type;
40  filter_t(dest_t dest, const F & functor):
41  functor(functor), dest(std::move(dest)) {
42  set_name(bits::extract_pipe_name(typeid(F).name()), PRIORITY_NO_NAME);
43  }
44 
45  void push(const item_type & item) {
46  if (functor(item))
47  dest.push(item);
48  }
49 };
50 
51 
52 } //namespace bits
53 
59 template <typename F>
61  return {functor};
62 }
63 
64 } //namespace terrastream::pipelining
65 
66 #endif //__TPIE_PIPELINING_FILTER_H__
tpie::pipelining
pipelining/factory_base.h Base class of pipelining factories
Definition: ami_glue.h:23
tpie::pipelining::node::set_name
void set_name(const std::string &name, priority_type priority=PRIORITY_USER)
Set this node's name.
tpie::pipelining::pipe_middle
Definition: pipe_base.h:243
tpie::pipelining::node
Base class of all nodes.
Definition: node.h:77
tpie::pipelining::filter
pipe_middle< tfactory< bits::filter_t, Args< F >, F > > filter(const F &functor)
A pipelining node that keeps only elements where functor evaluates to true.
Definition: filter.h:60
tpie::pipelining::bits::filter_t
Definition: filter.h:33