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 
7 #include <memory>
8 
9 namespace edm {
10  template<typename T> class RefToBase;
11  namespace reftobase {
13  public:
14  virtual ~RefVectorHolderBase() {}
15  typedef size_t size_type;
17  void swap(RefVectorHolderBase&) {} // nothing to swap
18  virtual bool empty() const = 0;
19  virtual size_type size() const = 0;
20  virtual void clear() = 0;
21  virtual void reserve(size_type n) = 0;
22  virtual ProductID id() const = 0;
23  virtual EDProductGetter const* productGetter() const = 0;
24  virtual RefVectorHolderBase* clone() const = 0;
25  virtual RefVectorHolderBase* cloneEmpty() const = 0;
26  virtual void push_back(RefHolderBase const* r) = 0;
27  // the following structure is public
28  // to allow dictionary to compile
29  // protected:
31  typedef ptrdiff_t difference_type;
33  virtual ~const_iterator_imp() { }
34  virtual const_iterator_imp* clone() const = 0;
35  virtual void increase() = 0;
36  virtual void decrease() = 0;
37  virtual void increase(difference_type d) = 0;
38  virtual void decrease(difference_type d) = 0;
39  virtual bool equal_to(const_iterator_imp const*) const = 0;
40  virtual bool less_than(const_iterator_imp const*) const = 0;
41  virtual void assign(const_iterator_imp const*) = 0;
42  virtual std::shared_ptr<RefHolderBase> deref() const = 0;
43  virtual difference_type difference(const_iterator_imp const*) const = 0;
44  };
45 
46  struct const_iterator : public std::iterator <std::random_access_iterator_tag, void*>{
47  typedef std::shared_ptr<RefHolderBase> value_type;
48  typedef std::ptrdiff_t difference_type;
51  const_iterator(const_iterator const& it) : i(it.isValid() ? it.i->clone() : nullptr) { }
52  ~const_iterator() { delete i; }
54  if(isInvalid()) i = it.i;
55  else i->assign(it.i);
56  return *this;
57  }
59  if(isInvalid())
61  "Trying to increment an inavlid RefToBaseVector<T>::const_iterator\n");
62  i->increase();
63  return *this;
64  }
66  if(isInvalid())
68  "Trying to postincrement an inavlid RefToBaseVector<T>::const_iterator\n");
69  const_iterator ci = *this;
70  i->increase();
71  return ci;
72  }
74  if(isInvalid())
76  "Trying to decrement an inavlid RefToBaseVector<T>::const_iterator\n");
77  i->decrease();
78  return *this;
79  }
81  if(isInvalid())
83  "Trying to postdecrement an inavlid RefToBaseVector<T>::const_iterator\n");
84  const_iterator ci = *this;
85  i->decrease();
86  return ci;
87  }
88  difference_type operator-(const_iterator const& o) const {
89  if(isInvalid() && o.isInvalid()) return 0;
90  if(isInvalid() || o.isInvalid())
92  "Trying to compute difference with an inavlid RefToBaseVector<T>::const_iterator\n");
93  return i->difference(o.i);
94  }
95  const_iterator operator+(difference_type n) const {
96  if(isInvalid())
98  "Trying to compute sum with an inavlid RefToBaseVector<T>::const_iterator\n");
99  const_iterator_imp* ii = i->clone();
100  ii->increase(n);
101  return const_iterator(ii);
102  }
103  const_iterator operator-(difference_type n) const {
104  if(isInvalid())
106  "Trying to compute difference with an inavlid RefToBaseVector<T>::const_iterator\n");
107  const_iterator_imp* ii = i->clone();
108  ii->decrease(n);
109  return const_iterator(ii);
110  }
111  bool operator<(const_iterator const& o) const {
112  if(isInvalid() && o.isInvalid()) return false;
113  if(isInvalid() || o.isInvalid())
115  "Trying to compute < operator with an inavlid RefToBaseVector<T>::const_iterator\n");
116  return i->less_than(o.i);
117  }
118  bool operator==(const const_iterator& ci) const {
119  if(isInvalid() && ci.isInvalid()) return true;
120  if(isInvalid() || ci.isInvalid()) return false;
121  return i->equal_to(ci.i);
122  }
123  bool operator!=(const const_iterator& ci) const {
124  if(isInvalid() && ci.isInvalid()) return false;
125  if(isInvalid() || ci.isInvalid()) return true;
126  return ! i->equal_to(ci.i);
127  }
128  value_type operator*() const {
129  if(isInvalid())
131  "Trying to dereference an inavlid RefToBaseVector<T>::const_iterator\n");
132  return i->deref();
133  }
134  const_iterator& operator-=(difference_type d) {
135  if(isInvalid())
137  "Trying to decrement an inavlid RefToBaseVector<T>::const_iterator\n");
138  i->decrease(d);
139  return *this;
140  }
141  const_iterator& operator+=(difference_type d) {
142  if(isInvalid())
144  "Trying to increment an inavlid RefToBaseVector<T>::const_iterator\n");
145  i->increase(d);
146  return *this;
147  }
148  bool isValid() const { return i != nullptr; }
149  bool isInvalid() const { return i == nullptr; }
150 
151  private:
153  };
154 
155  virtual const_iterator begin() const = 0;
156  virtual const_iterator end() const = 0;
157  template<typename T> RefToBase<T> getRef(size_t idx) const;
158  virtual size_t keyForIndex(size_t idx) const = 0;
159 
162  virtual bool isAvailable() const = 0;
163 
164  private:
165  virtual std::shared_ptr<reftobase::RefHolderBase> refBase(size_t idx) const = 0;
166  };
167 
168  template<typename T>
170  std::shared_ptr<reftobase::RefHolderBase> rb = refBase(idx);
171  return RefToBase<T>(rb);
172  }
173 
174  // Free swap function
175  inline
177  lhs.swap(rhs);
178  }
179  }
180 }
181 
182 #endif
virtual ProductID id() const =0
bool operator==(const const_iterator &ci) const
virtual std::shared_ptr< reftobase::RefHolderBase > refBase(size_t idx) const =0
void swap(RefVectorHolderBase &)
virtual size_t keyForIndex(size_t idx) const =0
virtual const_iterator begin() const =0
const_iterator operator-(difference_type n) const
#define nullptr
virtual size_type size() const =0
virtual bool equal_to(const_iterator_imp const *) const =0
bool operator!=(const const_iterator &ci) const
static void throwThis(Code category, char const *message0="", char const *message1="", char const *message2="", char const *message3="", char const *message4="")
virtual bool empty() const =0
virtual bool isAvailable() const =0
bool operator<(const_iterator const &o) const
virtual void assign(const_iterator_imp const *)=0
virtual EDProductGetter const * productGetter() const =0
const_iterator operator+(difference_type n) const
virtual difference_type difference(const_iterator_imp const *) const =0
ii
Definition: cuy.py:588
virtual const_iterator end() const =0
virtual void reserve(size_type n)=0
const_iterator & operator=(const_iterator const &it)
virtual RefVectorHolderBase * cloneEmpty() const =0
HLT enums.
virtual const_iterator_imp * clone() const =0
virtual void push_back(RefHolderBase const *r)=0
virtual std::shared_ptr< RefHolderBase > deref() const =0
RefToBase< T > getRef(size_t idx) const
difference_type operator-(const_iterator const &o) const
virtual bool less_than(const_iterator_imp const *) const =0
virtual RefVectorHolderBase * clone() const =0