Go to the documentation of this file.00001 #ifndef DataFormats_Common_RefVectorBase_h
00002 #define DataFormats_Common_RefVectorBase_h
00003
00004
00005
00006
00007
00008
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
00017 namespace edm {
00018
00019 class EDProductGetter;
00020 template <typename KEY>
00021 class RefVectorBase {
00022 public:
00023 typedef std::vector<KEY > keys_type;
00024 typedef KEY key_type;
00025 typedef typename keys_type::size_type size_type;
00027 RefVectorBase() : product_(), keys_() {}
00028
00029 explicit RefVectorBase(ProductID const& productID, void const* prodPtr = 0,
00030 EDProductGetter const* prodGetter = 0) :
00031 product_(productID, prodPtr, prodGetter, false), keys_() {}
00032
00034 ~RefVectorBase() {}
00035
00037 RefCore const& refCore() const {return product_;}
00038
00040 keys_type const& keys() const {return keys_;}
00041
00043 bool empty() const {return keys_.empty();}
00044
00046 size_type size() const {return keys_.size();}
00047
00048 void pushBack(RefCore const& product, KEY const& key) {
00049 product_.pushBackItem(product, true);
00050 keys_.push_back(key);
00051 }
00052
00054 size_type capacity() const {return keys_.capacity();}
00055
00057 void reserve(size_type n) {keys_.reserve(n);}
00058
00060 typename keys_type::iterator eraseAtIndex(size_type index) {
00061 return keys_.erase(keys_.begin() + index);
00062 }
00063
00065 void clear() {
00066 keys_.clear();
00067 product_ = RefCore();
00068 }
00069
00071 void swap(RefVectorBase<KEY> & other) {
00072 product_.swap(other.product_);
00073 keys_.swap(other.keys_);
00074 }
00075
00077 RefVectorBase& operator=(RefVectorBase const& rhs) {
00078 RefVectorBase temp(rhs);
00079 this->swap(temp);
00080 return *this;
00081 }
00082
00083
00084 CMS_CLASS_VERSION(10)
00085
00086 private:
00087 RefCore product_;
00088 keys_type keys_;
00089 };
00090
00092 template<typename KEY>
00093 bool
00094 operator==(RefVectorBase<KEY> const& lhs, RefVectorBase<KEY> const& rhs) {
00095 return lhs.refCore() == rhs.refCore() && lhs.keys() == rhs.keys();
00096 }
00097
00099 template<typename KEY>
00100 bool
00101 operator!=(RefVectorBase<KEY> const& lhs, RefVectorBase<KEY> const& rhs) {
00102 return !(lhs == rhs);
00103 }
00104
00106 template<typename KEY>
00107 inline
00108 void
00109 swap(RefVectorBase<KEY> & a, RefVectorBase<KEY> & b) {
00110 a.swap(b);
00111 }
00112
00113 }
00114 #endif