CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
IndirectVectorHolder.h
Go to the documentation of this file.
1 #ifndef DataFormats_Common_IndirectVectorHolder_h
2 #define DataFormats_Common_IndirectVectorHolder_h
7 #include <memory>
8 
9 namespace edm {
10  namespace reftobase {
11 
12  template <typename T>
13  class IndirectVectorHolder : public BaseVectorHolder<T> {
14  public:
16  typedef typename base_type::size_type size_type;
20 
23  IndirectVectorHolder(std::shared_ptr<RefVectorHolderBase> p);
25  ~IndirectVectorHolder() override;
27  void swap(IndirectVectorHolder& other);
28  BaseVectorHolder<T>* clone() const override;
29  BaseVectorHolder<T>* cloneEmpty() const override;
30  ProductID id() const override;
31  EDProductGetter const* productGetter() const override;
32  bool empty() const override;
33  size_type size() const override;
34  void clear() override;
35  base_ref_type const at(size_type idx) const override;
36  std::unique_ptr<reftobase::RefVectorHolderBase> vectorHolder() const override {
37  return std::unique_ptr<reftobase::RefVectorHolderBase>(helper_->clone());
38  }
39  void push_back(const BaseHolder<T>* r) override {
40  typedef IndirectHolder<T> holder_type;
41  const holder_type* h = dynamic_cast<const holder_type*>(r);
42  if (h == nullptr)
44  "In IndirectHolder<T> trying to push_back wrong reference type");
45  helper_->push_back(h->helper_);
46  }
47 
50  bool isAvailable() const override { return helper_->isAvailable(); }
51 
52  //Used by ROOT storage
54 
55  private:
58 
59  public:
60  struct const_iterator_imp_specific : public const_iterator_imp {
61  typedef ptrdiff_t difference_type;
66  void increase() override { ++i; }
67  void decrease() override { --i; }
68  void increase(difference_type d) override { i += d; }
69  void decrease(difference_type d) override { i -= d; }
70  bool equal_to(const const_iterator_imp* o) const override { return i == dc(o); }
71  bool less_than(const const_iterator_imp* o) const override { return i < dc(o); }
72  void assign(const const_iterator_imp* o) override { i = dc(o); }
73  base_ref_type deref() const override { return base_ref_type(*i); }
74  difference_type difference(const const_iterator_imp* o) const override { return i - dc(o); }
75 
76  private:
77  const typename RefVectorHolderBase::const_iterator& dc(const const_iterator_imp* o) const {
78  if (o == nullptr) {
80  "In IndirectVectorHolder trying to dereference a null pointer");
81  }
82  const const_iterator_imp_specific* oo = dynamic_cast<const const_iterator_imp_specific*>(o);
83  if (oo == nullptr) {
85  "In IndirectVectorHolder trying to cast iterator to wrong type ");
86  }
87  return oo->i;
88  }
90  };
91 
92  const_iterator begin() const override {
94  }
96  };
97 
98  template <typename T>
100 
101  template <typename T>
102  IndirectVectorHolder<T>::IndirectVectorHolder(std::shared_ptr<RefVectorHolderBase> p)
103  : BaseVectorHolder<T>(), helper_(p->clone()) {}
104 
105  template <typename T>
107 
108  template <typename T>
110  : BaseVectorHolder<T>(), helper_(other.helper_->clone()) {}
111 
112  template <typename T>
114  delete helper_;
115  }
116 
117  template <typename T>
119  this->BaseVectorHolder<T>::swap(other);
120  std::swap(helper_, other.helper_);
121  }
122 
123  template <typename T>
126  swap(temp);
127  return *this;
128  }
129 
130  template <typename T>
132  return new IndirectVectorHolder<T>(*this);
133  }
134 
135  template <typename T>
137  return new IndirectVectorHolder<T>(helper_->cloneEmpty());
138  }
139 
140  template <typename T>
142  return helper_->id();
143  }
144 
145  template <typename T>
147  return helper_->productGetter();
148  }
149 
150  template <typename T>
152  return helper_->empty();
153  }
154 
155  template <typename T>
157  return helper_->size();
158  }
159 
160  template <typename T>
162  return helper_->clear();
163  }
164 
165  template <typename T>
167  return helper_ ? helper_->template getRef<T>(idx) : typename IndirectVectorHolder<T>::base_ref_type();
168  }
169 
170  // Free swap function
171  template <typename T>
173  lhs.swap(rhs);
174  }
175  } // namespace reftobase
176 } // namespace edm
177 
178 #endif
std::unique_ptr< reftobase::RefVectorHolderBase > vectorHolder() const override
virtual RefVectorHolderBase * clone() const =0
const_iterator end() const override
void push_back(const BaseHolder< T > *r) override
base_type::const_iterator const_iterator
#define CMS_CLASS_VERSION(_version_)
base_ref_type const at(size_type idx) 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:84
const_iterator begin() const override
tuple d
Definition: ztail.py:151
IndirectVectorHolder & operator=(IndirectVectorHolder const &rhs)
EDProductGetter const * productGetter() const override
void swap(edm::DataFrameContainer &lhs, edm::DataFrameContainer &rhs)
difference_type difference(const const_iterator_imp *o) const override
bool less_than(const const_iterator_imp *o) const override
const_iterator_imp_specific(const typename RefVectorHolderBase::const_iterator &it)
const RefVectorHolderBase::const_iterator & dc(const const_iterator_imp *o) const
bool equal_to(const const_iterator_imp *o) const override
void swap(IndirectVectorHolder &other)
virtual const_iterator begin() const =0
TEveGeoShape * clone(const TEveElement *element, TEveElement *parent)
Definition: eve_macros.cc:135
BaseVectorHolder< T > * clone() const override
virtual const_iterator end() const =0
virtual void push_back(RefHolderBase const *r)=0
virtual bool isAvailable() const =0
BaseVectorHolder< T > * cloneEmpty() const override
ProductIndex id() const
Definition: ProductID.h:35
void swap(BaseVectorHolder &)
The Signals That Services Can Subscribe To This is based on ActivityRegistry h
Helper function to determine trigger accepts.
Definition: Activities.doc:4
long double T
void swap(BaseHolder< T > &lhs, BaseHolder< T > &rhs)
Definition: BaseHolder.h:105