test
CMS 3D CMS Logo

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