CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
Selection.h
Go to the documentation of this file.
1 #ifndef CommonTools_Utils_Selection_h
2 #define CommonTools_Utils_Selection_h
3 #include <vector>
4 
5 template <typename C, typename Selector, typename StoreContainer = std::vector<const typename C::value_type*> >
6 class Selection {
7 public:
8  typedef typename C::value_type value_type;
9  typedef typename C::size_type size_type;
11  typedef const value_type& const_reference;
12  Selection(const C& c, const Selector& sel) : select_(sel) {
13  for (typename C::const_iterator i = c.begin(); i != c.end(); ++i) {
14  if (select_(*i))
15  selected_.push_back(&*i);
16  }
17  }
19  public:
21  typedef value_type* pointer;
23  typedef std::ptrdiff_t difference_type;
24  typedef typename StoreContainer::const_iterator::iterator_category iterator_category;
25  const_iterator(const typename StoreContainer::const_iterator& it) : i(it) {}
26  const_iterator(const const_iterator& it) : i(it.i) {}
29  i = it.i;
30  return *this;
31  }
33  ++i;
34  return *this;
35  }
37  const_iterator ci = *this;
38  ++i;
39  return ci;
40  }
42  --i;
43  return *this;
44  }
46  const_iterator ci = *this;
47  --i;
48  return ci;
49  }
50  difference_type operator-(const const_iterator& o) const { return i - o.i; }
53  bool operator<(const const_iterator& o) const { return i < o.i; }
54  bool operator==(const const_iterator& ci) const { return i == ci.i; }
55  bool operator!=(const const_iterator& ci) const { return i != ci.i; }
56  const value_type& operator*() const { return **i; }
57  const value_type* operator->() const { return &(operator*()); }
59  i += d;
60  return *this;
61  }
63  i -= d;
64  return *this;
65  }
66 
67  private:
68  typename StoreContainer::const_iterator i;
69  };
70  const_iterator begin() const { return const_iterator(selected_.begin()); }
71  const_iterator end() const { return const_iterator(selected_.end()); }
72  size_type size() const { return selected_.size(); }
73  bool empty() const { return selected_.empty(); }
75 
76 private:
78  StoreContainer selected_;
79 };
80 
81 #endif
const value_type & const_reference
Definition: Selection.h:11
const edm::EventSetup & c
StoreContainer::const_iterator::iterator_category iterator_category
Definition: Selection.h:24
value_type * pointer
Definition: Selection.h:21
std::ptrdiff_t difference_type
Definition: Selection.h:23
const_iterator operator--(int)
Definition: Selection.h:45
bool operator==(const const_iterator &ci) const
Definition: Selection.h:54
const_iterator & operator+=(difference_type d)
Definition: Selection.h:58
bool operator!=(const const_iterator &ci) const
Definition: Selection.h:55
const_iterator & operator++()
Definition: Selection.h:32
const_iterator(const typename StoreContainer::const_iterator &it)
Definition: Selection.h:25
const_iterator begin() const
Definition: Selection.h:70
const_reference operator[](size_type i)
Definition: Selection.h:74
bool empty() const
Definition: Selection.h:73
size_type size() const
Definition: Selection.h:72
uint16_t size_type
const_iterator operator-(difference_type n) const
Definition: Selection.h:52
C::value_type value_type
Definition: Selection.h:8
tuple d
Definition: ztail.py:151
Selection< C, Selector, StoreContainer >::value_type value_type
Definition: Selection.h:20
StoreContainer::const_iterator i
Definition: Selection.h:68
const_iterator operator++(int)
Definition: Selection.h:36
Selector select_
Definition: Selection.h:77
value_type & reference
Definition: Selection.h:10
const_iterator & operator-=(difference_type d)
Definition: Selection.h:62
difference_type operator-(const const_iterator &o) const
Definition: Selection.h:50
Functor that operates on &lt;T&gt;
Definition: Selector.h:22
const_iterator operator+(difference_type n) const
Definition: Selection.h:51
value_type & reference
Definition: Selection.h:22
StoreContainer selected_
Definition: Selection.h:78
const_iterator & operator--()
Definition: Selection.h:41
C::size_type size_type
Definition: Selection.h:9
const_iterator(const const_iterator &it)
Definition: Selection.h:26
Selection(const C &c, const Selector &sel)
Definition: Selection.h:12
const value_type * operator->() const
Definition: Selection.h:57
bool operator<(const const_iterator &o) const
Definition: Selection.h:53
const value_type & operator*() const
Definition: Selection.h:56
const_iterator & operator=(const const_iterator &it)
Definition: Selection.h:28
const_iterator end() const
Definition: Selection.h:71