Go to the documentation of this file.00001 #ifndef DataFormats_Common_PtrVectorBase_h
00002 #define DataFormats_Common_PtrVectorBase_h
00003
00004
00005
00006
00007
00016
00017
00018
00019
00020
00021
00022 #include <vector>
00023 #include <typeinfo>
00024
00025
00026 #include "DataFormats/Common/interface/RefCore.h"
00027
00028
00029
00030 namespace edm {
00031 class PtrVectorBase {
00032
00033 public:
00034 typedef unsigned long key_type;
00035 typedef key_type size_type;
00036
00037 explicit PtrVectorBase(ProductID const& productID, void const* prodPtr = 0,
00038 EDProductGetter const* prodGetter = 0) :
00039 core_(productID, prodPtr, prodGetter, false), indicies_() {}
00040
00041 virtual ~PtrVectorBase();
00042
00043
00045 bool isNull() const {return !isNonnull(); }
00046
00048
00049 bool isNonnull() const { return core_.isNonnull(); }
00050
00052 bool operator!() const {return isNull();}
00053
00055 ProductID id() const {return core_.id();}
00056
00058 EDProductGetter const* productGetter() const {return core_.productGetter();}
00059
00060 bool hasCache() const { return !cachedItems_.empty(); }
00061
00062 bool hasProductCache() const { return 0 == core_.productPtr(); }
00063
00066 bool isAvailable() const { return core_.isAvailable(); }
00067
00069 bool empty() const {return indicies_.empty();}
00070
00072 size_type size() const {return indicies_.size();}
00073
00075 size_type capacity() const {return indicies_.capacity();}
00076
00078 void clear() { core_ = RefCore(); indicies_.clear(); cachedItems_.clear(); }
00079
00080 bool operator==(PtrVectorBase const& iRHS) const;
00081
00082
00083
00085 void reserve(size_type n) {indicies_.reserve(n); cachedItems_.reserve(n);}
00086
00087 void setProductGetter(EDProductGetter* iGetter) const { core_.setProductGetter(iGetter); }
00088
00089 bool isTransient() const {return core_.isTransient();}
00090
00091 void const* product() const {
00092 return 0;
00093 }
00094
00095 protected:
00096 PtrVectorBase();
00097
00099 void swap(PtrVectorBase& other);
00100
00101 void push_back_base(RefCore const& core, key_type iKey, void const* iData);
00102
00103 std::vector<void const*>::const_iterator void_begin() const {
00104 getProduct_();
00105 return cachedItems_.begin();
00106 }
00107 std::vector<void const*>::const_iterator void_end() const {
00108 getProduct_();
00109 return cachedItems_.end();
00110 }
00111
00112 template<typename TPtr>
00113 TPtr makePtr(unsigned long iIndex) const {
00114 if (isTransient()) {
00115 return TPtr(reinterpret_cast<typename TPtr::value_type const*>(cachedItems_[iIndex]),
00116 indicies_[iIndex]);
00117 }
00118 if (hasCache()) {
00119 return TPtr(this->id(),
00120 reinterpret_cast<typename TPtr::value_type const*>(cachedItems_[iIndex]),
00121 indicies_[iIndex]);
00122 }
00123 return TPtr(this->id(), indicies_[iIndex], productGetter());
00124 }
00125
00126 template<typename TPtr>
00127 TPtr makePtr(std::vector<void const*>::const_iterator const iIt) const {
00128 if (isTransient()) {
00129 return TPtr(reinterpret_cast<typename TPtr::value_type const*>(*iIt),
00130 indicies_[iIt - cachedItems_.begin()]);
00131 }
00132 if (hasCache()) {
00133 return TPtr(this->id(),
00134 reinterpret_cast<typename TPtr::value_type const*>(*iIt),
00135 indicies_[iIt - cachedItems_.begin()]);
00136 }
00137 return TPtr(this->id(), indicies_[iIt - cachedItems_.begin()], productGetter());
00138 }
00139
00140 private:
00141 void getProduct_() const;
00142 virtual std::type_info const& typeInfo() const = 0;
00143
00144 RefCore core_;
00145 std::vector<key_type> indicies_;
00146 mutable std::vector<void const*> cachedItems_;
00147 };
00148 }
00149
00150 #endif