CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_2_7_hltpatch1/src/DataFormats/Common/interface/EDCollection.h

Go to the documentation of this file.
00001 #ifndef DataFormats_Common_EDCollection_h
00002 #define DataFormats_Common_EDCollection_h
00003 
00004 /*----------------------------------------------------------------------
00005   
00006 EDCollection: A collection of homogeneous objects that can be used for an EDProduct,
00007 or as a base class for an EDProduct.
00008 
00009 $Id: EDCollection.h,v 1.6 2008/03/31 21:12:11 wmtan Exp $
00010 
00011 ----------------------------------------------------------------------*/
00012 
00013 #include <vector>
00014 
00015 namespace edm {
00016   template <class T>
00017   class EDCollection {
00018   public:
00019     typedef T value_type;
00020     typedef typename std::vector<T>::const_iterator const_iterator;
00021     typedef typename std::vector<T>::size_type size_type;
00022     EDCollection();
00023     explicit EDCollection(size_type n);
00024     explicit EDCollection(std::vector<T> const& vec);
00025     EDCollection(EDCollection<T> const& h);
00026     virtual ~EDCollection();
00027     void push_back(T const& t);
00028     void swap(EDCollection<T>& other);
00029     EDCollection<T>& operator=(EDCollection<T> const& rhs);
00030     bool empty() const;
00031     size_type size() const;
00032     size_type capacity() const;
00033     void reserve(size_type n);
00034     T& operator[](size_type i);
00035     T const& operator[](size_type i) const;
00036     T& at(size_type i);
00037     T const& at(size_type i) const;
00038     const_iterator begin() const;
00039     const_iterator end() const;
00040     
00041 
00042   private:
00043     std::vector<T> obj;    
00044   };
00045 
00046   template <class T>
00047   inline
00048   EDCollection<T>::EDCollection() : obj() {}
00049 
00050   template <class T>
00051   inline
00052   EDCollection<T>::EDCollection(size_type n) : obj(n) {}
00053 
00054   template <class T>
00055   inline
00056   EDCollection<T>::EDCollection(std::vector<T> const& vec) : obj(vec) {}
00057 
00058   template <class T>
00059   inline
00060   EDCollection<T>::EDCollection(EDCollection<T> const& h) : obj(h.obj) {}
00061 
00062   template <class T>
00063   EDCollection<T>::~EDCollection() {}
00064 
00065   template <class T>
00066   inline
00067   void
00068   EDCollection<T>::push_back(T const& t) {
00069     obj.push_back(t);
00070   }
00071 
00072   template <class T>
00073   inline
00074   void
00075   EDCollection<T>::swap(EDCollection<T>& other) {
00076     obj.swap(other.obj);
00077   }
00078 
00079   template <class T>
00080   inline
00081   EDCollection<T>&
00082   EDCollection<T>::operator=(EDCollection<T> const& rhs) {
00083     EDCollection<T> temp(rhs);
00084     this->swap(temp);
00085     return *this;
00086   }
00087 
00088   template <class T>
00089   inline
00090   bool
00091   EDCollection<T>::empty() const {
00092     return obj.empty();
00093   }
00094 
00095   template <class T>
00096   inline
00097   typename std::vector<T>::size_type
00098   EDCollection<T>::size() const {
00099     return obj.size();
00100   }
00101 
00102   template <class T>
00103   inline
00104   typename std::vector<T>::size_type
00105   EDCollection<T>::capacity() const {
00106     return obj.capacity();
00107   }
00108 
00109   template <class T>
00110   inline
00111   void
00112   EDCollection<T>::reserve(typename std::vector<T>::size_type n) {
00113     obj.reserve(n);
00114   }
00115 
00116   template <class T>
00117   inline
00118   T& 
00119   EDCollection<T>::operator[](size_type i) {
00120     return obj[i];
00121   }
00122 
00123   template <class T>
00124   inline
00125   T const& 
00126   EDCollection<T>::operator[](size_type i) const {
00127     return obj[i];
00128   }
00129 
00130   template <class T>
00131   inline
00132   T& 
00133   EDCollection<T>::at(size_type i) {
00134     return obj.at(i);
00135   }
00136 
00137   template <class T>
00138   inline
00139   T const& 
00140   EDCollection<T>::at(size_type i) const {
00141     return obj.at(i);
00142   }
00143 
00144   template <class T>
00145   inline
00146   typename std::vector<T>::const_iterator
00147   EDCollection<T>::begin() const {
00148     return obj.begin();
00149   }
00150 
00151   template <class T>
00152   inline
00153   typename std::vector<T>::const_iterator
00154   EDCollection<T>::end() const {
00155     return obj.end();
00156   }
00157 
00158   // Free swap function
00159   template <class T>
00160   inline
00161   void
00162   swap(EDCollection<T>& a, EDCollection<T>& b) 
00163   {
00164     a.swap(b);
00165   }
00166 
00167 }
00168 
00169 #endif