CMS 3D CMS Logo

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