1 /***************************************************************************
2 * Copyright (C) 2008-2014 by Andrzej Rybczak *
3 * electricityispower@gmail.com *
5 * This program is free software; you can redistribute it and/or modify *
6 * it under the terms of the GNU General Public License as published by *
7 * the Free Software Foundation; either version 2 of the License, or *
8 * (at your option) any later version. *
10 * This program is distributed in the hope that it will be useful, *
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13 * GNU General Public License for more details. *
15 * You should have received a copy of the GNU General Public License *
16 * along with this program; if not, write to the *
17 * Free Software Foundation, Inc., *
18 * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. *
19 ***************************************************************************/
21 #ifndef NCMPCPP_REGEX_FILTER_H
22 #define NCMPCPP_REGEX_FILTER_H
24 #include <boost/regex.hpp>
27 template <typename T
> struct RegexFilter
29 typedef NC::Menu
<T
> MenuT
;
30 typedef typename
NC::Menu
<T
>::Item Item
;
31 typedef std::function
<bool(const boost::regex
&, const T
&)> FilterFunction
;
33 RegexFilter(boost::regex rx
, FilterFunction filter
)
34 : m_rx(rx
), m_filter(filter
) { }
36 bool operator()(const Item
&item
) {
37 return m_filter(m_rx
, item
.value());
40 static std::string
currentFilter(MenuT
&menu
)
43 auto rf
= menu
.getFilter().template target
< RegexFilter
<T
> >();
45 filter
= rf
->m_rx
.str();
51 FilterFunction m_filter
;
54 template <typename T
> struct RegexItemFilter
56 typedef NC::Menu
<T
> MenuT
;
57 typedef typename
NC::Menu
<T
>::Item Item
;
58 typedef std::function
<bool(const boost::regex
&, const Item
&)> FilterFunction
;
60 RegexItemFilter(boost::regex rx
, FilterFunction filter
)
61 : m_rx(rx
), m_filter(filter
) { }
63 bool operator()(const Item
&item
) {
64 return m_filter(m_rx
, item
);
67 static std::string
currentFilter(MenuT
&menu
)
70 auto rf
= menu
.getFilter().template target
< RegexItemFilter
<T
> >();
72 filter
= rf
->m_rx
.str();
78 FilterFunction m_filter
;
81 #endif // NCMPCPP_REGEX_FILTER_H