CMS 3D CMS Logo

/afs/cern.ch/work/a/aaltunda/public/www/CMSSW_6_2_5/src/DataFormats/Common/interface/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.19 2012/04/11 10:15:07 innocent Exp $
00009 
00010 ----------------------------------------------------------------------*/
00011 
00012 #include "DataFormats/Common/interface/CMS_CLASS_VERSION.h"
00013 #include "DataFormats/Common/interface/EDProductfwd.h"
00014 #include "DataFormats/Common/interface/RefCore.h"
00015 #include <vector>
00016 #include "FWCore/Utilities/interface/GCC11Compatibility.h"
00017 
00018 namespace edm {
00019 
00020   class EDProductGetter;
00021   template <typename KEY>
00022   class RefVectorBase {
00023   public:
00024     typedef std::vector<KEY > keys_type;
00025     typedef KEY key_type;
00026     typedef typename keys_type::size_type size_type;
00028     RefVectorBase() : product_(), keys_() {}
00029     RefVectorBase( RefVectorBase const & rhs) : product_(rhs.product_), keys_(rhs.keys_) {}
00030 #if defined(__GXX_EXPERIMENTAL_CXX0X__)
00031     RefVectorBase( RefVectorBase && rhs)  noexcept : product_(std::move(rhs.product_)), keys_(std::move(rhs.keys_)) {}
00032 #endif
00033 
00034     explicit RefVectorBase(ProductID const& productID, void const* prodPtr = 0,
00035                            EDProductGetter const* prodGetter = 0) :
00036       product_(productID, prodPtr, prodGetter, false), keys_() {}
00037 
00039     ~RefVectorBase() noexcept {}
00040 
00042     RefCore const& refCore() const {return product_;}
00043 
00045     keys_type const& keys() const {return keys_;}
00046 
00048     bool empty() const {return keys_.empty();}
00049 
00051     size_type size() const {return keys_.size();}
00052 
00053     void pushBack(RefCore const& product, KEY const& key) {
00054       product_.pushBackItem(product, true);
00055       keys_.push_back(key);
00056     }
00057 
00059     size_type capacity() const {return keys_.capacity();}
00060 
00062     void reserve(size_type n) {keys_.reserve(n);}
00063 
00065     typename keys_type::iterator eraseAtIndex(size_type index) {
00066       return keys_.erase(keys_.begin() + index);
00067     }
00068     
00070     void clear() {
00071       keys_.clear();
00072       product_ = RefCore();
00073     }
00074 
00076     void swap(RefVectorBase<KEY> & other)  noexcept {
00077       product_.swap(other.product_);
00078       keys_.swap(other.keys_);
00079     }
00080 
00082     RefVectorBase& operator=(RefVectorBase const& rhs) {
00083       RefVectorBase temp(rhs);
00084       this->swap(temp);
00085       return *this;
00086     }
00087 #if defined(__GXX_EXPERIMENTAL_CXX0X__)
00088     RefVectorBase& operator=(RefVectorBase && rhs)  noexcept {
00089       product_ = std::move(rhs.product_); 
00090       keys_ =std::move(rhs.keys_);
00091       return *this;
00092     }
00093 #endif
00094 
00095     //Needed for ROOT storage
00096     CMS_CLASS_VERSION(10)
00097 
00098   private:
00099     RefCore product_;
00100     keys_type keys_;
00101   };
00102 
00104   template<typename KEY>
00105   bool
00106   operator==(RefVectorBase<KEY> const& lhs, RefVectorBase<KEY> const& rhs) {
00107     return lhs.refCore() == rhs.refCore() && lhs.keys() == rhs.keys();
00108   }
00109 
00111   template<typename KEY>
00112   bool
00113   operator!=(RefVectorBase<KEY> const& lhs, RefVectorBase<KEY> const& rhs) {
00114     return !(lhs == rhs);
00115   }
00116 
00118   template<typename KEY>
00119   inline
00120   void
00121   swap(RefVectorBase<KEY> & a, RefVectorBase<KEY> & b) {
00122     a.swap(b);
00123   }
00124 
00125 }
00126 #endif