CMS 3D CMS Logo

EDCollection.h
Go to the documentation of this file.
1 #ifndef DataFormats_Common_EDCollection_h
2 #define DataFormats_Common_EDCollection_h
3 
4 /*----------------------------------------------------------------------
5 
6 EDCollection: A collection of homogeneous objects that can be used for an EDProduct,
7 or as a base class for an EDProduct.
8 
9 
10 ----------------------------------------------------------------------*/
11 
12 #include <vector>
13 
14 namespace edm {
15  template <class T>
16  class EDCollection {
17  public:
18  typedef T value_type;
19  typedef typename std::vector<T>::const_iterator const_iterator;
21  EDCollection();
22  explicit EDCollection(size_type n);
23  explicit EDCollection(std::vector<T> const& vec);
25  virtual ~EDCollection();
26  void push_back(T const& t);
27  void swap(EDCollection<T>& other);
29  bool empty() const;
30  size_type size() const;
31  size_type capacity() const;
32  void reserve(size_type n);
33  T& operator[](size_type i);
34  T const& operator[](size_type i) const;
35  T& at(size_type i);
36  T const& at(size_type i) const;
37  const_iterator begin() const;
38  const_iterator end() const;
39 
40  private:
41  std::vector<T> obj;
42  };
43 
44  template <class T>
46 
47  template <class T>
49 
50  template <class T>
51  inline EDCollection<T>::EDCollection(std::vector<T> const& vec) : obj(vec) {}
52 
53  template <class T>
55 
56  template <class T>
58 
59  template <class T>
60  inline void EDCollection<T>::push_back(T const& t) {
61  obj.push_back(t);
62  }
63 
64  template <class T>
66  obj.swap(other.obj);
67  }
68 
69  template <class T>
71  EDCollection<T> temp(rhs);
72  this->swap(temp);
73  return *this;
74  }
75 
76  template <class T>
77  inline bool EDCollection<T>::empty() const {
78  return obj.empty();
79  }
80 
81  template <class T>
83  return obj.size();
84  }
85 
86  template <class T>
88  return obj.capacity();
89  }
90 
91  template <class T>
93  obj.reserve(n);
94  }
95 
96  template <class T>
98  return obj[i];
99  }
100 
101  template <class T>
102  inline T const& EDCollection<T>::operator[](size_type i) const {
103  return obj[i];
104  }
105 
106  template <class T>
108  return obj.at(i);
109  }
110 
111  template <class T>
112  inline T const& EDCollection<T>::at(size_type i) const {
113  return obj.at(i);
114  }
115 
116  template <class T>
117  inline typename std::vector<T>::const_iterator EDCollection<T>::begin() const {
118  return obj.begin();
119  }
120 
121  template <class T>
122  inline typename std::vector<T>::const_iterator EDCollection<T>::end() const {
123  return obj.end();
124  }
125 
126  // Free swap function
127  template <class T>
129  a.swap(b);
130  }
131 
132 } // namespace edm
133 
134 #endif
size_type size() const
Definition: EDCollection.h:82
FWCore Framework interface EventSetupRecordImplementation h
Helper function to determine trigger accepts.
virtual ~EDCollection()
Definition: EDCollection.h:57
const_iterator end() const
Definition: EDCollection.h:122
void push_back(T const &t)
Definition: EDCollection.h:60
uint16_t size_type
bool empty() const
Definition: EDCollection.h:77
std::vector< T > obj
Definition: EDCollection.h:41
std::vector< T >::size_type size_type
Definition: EDCollection.h:20
void reserve(size_type n)
Definition: EDCollection.h:92
const_iterator begin() const
Definition: EDCollection.h:117
T & at(size_type i)
Definition: EDCollection.h:107
double b
Definition: hdecay.h:118
HLT enums.
double a
Definition: hdecay.h:119
long double T
void swap(EDCollection< T > &other)
Definition: EDCollection.h:65
size_type capacity() const
Definition: EDCollection.h:87
std::vector< T >::const_iterator const_iterator
Definition: EDCollection.h:19
T & operator[](size_type i)
Definition: EDCollection.h:97
EDCollection< T > & operator=(EDCollection< T > const &rhs)
Definition: EDCollection.h:70