CMS 3D CMS Logo

RefVectorBase.h

Go to the documentation of this file.
00001 #ifndef DataFormats_Common_RefVectorBase_h
00002 #define DataFormats_Common_RefVectorBase_h
00003 
00004 /*----------------------------------------------------------------------
00005   
00006 RefVectorBase: Base class for a vector of interproduct references.
00007 
00008 $Id: RefVectorBase.h,v 1.15 2008/02/15 20:06:17 wmtan Exp $
00009 
00010 ----------------------------------------------------------------------*/
00011 
00012 #include "DataFormats/Common/interface/EDProductfwd.h"
00013 #include "DataFormats/Common/interface/RefCore.h"
00014 #include <vector>
00015 
00016 namespace edm {
00017 
00018   class EDProductGetter;
00019   template <typename KEY>
00020   class RefVectorBase {
00021   public:
00022     typedef std::vector<RefItem<KEY> > RefItems;
00023     typedef KEY key_type;
00024     typedef typename RefItems::size_type size_type;
00026     RefVectorBase() : product_(), items_() {}
00027 
00028     explicit RefVectorBase(ProductID const& productID, void const* prodPtr = 0,
00029                            EDProductGetter const* prodGetter = 0) :
00030       product_(productID, prodPtr, prodGetter, false), items_() {}
00031 
00033     ~RefVectorBase() {}
00034 
00036     RefCore const& refCore() const {return product_;}
00037 
00039     RefItems const& items() const {return items_;}
00040 
00042     bool empty() const {return items_.empty();}
00043 
00045     size_type size() const {return items_.size();}
00046 
00047     void pushBack(RefCore const& product, RefItem<KEY> const& item_) {
00048       product_.pushBackItem(product, true);
00049       items_.push_back(item_);
00050     }
00051 
00053     size_type capacity() const {return items_.capacity();}
00054 
00056     void reserve(size_type n) {items_.reserve(n);}
00057 
00059     typename RefItems::iterator eraseAtIndex(size_type index) {
00060       return items_.erase(items_.begin() + index);
00061     }
00062     
00064     void clear() {
00065       items_.clear();
00066       product_ = RefCore();
00067     }
00068 
00070     void swap(RefVectorBase<KEY> & other) {
00071       product_.swap(other.product_);
00072       items_.swap(other.items_);
00073     }
00074 
00076     RefVectorBase& operator=(RefVectorBase const& rhs) {
00077       RefVectorBase temp(rhs);
00078       this->swap(temp);
00079       return *this;
00080     }
00081 
00082   private:
00083     RefCore product_;
00084     RefItems items_;
00085   };
00086 
00088   template<typename KEY>
00089   bool
00090   operator==(RefVectorBase<KEY> const& lhs, RefVectorBase<KEY> const& rhs) {
00091     return lhs.refCore() == rhs.refCore() && lhs.items() == rhs.items();
00092   }
00093 
00095   template<typename KEY>
00096   bool
00097   operator!=(RefVectorBase<KEY> const& lhs, RefVectorBase<KEY> const& rhs) {
00098     return !(lhs == rhs);
00099   }
00100 
00102   template<typename KEY>
00103   inline
00104   void
00105   swap(RefVectorBase<KEY> & a, RefVectorBase<KEY> & b) {
00106     a.swap(b);
00107   }
00108 
00109 }
00110 #endif

Generated on Tue Jun 9 17:30:12 2009 for CMSSW by  doxygen 1.5.4