CMS 3D CMS Logo

RefVectorHolder.h
Go to the documentation of this file.
1 #ifndef DataFormats_Common_RefVectorHolder_h
2 #define DataFormats_Common_RefVectorHolder_h
3 
8 
9 namespace edm {
10  namespace reftobase {
11  class RefHolderBase;
12  template <typename REF> class RefHolder;
13 
14  template<typename REFV>
16  public:
18  }
19  RefVectorHolder(REFV const& refs) : RefVectorHolderBase(), refs_(refs) {
20  }
21  explicit RefVectorHolder(ProductID const& iId) : RefVectorHolderBase(), refs_(iId) {
22  }
23  ~RefVectorHolder() override { }
24  void swap(RefVectorHolder& other);
26  bool empty() const override;
27  size_type size() const override;
28  void clear() override;
29  void push_back(RefHolderBase const* r) override;
30  void reserve(size_type n) override;
31  ProductID id() const override;
32  EDProductGetter const* productGetter() const override;
33  RefVectorHolder<REFV> * clone() const override;
34  RefVectorHolder<REFV> * cloneEmpty() const override;
35  void setRefs(REFV const& refs);
36  size_t keyForIndex(size_t idx) const override;
37 
38  //Needed for ROOT storage
40 
41  private:
43 
44  public:
45  struct const_iterator_imp_specific : public const_iterator_imp {
46  typedef ptrdiff_t difference_type;
48  explicit const_iterator_imp_specific(typename REFV::const_iterator const& it) : i (it) { }
50  const_iterator_imp_specific * clone() const override { return new const_iterator_imp_specific(i); }
51  void increase() override { ++i; }
52  void decrease() override { --i; }
53  void increase(difference_type d) override { i += d; }
54  void decrease(difference_type d) override { i -= d; }
55  bool equal_to(const_iterator_imp const* o) const override { return i == dc(o); }
56  bool less_than(const_iterator_imp const* o) const override { return i < dc(o); }
57  void assign(const_iterator_imp const* o) override { i = dc(o); }
58  std::shared_ptr<RefHolderBase> deref() const override;
59  difference_type difference(const_iterator_imp const* o) const override { return i - dc(o); }
60  private:
61  typename REFV::const_iterator const& dc(const_iterator_imp const* o) const {
62  if (o == nullptr) {
64  "In RefVectorHolder trying to dereference a null pointer\n");
65  }
66  const_iterator_imp_specific const* oo = dynamic_cast<const_iterator_imp_specific const*>(o);
67  if (oo == nullptr) {
69  "In RefVectorHolder trying to cast iterator to wrong type\n");
70  }
71  return oo->i;
72  }
73  typename REFV::const_iterator i;
74  };
75 
77 
78  const_iterator begin() const override {
80  }
81  const_iterator end() const override {
83  }
84 
87  bool isAvailable() const override { return refs_.isAvailable(); }
88 
89  private:
90  std::shared_ptr<reftobase::RefHolderBase> refBase(size_t idx) const override;
91  REFV refs_;
92  };
93 
94  //
95  // implementations for RefVectorHolder<REFV>
96  //
97 
98  template <typename REFV>
99  inline
101  this->RefVectorHolderBase::swap(other);
102  refs_.swap(other.refs_);
103  }
104 
105  template <typename REFV>
106  inline
109  this->swap(temp);
110  return *this;
111  }
112 
113  template<typename REFV>
114  inline
116  return refs_.empty();
117  }
118 
119  template<typename REFV>
120  inline
122  return refs_.size();
123  }
124 
125  template<typename REFV>
126  inline
128  return refs_.clear();
129  }
130 
131  template<typename REFV>
132  inline
134  typename REFV::size_type s = n;
135  refs_.reserve(s);
136  }
137 
138  template<typename REFV>
139  inline
141  return refs_.id();
142  }
143 
144  template<typename REFV>
145  inline
147  return refs_.productGetter();
148  }
149 
150  template<typename REFV>
151  inline
153  return new RefVectorHolder<REFV>(*this);
154  }
155 
156  template<typename REFV>
157  inline
159  return new RefVectorHolder<REFV>(id());
160  }
161 
162  template<typename REFV>
163  inline
164  void RefVectorHolder<REFV>::setRefs(REFV const& refs) {
165  refs_ = refs;
166  }
167 
168  template <typename REFV>
169  inline
171  return refs_[idx].key();
172  }
173 
174  // Free swap function
175  template <typename REFV>
176  inline
177  void
179  lhs.swap(rhs);
180  }
181  }
182 }
183 
185 
186 namespace edm {
187  namespace reftobase {
188 
189  template<typename REFV>
191  typedef typename REFV::value_type REF;
192  RefHolder<REF> const* rh = dynamic_cast<RefHolder<REF> const*>(h);
193  if(rh == nullptr) {
195  "RefVectorHolder: attempting to cast a RefHolderBase "
196  "to an invalid type.\nExpected: ",
197  typeid(REF).name(),
198  "\n");
199  }
200  refs_.push_back(rh->getRef());
201  }
202 
203  template <typename REFV>
204  std::shared_ptr<RefHolderBase>
206  return std::shared_ptr<RefHolderBase>(std::make_shared<RefHolder<typename REFV::value_type> >(refs_[idx]));
207  }
208 
209  template<typename REFV>
210  std::shared_ptr<RefHolderBase>
212  return std::shared_ptr<RefHolderBase>(std::make_shared<RefHolder<typename REFV::value_type> >(*i));
213  }
214  }
215 }
216 
217 #endif
RefVectorHolderBase::const_iterator const_iterator
void assign(const_iterator_imp const *o) override
FWCore Framework interface EventSetupRecordImplementation h
Helper function to determine trigger accepts.
void swap(RefVectorHolderBase &)
REF const & getRef() const
Definition: RefHolder_.h:108
const_iterator end() const override
RefVectorHolder & operator=(RefVectorHolder const &rhs)
size_type size() const override
difference_type difference(const_iterator_imp const *o) const override
#define CMS_CLASS_VERSION(_version_)
void reserve(size_type n) override
bool equal_to(const_iterator_imp const *o) const override
uint16_t size_type
RefVectorHolder< REFV > * clone() const override
static void throwThis(Code category, char const *message0="", char const *message1="", char const *message2="", char const *message3="", char const *message4="")
Definition: EDMException.cc:82
RefVectorHolder< REFV > * cloneEmpty() const override
void setRefs(REFV const &refs)
const_iterator_imp_specific * clone() const override
size_t keyForIndex(size_t idx) const override
EDProductGetter const * productGetter() const override
bool less_than(const_iterator_imp const *o) const override
std::shared_ptr< reftobase::RefHolderBase > refBase(size_t idx) const override
RefVectorHolder(ProductID const &iId)
bool isAvailable() const override
std::shared_ptr< RefHolderBase > deref() const override
const_iterator_imp_specific(typename REFV::const_iterator const &it)
void swap(RefVectorHolder &other)
HLT enums.
REFV::const_iterator const & dc(const_iterator_imp const *o) const
void push_back(RefHolderBase const *r) override
ProductID id() const override
const_iterator begin() const override