CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
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 $Id: EDCollection.h,v 1.6 2008/03/31 21:12:11 wmtan Exp $
10 
11 ----------------------------------------------------------------------*/
12 
13 #include <vector>
14 
15 namespace edm {
16  template <class T>
17  class EDCollection {
18  public:
19  typedef T value_type;
20  typedef typename std::vector<T>::const_iterator const_iterator;
22  EDCollection();
23  explicit EDCollection(size_type n);
24  explicit EDCollection(std::vector<T> const& vec);
26  virtual ~EDCollection();
27  void push_back(T const& t);
28  void swap(EDCollection<T>& other);
30  bool empty() const;
31  size_type size() const;
32  size_type capacity() const;
33  void reserve(size_type n);
35  T const& operator[](size_type i) const;
36  T& at(size_type i);
37  T const& at(size_type i) const;
38  const_iterator begin() const;
39  const_iterator end() const;
40 
41 
42  private:
43  std::vector<T> obj;
44  };
45 
46  template <class T>
47  inline
49 
50  template <class T>
51  inline
53 
54  template <class T>
55  inline
56  EDCollection<T>::EDCollection(std::vector<T> const& vec) : obj(vec) {}
57 
58  template <class T>
59  inline
61 
62  template <class T>
64 
65  template <class T>
66  inline
67  void
69  obj.push_back(t);
70  }
71 
72  template <class T>
73  inline
74  void
76  obj.swap(other.obj);
77  }
78 
79  template <class T>
80  inline
83  EDCollection<T> temp(rhs);
84  this->swap(temp);
85  return *this;
86  }
87 
88  template <class T>
89  inline
90  bool
92  return obj.empty();
93  }
94 
95  template <class T>
96  inline
99  return obj.size();
100  }
101 
102  template <class T>
103  inline
106  return obj.capacity();
107  }
108 
109  template <class T>
110  inline
111  void
113  obj.reserve(n);
114  }
115 
116  template <class T>
117  inline
118  T&
120  return obj[i];
121  }
122 
123  template <class T>
124  inline
125  T const&
127  return obj[i];
128  }
129 
130  template <class T>
131  inline
132  T&
134  return obj.at(i);
135  }
136 
137  template <class T>
138  inline
139  T const&
141  return obj.at(i);
142  }
143 
144  template <class T>
145  inline
146  typename std::vector<T>::const_iterator
148  return obj.begin();
149  }
150 
151  template <class T>
152  inline
153  typename std::vector<T>::const_iterator
155  return obj.end();
156  }
157 
158  // Free swap function
159  template <class T>
160  inline
161  void
163  {
164  a.swap(b);
165  }
166 
167 }
168 
169 #endif
size_type size() const
Definition: EDCollection.h:98
int i
Definition: DBlmapReader.cc:9
virtual ~EDCollection()
Definition: EDCollection.h:63
const_iterator end() const
Definition: EDCollection.h:154
void push_back(T const &t)
Definition: EDCollection.h:68
uint16_t size_type
void swap(Association< C > &lhs, Association< C > &rhs)
Definition: Association.h:117
bool empty() const
Definition: EDCollection.h:91
std::vector< T > obj
Definition: EDCollection.h:43
std::vector< T >::size_type size_type
Definition: EDCollection.h:21
void reserve(size_type n)
Definition: EDCollection.h:112
const_iterator begin() const
Definition: EDCollection.h:147
The Signals That Services Can Subscribe To This is based on ActivityRegistry h
Helper function to determine trigger accepts.
Definition: Activities.doc:4
T & at(size_type i)
Definition: EDCollection.h:133
double b
Definition: hdecay.h:120
double a
Definition: hdecay.h:121
long double T
void swap(EDCollection< T > &other)
Definition: EDCollection.h:75
size_type capacity() const
Definition: EDCollection.h:105
std::vector< T >::const_iterator const_iterator
Definition: EDCollection.h:20
T & operator[](size_type i)
Definition: EDCollection.h:119
EDCollection< T > & operator=(EDCollection< T > const &rhs)
Definition: EDCollection.h:82