CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
PtrVectorBase.h
Go to the documentation of this file.
1 #ifndef DataFormats_Common_PtrVectorBase_h
2 #define DataFormats_Common_PtrVectorBase_h
3 // -*- C++ -*-
4 //
5 // Package: Common
6 // Class : PtrVectorBase
7 //
16 //
17 // Original Author: Chris Jones
18 // Created: Wed Oct 24 15:26:45 EDT 2007
19 //
20 
21 // user include files
23 
24 // system include files
25 #include <typeinfo>
26 #include <vector>
27 #include <cassert>
28 
29 // forward declarations
30 
31 namespace edm {
32  class PtrVectorBase {
33 
34  public:
35  typedef unsigned long key_type;
37 
38  explicit PtrVectorBase(ProductID const& productID, void const* prodPtr = 0,
39  EDProductGetter const* prodGetter = 0) :
40  core_(productID, prodPtr, prodGetter, false), indicies_() {}
41 
42  virtual ~PtrVectorBase();
43 
44  // ---------- const member functions ---------------------
46  bool isNull() const {return !isNonnull(); }
47 
49  //bool isNonnull() const {return id().isValid(); }
50  bool isNonnull() const { return core_.isNonnull(); }
51 
53  bool operator!() const {return isNull();}
54 
56  ProductID id() const {return core_.id();}
57 
59  EDProductGetter const* productGetter() const {return core_.productGetter();}
60 
61  bool hasCache() const { return !cachedItems_.empty(); }
62 
65  bool isAvailable() const;
66 
68  bool empty() const {return indicies_.empty();}
69 
71  size_type size() const {return indicies_.size();}
72 
74  size_type capacity() const {return indicies_.capacity();}
75 
77  void clear() { core_ = RefCore(); indicies_.clear(); cachedItems_.clear(); }
78 
79  bool operator==(PtrVectorBase const& iRHS) const;
80  // ---------- static member functions --------------------
81 
82  // ---------- member functions ---------------------------
84  void reserve(size_type n) {indicies_.reserve(n); cachedItems_.reserve(n);}
85 
86  void setProductGetter(EDProductGetter* iGetter) const { core_.setProductGetter(iGetter); }
87 
88  bool isTransient() const {return core_.isTransient();}
89 
90  void const* product() const {
91  return 0;
92  }
93 
94  protected:
95  PtrVectorBase();
96 
98  void swap(PtrVectorBase& other);
99 
100  void push_back_base(RefCore const& core, key_type iKey, void const* iData);
101 
102  std::vector<void const*>::const_iterator void_begin() const {
103  getProduct_();
105  return cachedItems_.begin();
106  }
107  std::vector<void const*>::const_iterator void_end() const {
108  getProduct_();
110  return cachedItems_.end();
111  }
112 
113  template<typename TPtr>
114  TPtr makePtr(unsigned long iIndex) const {
115  if (isTransient()) {
116  return TPtr(reinterpret_cast<typename TPtr::value_type const*>(cachedItems_[iIndex]),
117  indicies_[iIndex]);
118  }
119  if (hasCache() && (cachedItems_[iIndex] != nullptr || productGetter() == nullptr)) {
120  return TPtr(this->id(),
121  reinterpret_cast<typename TPtr::value_type const*>(cachedItems_[iIndex]),
122  indicies_[iIndex]);
123  }
124  return TPtr(this->id(), indicies_[iIndex], productGetter());
125  }
126 
127  template<typename TPtr>
128  TPtr makePtr(std::vector<void const*>::const_iterator const iIt) const {
129  if (isTransient()) {
130  return TPtr(reinterpret_cast<typename TPtr::value_type const*>(*iIt),
131  indicies_[iIt - cachedItems_.begin()]);
132  }
133  if (hasCache() && (*iIt != nullptr || productGetter() == nullptr)) {
134  return TPtr(this->id(),
135  reinterpret_cast<typename TPtr::value_type const*>(*iIt),
136  indicies_[iIt - cachedItems_.begin()]);
137  }
138  return TPtr(this->id(), indicies_[iIt - cachedItems_.begin()], productGetter());
139  }
140 
141  private:
142  void getProduct_() const;
143  //virtual std::type_info const& typeInfo() const = 0;
144  virtual std::type_info const& typeInfo() const {
145  assert(false);
146  return *reinterpret_cast<const std::type_info*>(0);
147  }
148 
149  void checkCachedItems() const;
150 
151  // ---------- member data --------------------------------
153  std::vector<key_type> indicies_;
154  mutable std::vector<void const*> cachedItems_;
155  };
156 }
157 
158 #endif
void push_back_base(RefCore const &core, key_type iKey, void const *iData)
size_type size() const
Size of the RefVector.
Definition: PtrVectorBase.h:71
std::vector< void const * >::const_iterator void_begin() const
PtrVectorBase(ProductID const &productID, void const *prodPtr=0, EDProductGetter const *prodGetter=0)
Definition: PtrVectorBase.h:38
bool isNull() const
Checks for null.
Definition: PtrVectorBase.h:46
TPtr makePtr(unsigned long iIndex) const
bool empty() const
Is the RefVector empty.
Definition: PtrVectorBase.h:68
void swap(PtrVectorBase &other)
swap
bool isNonnull() const
Definition: RefCore.h:43
virtual std::type_info const & typeInfo() const
void getProduct_() const
bool isTransient() const
Definition: PtrVectorBase.h:88
ProductID id() const
Accessor for product ID.
Definition: PtrVectorBase.h:56
bool operator!() const
Checks for null.
Definition: PtrVectorBase.h:53
bool isNonnull() const
Checks for non-null.
Definition: PtrVectorBase.h:50
bool isAvailable() const
std::vector< key_type > indicies_
bool operator==(PtrVectorBase const &iRHS) const
std::vector< void const * > cachedItems_
void setProductGetter(EDProductGetter *iGetter) const
Definition: PtrVectorBase.h:86
size_type capacity() const
Capacity of the RefVector.
Definition: PtrVectorBase.h:74
virtual ~PtrVectorBase()
std::vector< void const * >::const_iterator void_end() const
bool hasCache() const
Definition: PtrVectorBase.h:61
TPtr makePtr(std::vector< void const * >::const_iterator const iIt) const
EDProductGetter const * productGetter() const
Definition: RefCore.h:53
unsigned long key_type
Definition: PtrVectorBase.h:35
ProductID id() const
Definition: RefCore.h:29
void reserve(size_type n)
Reserve space for RefVector.
Definition: PtrVectorBase.h:84
bool isTransient() const
Definition: RefCore.h:75
void clear()
Clear the PtrVector.
Definition: PtrVectorBase.h:77
void checkCachedItems() const
void setProductGetter(EDProductGetter const *prodGetter) const
Definition: RefCore.cc:161
volatile std::atomic< bool > shutdown_flag false
EDProductGetter const * productGetter() const
Accessor for product getter.
Definition: PtrVectorBase.h:59
void const * product() const
Definition: PtrVectorBase.h:90