Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 12:52:58

0001 #ifndef DataFormats_Common_EDCollection_h
0002 #define DataFormats_Common_EDCollection_h
0003 
0004 /*----------------------------------------------------------------------
0005   
0006 EDCollection: A collection of homogeneous objects that can be used for an EDProduct,
0007 or as a base class for an EDProduct.
0008 
0009 
0010 ----------------------------------------------------------------------*/
0011 
0012 #include <vector>
0013 
0014 namespace edm {
0015   template <class T>
0016   class EDCollection {
0017   public:
0018     typedef T value_type;
0019     typedef typename std::vector<T>::const_iterator const_iterator;
0020     typedef typename std::vector<T>::size_type size_type;
0021     EDCollection();
0022     explicit EDCollection(size_type n);
0023     explicit EDCollection(std::vector<T> const& vec);
0024     EDCollection(EDCollection<T> const& h);
0025     virtual ~EDCollection();
0026     void push_back(T const& t);
0027     void swap(EDCollection<T>& other);
0028     EDCollection<T>& operator=(EDCollection<T> const& rhs);
0029     bool empty() const;
0030     size_type size() const;
0031     size_type capacity() const;
0032     void reserve(size_type n);
0033     T& operator[](size_type i);
0034     T const& operator[](size_type i) const;
0035     T& at(size_type i);
0036     T const& at(size_type i) const;
0037     const_iterator begin() const;
0038     const_iterator end() const;
0039 
0040   private:
0041     std::vector<T> obj;
0042   };
0043 
0044   template <class T>
0045   inline EDCollection<T>::EDCollection() : obj() {}
0046 
0047   template <class T>
0048   inline EDCollection<T>::EDCollection(size_type n) : obj(n) {}
0049 
0050   template <class T>
0051   inline EDCollection<T>::EDCollection(std::vector<T> const& vec) : obj(vec) {}
0052 
0053   template <class T>
0054   inline EDCollection<T>::EDCollection(EDCollection<T> const& h) : obj(h.obj) {}
0055 
0056   template <class T>
0057   EDCollection<T>::~EDCollection() {}
0058 
0059   template <class T>
0060   inline void EDCollection<T>::push_back(T const& t) {
0061     obj.push_back(t);
0062   }
0063 
0064   template <class T>
0065   inline void EDCollection<T>::swap(EDCollection<T>& other) {
0066     obj.swap(other.obj);
0067   }
0068 
0069   template <class T>
0070   inline EDCollection<T>& EDCollection<T>::operator=(EDCollection<T> const& rhs) {
0071     EDCollection<T> temp(rhs);
0072     this->swap(temp);
0073     return *this;
0074   }
0075 
0076   template <class T>
0077   inline bool EDCollection<T>::empty() const {
0078     return obj.empty();
0079   }
0080 
0081   template <class T>
0082   inline typename std::vector<T>::size_type EDCollection<T>::size() const {
0083     return obj.size();
0084   }
0085 
0086   template <class T>
0087   inline typename std::vector<T>::size_type EDCollection<T>::capacity() const {
0088     return obj.capacity();
0089   }
0090 
0091   template <class T>
0092   inline void EDCollection<T>::reserve(typename std::vector<T>::size_type n) {
0093     obj.reserve(n);
0094   }
0095 
0096   template <class T>
0097   inline T& EDCollection<T>::operator[](size_type i) {
0098     return obj[i];
0099   }
0100 
0101   template <class T>
0102   inline T const& EDCollection<T>::operator[](size_type i) const {
0103     return obj[i];
0104   }
0105 
0106   template <class T>
0107   inline T& EDCollection<T>::at(size_type i) {
0108     return obj.at(i);
0109   }
0110 
0111   template <class T>
0112   inline T const& EDCollection<T>::at(size_type i) const {
0113     return obj.at(i);
0114   }
0115 
0116   template <class T>
0117   inline typename std::vector<T>::const_iterator EDCollection<T>::begin() const {
0118     return obj.begin();
0119   }
0120 
0121   template <class T>
0122   inline typename std::vector<T>::const_iterator EDCollection<T>::end() const {
0123     return obj.end();
0124   }
0125 
0126   // Free swap function
0127   template <class T>
0128   inline void swap(EDCollection<T>& a, EDCollection<T>& b) {
0129     a.swap(b);
0130   }
0131 
0132 }  // namespace edm
0133 
0134 #endif