CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
RefVectorHolderBase.h
Go to the documentation of this file.
1 #ifndef DataFormats_Common_RefVectorHolderBase_h
2 #define DataFormats_Common_RefVectorHolderBase_h
3 
7 
8 #include <memory>
9 
10 namespace edm {
11  template<typename T> 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(0) { }
52  const_iterator(const_iterator const& it) : i(it.isValid() ? it.i->clone() : 0) { }
53  ~const_iterator() { delete i; }
55  if(isInvalid()) i = it.i;
56  else i->assign(it.i);
57  return *this;
58  }
60  if(isInvalid())
62  "Trying to increment an inavlid RefToBaseVector<T>::const_iterator\n");
63  i->increase();
64  return *this;
65  }
67  if(isInvalid())
69  "Trying to postincrement an inavlid RefToBaseVector<T>::const_iterator\n");
70  const_iterator ci = *this;
71  i->increase();
72  return ci;
73  }
75  if(isInvalid())
77  "Trying to decrement an inavlid RefToBaseVector<T>::const_iterator\n");
78  i->decrease();
79  return *this;
80  }
82  if(isInvalid())
84  "Trying to postdecrement an inavlid RefToBaseVector<T>::const_iterator\n");
85  const_iterator ci = *this;
86  i->decrease();
87  return ci;
88  }
90  if(isInvalid() && o.isInvalid()) return 0;
91  if(isInvalid() || o.isInvalid())
93  "Trying to compute difference with an inavlid RefToBaseVector<T>::const_iterator\n");
94  return i->difference(o.i);
95  }
97  if(isInvalid())
99  "Trying to compute sum with an inavlid RefToBaseVector<T>::const_iterator\n");
101  ii->increase(n);
102  return const_iterator(ii);
103  }
105  if(isInvalid())
107  "Trying to compute difference with an inavlid RefToBaseVector<T>::const_iterator\n");
109  ii->decrease(n);
110  return const_iterator(ii);
111  }
112  bool operator<(const_iterator const& o) const {
113  if(isInvalid() && o.isInvalid()) return false;
114  if(isInvalid() || o.isInvalid())
116  "Trying to compute < operator with an inavlid RefToBaseVector<T>::const_iterator\n");
117  return i->less_than(o.i);
118  }
119  bool operator==(const const_iterator& ci) const {
120  if(isInvalid() && ci.isInvalid()) return true;
121  if(isInvalid() || ci.isInvalid()) return false;
122  return i->equal_to(ci.i);
123  }
124  bool operator!=(const const_iterator& ci) const {
125  if(isInvalid() && ci.isInvalid()) return false;
126  if(isInvalid() || ci.isInvalid()) return true;
127  return ! i->equal_to(ci.i);
128  }
130  if(isInvalid())
132  "Trying to dereference an inavlid RefToBaseVector<T>::const_iterator\n");
133  return i->deref();
134  }
136  if(isInvalid())
138  "Trying to decrement an inavlid RefToBaseVector<T>::const_iterator\n");
139  i->decrease(d);
140  return *this;
141  }
143  if(isInvalid())
145  "Trying to increment an inavlid RefToBaseVector<T>::const_iterator\n");
146  i->increase(d);
147  return *this;
148  }
149  bool isValid() const { return i != 0; }
150  bool isInvalid() const { return i == 0; }
151 
152  private:
154  };
155 
156  virtual const_iterator begin() const = 0;
157  virtual const_iterator end() const = 0;
158  template<typename T> RefToBase<T> getRef(size_t idx) const;
159  virtual void const* product() const = 0;
160  virtual void reallyFillView(void const*, ProductID const&, std::vector<void const*>&) = 0;
161  virtual size_t keyForIndex(size_t idx) const = 0;
162 
165  virtual bool isAvailable() const = 0;
166 
167  private:
168  virtual std::shared_ptr<reftobase::RefHolderBase> refBase(size_t idx) const = 0;
169  };
170 
171  template<typename T>
173  std::shared_ptr<reftobase::RefHolderBase> rb = refBase(idx);
174  return RefToBase<T>(rb);
175  }
176 
177  // Free swap function
178  inline
180  lhs.swap(rhs);
181  }
182  }
183 }
184 
185 #endif
bool operator==(const const_iterator &ci) const
void swap(RefVectorHolderBase &)
virtual const_iterator_imp * clone() const =0
virtual RefVectorHolderBase * clone() const =0
const_iterator operator-(difference_type n) const
virtual bool empty() const =0
int ii
Definition: cuy.py:588
virtual RefVectorHolderBase * cloneEmpty() 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 size_t keyForIndex(size_t idx) const =0
virtual void const * product() const =0
virtual size_type size() const =0
virtual void reallyFillView(void const *, ProductID const &, std::vector< void const * > &)=0
virtual std::shared_ptr< RefHolderBase > deref() 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
virtual const_iterator begin() const =0
virtual bool less_than(const_iterator_imp const *) const =0
tuple idx
DEBUGGING if hasattr(process,&quot;trackMonIterativeTracking2012&quot;): print &quot;trackMonIterativeTracking2012 D...
virtual void reserve(size_type n)=0
const_iterator & operator=(const_iterator const &it)
virtual const_iterator end() const =0
virtual ProductID id() const =0
virtual void push_back(RefHolderBase const *r)=0
virtual bool isAvailable() const =0
RefToBase< T > getRef(size_t idx) const
virtual std::shared_ptr< reftobase::RefHolderBase > refBase(size_t idx) const =0
difference_type operator-(const_iterator const &o) const
virtual bool equal_to(const_iterator_imp const *) const =0
void swap(BaseHolder< T > &lhs, BaseHolder< T > &rhs)
Definition: BaseHolder.h:117