Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:03:51

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     std::vector<T> const& as_vector() const { return obj; }
0040 
0041   private:
0042     std::vector<T> obj;
0043   };
0044 
0045   template <class T>
0046   inline EDCollection<T>::EDCollection() : obj() {}
0047 
0048   template <class T>
0049   inline EDCollection<T>::EDCollection(size_type n) : obj(n) {}
0050 
0051   template <class T>
0052   inline EDCollection<T>::EDCollection(std::vector<T> const& vec) : obj(vec) {}
0053 
0054   template <class T>
0055   inline EDCollection<T>::EDCollection(EDCollection<T> const& h) : obj(h.obj) {}
0056 
0057   template <class T>
0058   EDCollection<T>::~EDCollection() {}
0059 
0060   template <class T>
0061   inline void EDCollection<T>::push_back(T const& t) {
0062     obj.push_back(t);
0063   }
0064 
0065   template <class T>
0066   inline void EDCollection<T>::swap(EDCollection<T>& other) {
0067     obj.swap(other.obj);
0068   }
0069 
0070   template <class T>
0071   inline EDCollection<T>& EDCollection<T>::operator=(EDCollection<T> const& rhs) {
0072     EDCollection<T> temp(rhs);
0073     this->swap(temp);
0074     return *this;
0075   }
0076 
0077   template <class T>
0078   inline bool EDCollection<T>::empty() const {
0079     return obj.empty();
0080   }
0081 
0082   template <class T>
0083   inline typename std::vector<T>::size_type EDCollection<T>::size() const {
0084     return obj.size();
0085   }
0086 
0087   template <class T>
0088   inline typename std::vector<T>::size_type EDCollection<T>::capacity() const {
0089     return obj.capacity();
0090   }
0091 
0092   template <class T>
0093   inline void EDCollection<T>::reserve(typename std::vector<T>::size_type n) {
0094     obj.reserve(n);
0095   }
0096 
0097   template <class T>
0098   inline T& EDCollection<T>::operator[](size_type i) {
0099     return obj[i];
0100   }
0101 
0102   template <class T>
0103   inline T const& EDCollection<T>::operator[](size_type i) const {
0104     return obj[i];
0105   }
0106 
0107   template <class T>
0108   inline T& EDCollection<T>::at(size_type i) {
0109     return obj.at(i);
0110   }
0111 
0112   template <class T>
0113   inline T const& EDCollection<T>::at(size_type i) const {
0114     return obj.at(i);
0115   }
0116 
0117   template <class T>
0118   inline typename std::vector<T>::const_iterator EDCollection<T>::begin() const {
0119     return obj.begin();
0120   }
0121 
0122   template <class T>
0123   inline typename std::vector<T>::const_iterator EDCollection<T>::end() const {
0124     return obj.end();
0125   }
0126 
0127   // Free swap function
0128   template <class T>
0129   inline void swap(EDCollection<T>& a, EDCollection<T>& b) {
0130     a.swap(b);
0131   }
0132 
0133 }  // namespace edm
0134 
0135 #endif