CMS 3D CMS Logo

BaseVectorHolder.h
Go to the documentation of this file.
1 #ifndef DataFormats_Common_BaseVectorHolder_h
2 #define DataFormats_Common_BaseVectorHolder_h
6 #include <cstddef>
7 #include <memory>
8 
9 namespace edm {
10  class ProductID;
11  template <typename T>
12  class RefToBase;
13  namespace reftobase {
14  template <typename T>
15  class BaseVectorHolder {
16  public:
17  typedef size_t size_type;
18  typedef T element_type;
21  virtual ~BaseVectorHolder() {}
22  virtual BaseVectorHolder* clone() const = 0;
23  virtual BaseVectorHolder* cloneEmpty() const = 0;
24  virtual base_ref_type const at(size_type idx) const = 0;
25  virtual bool empty() const = 0;
26 
27  virtual size_type size() const = 0;
28  //virtual size_type capacity() const = 0;
29  //virtual void reserve(size_type n) = 0;
30  virtual void clear() = 0;
31  virtual ProductID id() const = 0;
32  virtual EDProductGetter const* productGetter() const = 0;
33  void swap(BaseVectorHolder&) {} // nothing to swap
34 
35  // the following structure is public
36  // to allow dictionary to compile
37  // protected:
39  typedef ptrdiff_t difference_type;
41  virtual ~const_iterator_imp() {}
42  virtual const_iterator_imp* clone() const = 0;
43  virtual void increase() = 0;
44  virtual void decrease() = 0;
45  virtual void increase(difference_type d) = 0;
46  virtual void decrease(difference_type d) = 0;
47  virtual bool equal_to(const_iterator_imp const*) const = 0;
48  virtual bool less_than(const_iterator_imp const*) const = 0;
49  virtual void assign(const_iterator_imp const*) = 0;
50  virtual base_ref_type deref() const = 0;
51  virtual difference_type difference(const_iterator_imp const*) const = 0;
52  };
53 
54  struct const_iterator : public std::iterator<std::random_access_iterator_tag, RefToBase<T> > {
56  typedef std::unique_ptr<value_type> pointer;
57  typedef std::ptrdiff_t difference_type;
58 
59  const_iterator() : i(nullptr) {}
61  const_iterator(const_iterator const& it) : i(it.isValid() ? it.i->clone() : nullptr) {}
62  ~const_iterator() { delete i; }
64  if (this == &it) {
65  return *this;
66  }
67  if (isInvalid())
68  i = it.i;
69  else
70  i->assign(it.i);
71  return *this;
72  }
74  throwInvalidReference(isInvalid(), "increment");
75  i->increase();
76  return *this;
77  }
79  throwInvalidReference(isInvalid(), "postincrement");
80  const_iterator ci = *this;
81  i->increase();
82  return ci;
83  }
85  throwInvalidReference(isInvalid(), "decrement");
86  i->decrease();
87  return *this;
88  }
90  throwInvalidReference(isInvalid(), "postdecrement");
91  const_iterator ci = *this;
92  i->decrease();
93  return ci;
94  }
96  if (isInvalid() && o.isInvalid())
97  return 0;
98  throwInvalidReference(isInvalid() || o.isInvalid(), "compute difference with");
99  return i->difference(o.i);
100  }
102  throwInvalidReference(isInvalid(), "compute sum with");
104  ii->increase(n);
105  return const_iterator(ii);
106  }
108  throwInvalidReference(isInvalid(), "compute difference with");
110  ii->decrease(n);
111  return const_iterator(ii);
112  }
113  bool operator<(const_iterator const& o) const {
114  if (isInvalid() && o.isInvalid())
115  return false;
116  throwInvalidReference(isInvalid() || o.isInvalid(), "compute < operator with");
117  return i->less_than(o.i);
118  }
119  bool operator==(const_iterator const& ci) const {
120  if (isInvalid() && ci.isInvalid())
121  return true;
122  if (isInvalid() || ci.isInvalid())
123  return false;
124  return i->equal_to(ci.i);
125  }
126  bool operator!=(const_iterator const& ci) const {
127  if (isInvalid() && ci.isInvalid())
128  return false;
129  if (isInvalid() || ci.isInvalid())
130  return true;
131  return !i->equal_to(ci.i);
132  }
134  throwInvalidReference(isInvalid(), "dereference");
135  return i->deref();
136  }
137  pointer operator->() const { return pointer(new value_type(operator*())); }
139  throwInvalidReference(isInvalid(), "increment");
140  i->increase(d);
141  return *this;
142  }
144  throwInvalidReference(isInvalid(), "decrement");
145  i->decrease(d);
146  return *this;
147  }
148  bool isValid() const { return i != nullptr; }
149  bool isInvalid() const { return i == nullptr; }
150 
151  void throwInvalidReference(bool iIsInvalid, char const* iWhy) const {
152  if (iIsInvalid) {
154  errors::InvalidReference, "Trying to ", iWhy, " an invalid RefToBaseVector<T>::const_iterator");
155  }
156  }
157 
158  private:
160  };
161 
162  virtual const_iterator begin() const = 0;
163  virtual const_iterator end() const = 0;
164  virtual void push_back(BaseHolder<T> const*) = 0;
165  virtual std::unique_ptr<RefVectorHolderBase> vectorHolder() const = 0;
166 
169  virtual bool isAvailable() const = 0;
170 
171  //Used by ROOT storage
173  };
174 
175  // Free swap function
176  template <typename T>
177  inline void swap(BaseVectorHolder<T>& lhs, BaseVectorHolder<T>& rhs) {
178  lhs.swap(rhs);
179  }
180  } // namespace reftobase
181 } // namespace edm
182 
183 #endif
edm::reftobase::BaseVectorHolder::clone
virtual BaseVectorHolder * clone() const =0
edm::reftobase::BaseVectorHolder::const_iterator::operator-=
const_iterator & operator-=(difference_type d)
Definition: BaseVectorHolder.h:143
edm::reftobase::BaseVectorHolder::const_iterator::pointer
std::unique_ptr< value_type > pointer
Definition: BaseVectorHolder.h:56
dqmiodumpmetadata.n
n
Definition: dqmiodumpmetadata.py:28
edm::errors::InvalidReference
Definition: EDMException.h:39
edm::reftobase::BaseVectorHolder::size
virtual size_type size() const =0
edm::reftobase::BaseVectorHolder::const_iterator::isInvalid
bool isInvalid() const
Definition: BaseVectorHolder.h:149
edm
HLT enums.
Definition: AlignableModifier.h:19
edm::reftobase::BaseVectorHolder
Definition: BaseHolder.h:16
edm::reftobase::BaseVectorHolder::~BaseVectorHolder
virtual ~BaseVectorHolder()
Definition: BaseVectorHolder.h:21
edm::reftobase::BaseVectorHolder::const_iterator_imp::increase
virtual void increase()=0
edm::reftobase::BaseVectorHolder::id
virtual ProductID id() const =0
edm::reftobase::BaseVectorHolder::BaseVectorHolder
BaseVectorHolder()
Definition: BaseVectorHolder.h:20
edm::reftobase::BaseVectorHolder::cloneEmpty
virtual BaseVectorHolder * cloneEmpty() const =0
training_settings.idx
idx
Definition: training_settings.py:16
edm::reftobase::BaseVectorHolder::const_iterator::const_iterator
const_iterator()
Definition: BaseVectorHolder.h:59
EcalTangentSkim_cfg.o
o
Definition: EcalTangentSkim_cfg.py:36
edm::reftobase::BaseVectorHolder::size_type
size_t size_type
Definition: BaseVectorHolder.h:17
edm::reftobase::BaseVectorHolder::swap
void swap(BaseVectorHolder &)
Definition: BaseVectorHolder.h:33
EDMException.h
edm::EDProductGetter
Definition: EDProductGetter.h:32
edm::reftobase::BaseVectorHolder::const_iterator::operator*
value_type operator*() const
Definition: BaseVectorHolder.h:133
edm::reftobase::BaseVectorHolder::empty
virtual bool empty() const =0
edm::reftobase::BaseVectorHolder::const_iterator_imp::const_iterator_imp
const_iterator_imp()
Definition: BaseVectorHolder.h:40
edm::reftobase::BaseVectorHolder::const_iterator_imp::equal_to
virtual bool equal_to(const_iterator_imp const *) const =0
edm::reftobase::BaseVectorHolder::const_iterator_imp::decrease
virtual void decrease()=0
edm::reftobase::BaseVectorHolder::const_iterator::operator++
const_iterator & operator++()
Definition: BaseVectorHolder.h:73
edm::reftobase::BaseHolder
Definition: BaseHolder.h:29
edm::reftobase::BaseVectorHolder::const_iterator
Definition: BaseVectorHolder.h:54
CMS_CLASS_VERSION
#define CMS_CLASS_VERSION(_version_)
Definition: CMS_CLASS_VERSION.h:30
edm::reftobase::BaseVectorHolder::const_iterator::difference_type
std::ptrdiff_t difference_type
Definition: BaseVectorHolder.h:57
edm::reftobase::BaseVectorHolder::const_iterator::operator+=
const_iterator & operator+=(difference_type d)
Definition: BaseVectorHolder.h:138
edm::reftobase::BaseVectorHolder::const_iterator_imp::deref
virtual base_ref_type deref() const =0
edm::reftobase::BaseVectorHolder::base_ref_type
RefToBase< T > base_ref_type
Definition: BaseVectorHolder.h:19
edm::reftobase::BaseVectorHolder::const_iterator_imp::less_than
virtual bool less_than(const_iterator_imp const *) const =0
edm::reftobase::BaseVectorHolder::const_iterator::operator<
bool operator<(const_iterator const &o) const
Definition: BaseVectorHolder.h:113
edm::reftobase::BaseVectorHolder::const_iterator::operator+
const_iterator operator+(difference_type n) const
Definition: BaseVectorHolder.h:101
edm::reftobase::BaseVectorHolder::const_iterator::operator->
pointer operator->() const
Definition: BaseVectorHolder.h:137
BaseHolder.h
RefToBase
edm::reftobase::BaseVectorHolder::const_iterator::operator--
const_iterator & operator--()
Definition: BaseVectorHolder.h:84
edm::reftobase::BaseVectorHolder::push_back
virtual void push_back(BaseHolder< T > const *)=0
edm::reftobase::BaseVectorHolder::vectorHolder
virtual std::unique_ptr< RefVectorHolderBase > vectorHolder() const =0
edm::reftobase::BaseVectorHolder::element_type
T element_type
Definition: BaseVectorHolder.h:18
edm::reftobase::BaseVectorHolder::const_iterator::operator!=
bool operator!=(const_iterator const &ci) const
Definition: BaseVectorHolder.h:126
edm::reftobase::BaseVectorHolder::const_iterator_imp::difference_type
ptrdiff_t difference_type
Definition: BaseVectorHolder.h:39
edm::reftobase::BaseVectorHolder::const_iterator::const_iterator
const_iterator(const_iterator_imp *it)
Definition: BaseVectorHolder.h:60
edm::reftobase::BaseVectorHolder::const_iterator_imp::~const_iterator_imp
virtual ~const_iterator_imp()
Definition: BaseVectorHolder.h:41
edm::reftobase::BaseVectorHolder::const_iterator::~const_iterator
~const_iterator()
Definition: BaseVectorHolder.h:62
edm::reftobase::swap
void swap(BaseHolder< T > &lhs, BaseHolder< T > &rhs)
Definition: BaseHolder.h:111
edm::reftobase::BaseVectorHolder::productGetter
virtual EDProductGetter const * productGetter() const =0
CMS_CLASS_VERSION.h
edm::reftobase::BaseVectorHolder::end
virtual const_iterator end() const =0
edm::reftobase::BaseVectorHolder::const_iterator_imp::clone
virtual const_iterator_imp * clone() const =0
T
long double T
Definition: Basic3DVectorLD.h:48
edm::reftobase::BaseVectorHolder::const_iterator::isValid
bool isValid() const
Definition: BaseVectorHolder.h:148
edm::reftobase::BaseVectorHolder::const_iterator::value_type
base_ref_type value_type
Definition: BaseVectorHolder.h:55
edm::reftobase::BaseVectorHolder::const_iterator::operator-
const_iterator operator-(difference_type n) const
Definition: BaseVectorHolder.h:107
edm::reftobase::BaseVectorHolder::const_iterator_imp::assign
virtual void assign(const_iterator_imp const *)=0
edm::Exception::throwThis
static void throwThis(Code category, char const *message0="", char const *message1="", char const *message2="", char const *message3="", char const *message4="")
Definition: EDMException.cc:83
edm::reftobase::BaseVectorHolder::const_iterator::const_iterator
const_iterator(const_iterator const &it)
Definition: BaseVectorHolder.h:61
edm::reftobase::BaseVectorHolder::const_iterator::operator++
const_iterator operator++(int)
Definition: BaseVectorHolder.h:78
edm::reftobase::BaseVectorHolder::const_iterator::i
const_iterator_imp * i
Definition: BaseVectorHolder.h:159
edm::RefToBase
Definition: AssociativeIterator.h:54
edm::reftobase::BaseVectorHolder::const_iterator::throwInvalidReference
void throwInvalidReference(bool iIsInvalid, char const *iWhy) const
Definition: BaseVectorHolder.h:151
edm::reftobase::BaseVectorHolder::isAvailable
virtual bool isAvailable() const =0
ztail.d
d
Definition: ztail.py:151
edm::reftobase::BaseVectorHolder::const_iterator::operator--
const_iterator operator--(int)
Definition: BaseVectorHolder.h:89
edm::reftobase::BaseVectorHolder::const_iterator::operator-
difference_type operator-(const_iterator const &o) const
Definition: BaseVectorHolder.h:95
edm::reftobase::BaseVectorHolder::const_iterator_imp::difference
virtual difference_type difference(const_iterator_imp const *) const =0
edm::reftobase::BaseVectorHolder::const_iterator_imp
Definition: BaseVectorHolder.h:38
edm::reftobase::BaseVectorHolder::const_iterator::operator==
bool operator==(const_iterator const &ci) const
Definition: BaseVectorHolder.h:119
cuy.ii
ii
Definition: cuy.py:590
edm::ProductID
Definition: ProductID.h:27
edm::reftobase::BaseVectorHolder::begin
virtual const_iterator begin() const =0
edm::reftobase::BaseVectorHolder::clear
virtual void clear()=0
edm::reftobase::BaseVectorHolder::const_iterator::operator=
const_iterator & operator=(const_iterator const &it)
Definition: BaseVectorHolder.h:63
edm::reftobase::BaseVectorHolder::at
virtual const base_ref_type at(size_type idx) const =0