YAP
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Filter.h
Go to the documentation of this file.
1 /* YAP - Yet another PWA toolkit
2  Copyright 2015, Technische Universitaet Muenchen,
3  Authors: Daniel Greenwald, Johannes Rauch
4 
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 3 of the License, or
8  (at your option) any later version.
9 
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.
14 
15  You should have received a copy of the GNU General Public License
16  along with this program. If not, see <http://www.gnu.org/licenses/>.
17  */
18 
20 
21 #ifndef yap__Filter_h
22 #define yap__Filter_h
23 
24 #include "fwd/Filter.h"
25 
26 #include "Exceptions.h"
27 
28 #include <memory>
29 #include <set>
30 
31 namespace yap {
32 
35 
38 template <typename container>
39 typename container::value_type lone_elt(container& C)
40 {
41  if (C.size() != 1)
42  throw yap::exceptions::Exception("Container size not 1 (" + std::to_string(C.size())+ ")", "lone_elt");
43  return *C.begin();
44 }
45 
48 template <typename container>
49 typename container::value_type lone_elt(container&& C)
50 {
51  if (C.size() != 1)
52  throw yap::exceptions::Exception("Container size not 1 (" + std::to_string(C.size()) + ")", "lone_elt");
53  return *C.begin();
54 }
55 
59 template <typename T, typename Last, typename ... UnaryPredicates>
60 std::set<std::shared_ptr<T> > filter(const std::set<std::shared_ptr<T> >& S, Last p, UnaryPredicates ... P)
61 {
62  auto s = filter<T, UnaryPredicates...>(S, P...);
63  for (auto it = s.begin(); it != s.end(); ) {
64  if (p(**it))
65  ++it;
66  else
67  it = s.erase(it);
68  }
69  return s;
70 }
71 
72 // does nothing, needed to terminate above variadic template
73 template <typename T>
74 const std::set<std::shared_ptr<T> >& filter(const std::set<std::shared_ptr<T> >& S)
75 { return S; }
76 
78 // end of defgroup filters
79 
80 }
81 
82 #endif
container::value_type lone_elt(container &C)
Definition: Filter.h:39
Base class for handling YAP exceptions.
Definition: Exceptions.h:39
std::set< std::shared_ptr< T > > filter(const std::set< std::shared_ptr< T > > &S, Last p, UnaryPredicates...P)
Definition: Filter.h:60
std::string to_string(const CachedValue::Status &S)
streaming operator for CachedValue::Status
Definition: CachedValue.cxx:27