Skip to content

Commit fd35f8c

Browse files
committed
Replace 'exclude_lambda' with 'filter_map'
In continuation of the deprecation issue #196
1 parent 9c12a3e commit fd35f8c

3 files changed

Lines changed: 74 additions & 15 deletions

File tree

tpie/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ set (HEADERS
7171
pipelining/factory_helpers.h
7272
pipelining/file_stream.h
7373
pipelining/filter.h
74+
pipelining/filter_map.h
7475
pipelining/forwarder.h
7576
pipelining/helpers.h
7677
pipelining/internal_buffer.h

tpie/pipelining/filter_map.h

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
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_map_t: public node {
34+
private:
35+
F functor;
36+
dest_t dest;
37+
38+
public:
39+
typedef typename std::decay<typename unary_traits<F>::argument_type>::type item_type;
40+
41+
filter_map_t(dest_t dest, const F & functor):
42+
functor(functor), dest(std::move(dest)) {
43+
set_name(bits::extract_pipe_name(typeid(F).name()), PRIORITY_NO_NAME);
44+
}
45+
46+
void push(const item_type & item) {
47+
typename F::result_type t=f(item);
48+
if (t.second) dest.push(t.first);
49+
}
50+
};
51+
52+
} //namespace bits
53+
54+
///////////////////////////////////////////////////////////////////////////////
55+
/// \brief A pipelining node that applies a functor to items and only keeps
56+
/// some of them based on the functor's result.
57+
/// \details The result of the functor must be a pair, e.g.
58+
/// <tt>std::pair<T,bool></tt>: the second item is a boolean indiciating whether
59+
/// item should be pushed to the next node while the first one carries the value
60+
/// itself that is to be pushed.
61+
/// \param functor The functor that should be applied to items
62+
///////////////////////////////////////////////////////////////////////////////
63+
template <typename F, typename = typename std::enable_if<bits::has_argument_type<F>::value>::type>
64+
pipe_middle<tfactory<bits::filter_map_t, Args<F>, F> > filter_map(const F & functor) {
65+
return {functor};
66+
}
67+
68+
} //namespace terrastream::pipelining
69+
70+
#endif //__TPIE_PIPELINING_FILTER_H__

tpie/pipelining/std_glue.h

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
#include <tpie/pipelining/pipe_base.h>
2727
#include <tpie/pipelining/factory_helpers.h>
2828
#include <tpie/pipelining/map.h>
29+
#include <tpie/pipelining/filter_map.h>
2930

3031
namespace tpie::pipelining {
3132
namespace bits {
@@ -101,21 +102,7 @@ template <typename dest_t, typename F>
101102
using lambda_t [[deprecated("Use 'map_t' in 'tpie/pipelining/map.h'.")]] = map_t<dest_t, F>;
102103

103104
template <typename dest_t, typename F>
104-
class exclude_lambda_t: public node {
105-
public:
106-
typedef typename F::argument_type item_type;
107-
108-
exclude_lambda_t(dest_t dest, const F & f): f(f), dest(std::move(dest)) { }
109-
110-
void push(const item_type & item) {
111-
typename F::result_type t=f(item);
112-
if (t.second) dest.push(t.first);
113-
}
114-
private:
115-
F f;
116-
dest_t dest;
117-
};
118-
105+
using exclude_lambda_t [[deprecated("Use 'filter_map_t' in 'tpie/pipelining/map.h'.")]] = filter_map_t<dest_t, F>;
119106

120107
} // namespace bits
121108

@@ -176,6 +163,7 @@ inline pipe_middle<tfactory<bits::lambda_t, Args<F>, F> > lambda(const F & f) {
176163
/// \param f The functor that should be applied to items
177164
///////////////////////////////////////////////////////////////////////////////
178165
template <typename F>
166+
[[deprecated("Use 'filter_map' in 'tpie/pipelining/filter_map.h'.")]]
179167
inline pipe_middle<tfactory<bits::exclude_lambda_t, Args<F>, F> > exclude_lambda(const F & f) {
180168
return {f};
181169
}

0 commit comments

Comments
 (0)