test
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 
63  bool hasProductCache() const { return 0 == core_.productPtr(); }
64 
67  bool isAvailable() const { return core_.isAvailable(); }
68 
70  bool empty() const {return indicies_.empty();}
71 
73  size_type size() const {return indicies_.size();}
74 
76  size_type capacity() const {return indicies_.capacity();}
77 
79  void clear() { core_ = RefCore(); indicies_.clear(); cachedItems_.clear(); }
80 
81  bool operator==(PtrVectorBase const& iRHS) const;
82  // ---------- static member functions --------------------
83 
84  // ---------- member functions ---------------------------
86  void reserve(size_type n) {indicies_.reserve(n); cachedItems_.reserve(n);}
87 
88  void setProductGetter(EDProductGetter* iGetter) const { core_.setProductGetter(iGetter); }
89 
90  bool isTransient() const {return core_.isTransient();}
91 
92  void const* product() const {
93  return 0;
94  }
95 
96  protected:
97  PtrVectorBase();
98 
100  void swap(PtrVectorBase& other);
101 
102  void push_back_base(RefCore const& core, key_type iKey, void const* iData);
103 
104  std::vector<void const*>::const_iterator void_begin() const {
105  getProduct_();
106  return cachedItems_.begin();
107  }
108  std::vector<void const*>::const_iterator void_end() const {
109  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()) {
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()) {
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  // ---------- member data --------------------------------
150  std::vector<key_type> indicies_;
151  mutable std::vector<void const*> cachedItems_;
152  };
153 }
154 
155 #endif
size_type size() const
Size of the RefVector.
Definition: PtrVectorBase.h:73
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
bool operator==(PtrVectorBase const &iRHS) const
TPtr makePtr(unsigned long iIndex) const
bool hasProductCache() const
Definition: PtrVectorBase.h:63
bool empty() const
Is the RefVector empty.
Definition: PtrVectorBase.h:70
bool isNonnull() const
Definition: RefCore.h:43
virtual std::type_info const & typeInfo() const
bool isTransient() const
Definition: PtrVectorBase.h:90
void getProduct_() const
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
Definition: PtrVectorBase.h:67
std::vector< key_type > indicies_
void const * productPtr() const
Definition: RefCore.h:32
bool isAvailable() const
Definition: RefCore.cc:112
std::vector< void const * > cachedItems_
void setProductGetter(EDProductGetter *iGetter) const
Definition: PtrVectorBase.h:88
void push_back_base(RefCore const &core, key_type iKey, void const *iData)
size_type capacity() const
Capacity of the RefVector.
Definition: PtrVectorBase.h:76
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:86
bool isTransient() const
Definition: RefCore.h:69
void clear()
Clear the PtrVector.
Definition: PtrVectorBase.h:79
virtual ~PtrVectorBase()
void setProductGetter(EDProductGetter const *prodGetter) const
Definition: RefCore.cc:118
void swap(PtrVectorBase &other)
swap
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:92