CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
VectorHolder.h
Go to the documentation of this file.
1 #ifndef DataFormats_Common_VectorHolder_h
2 #define DataFormats_Common_VectorHolder_h
6 #include <memory>
7 
8 namespace edm {
9  namespace reftobase {
10 
11  class RefVectorHolderBase;
12 
13  template <class T, class REFV>
14  class VectorHolder : public BaseVectorHolder<T> {
15  public:
17  typedef typename base_type::size_type size_type;
21  typedef REFV ref_vector_type;
22 
25 #if defined(__GXX_EXPERIMENTAL_CXX0X__)
26  VectorHolder(VectorHolder&& rh) noexcept : base_type(std::forward(rh)), refVector_(std::move(rh.refVector_)) {}
27 #endif
28 
29  explicit VectorHolder(const ref_vector_type& iRefVector) : base_type(), refVector_(iRefVector) {}
30  explicit VectorHolder(const ProductID& iId) : base_type(), refVector_(iId) {}
31  ~VectorHolder() noexcept override {}
32  base_type* clone() const override { return new VectorHolder(*this); }
33  base_type* cloneEmpty() const override { return new VectorHolder(refVector_.id()); }
34  base_ref_type const at(size_type idx) const override { return base_ref_type(refVector_.at(idx)); }
35  bool empty() const override { return refVector_.empty(); }
36  size_type size() const override { return refVector_.size(); }
37  //size_type capacity() const { return refVector_.capacity(); }
38  //void reserve(size_type n) { refVector_.reserve(n); }
39  void clear() override { refVector_.clear(); }
40  ProductID id() const override { return refVector_.id(); }
41  EDProductGetter const* productGetter() const override { return refVector_.productGetter(); }
42  void swap(VectorHolder& other) noexcept {
43  this->BaseVectorHolder<T>::swap(other);
44  refVector_.swap(other.refVector_);
45  }
47  VectorHolder temp(rhs);
48  this->swap(temp);
49  return *this;
50  }
51 #if defined(__GXX_EXPERIMENTAL_CXX0X__)
52  VectorHolder& operator=(VectorHolder&& rhs) noexcept {
53  base_type::operator=(std::forward(rhs));
54  refVector_ = std::move(rhs.refVector_);
55  return *this;
56  }
57 #endif
58 
59  const_iterator begin() const override {
61  }
62  const_iterator end() const override { return const_iterator(new const_iterator_imp_specific(refVector_.end())); }
63  void push_back(const BaseHolder<T>* r) override {
64  typedef Holder<T, typename REFV::value_type> holder_type;
65  const holder_type* h = dynamic_cast<const holder_type*>(r);
66  if (h == nullptr)
68  "In VectorHolder<T, REFV> trying to push_back wrong reference type");
69  refVector_.push_back(h->getRef());
70  }
71  std::unique_ptr<RefVectorHolderBase> vectorHolder() const override {
72  return std::unique_ptr<RefVectorHolderBase>(new RefVectorHolder<REFV>(refVector_));
73  }
74 
77  bool isAvailable() const override { return refVector_.isAvailable(); }
78 
79  //Used by ROOT storage
81 
82  private:
84 
86 
87  // the following structure is public
88  // to allow dictionary to compile
89  public:
90  struct const_iterator_imp_specific : public const_iterator_imp {
91  typedef ptrdiff_t difference_type;
93  explicit const_iterator_imp_specific(const typename REFV::const_iterator& it) : i(it) {}
96  void increase() override { ++i; }
97  void decrease() override { --i; }
98  void increase(difference_type d) override { i += d; }
99  void decrease(difference_type d) override { i -= d; }
100  bool equal_to(const const_iterator_imp* o) const override { return i == dc(o); }
101  bool less_than(const const_iterator_imp* o) const override { return i < dc(o); }
102  void assign(const const_iterator_imp* o) override { i = dc(o); }
103  base_ref_type deref() const override { return base_ref_type(*i); }
104  difference_type difference(const const_iterator_imp* o) const override { return i - dc(o); }
105 
106  private:
107  const typename ref_vector_type::const_iterator& dc(const const_iterator_imp* o) const {
108  if (o == nullptr)
110  "In RefToBaseVector<T> trying to dereference a null pointer");
111  const const_iterator_imp_specific* oo = dynamic_cast<const const_iterator_imp_specific*>(o);
112  if (oo == nullptr)
114  "In RefToBaseVector<T> trying to cast iterator to wrong type ");
115  return oo->i;
116  }
117  typename ref_vector_type::const_iterator i;
118  };
119  };
120 
121  // Free swap function
122  template <typename T, typename REFV>
123  inline void swap(VectorHolder<T, REFV>& lhs, VectorHolder<T, REFV>& rhs) noexcept {
124  lhs.swap(rhs);
125  }
126  } // namespace reftobase
127 } // namespace edm
128 
129 #endif
base_type::const_iterator const_iterator
Definition: VectorHolder.h:20
size_type size() const override
Definition: VectorHolder.h:36
void assign(const const_iterator_imp *o) override
Definition: VectorHolder.h:102
VectorHolder & operator=(VectorHolder const &rhs)
Definition: VectorHolder.h:46
base_ref_type const at(size_type idx) const override
Definition: VectorHolder.h:34
const_iterator_imp_specific * clone() const override
Definition: VectorHolder.h:95
const_iterator end() const override
Definition: VectorHolder.h:62
const_iterator begin() const override
Definition: VectorHolder.h:59
#define CMS_CLASS_VERSION(_version_)
difference_type difference(const const_iterator_imp *o) const override
Definition: VectorHolder.h:104
VectorHolder(const ProductID &iId)
Definition: VectorHolder.h:30
bool less_than(const const_iterator_imp *o) const override
Definition: VectorHolder.h:101
VectorHolder(const ref_vector_type &iRefVector)
Definition: VectorHolder.h:29
static void throwThis(Code category, char const *message0="", char const *message1="", char const *message2="", char const *message3="", char const *message4="")
Definition: EDMException.cc:83
bool equal_to(const const_iterator_imp *o) const override
Definition: VectorHolder.h:100
tuple d
Definition: ztail.py:151
base_type::base_ref_type base_ref_type
Definition: VectorHolder.h:19
void swap(VectorHolder &other) noexcept
Definition: VectorHolder.h:42
def move
Definition: eostools.py:511
ProductID id() const override
Definition: VectorHolder.h:40
BaseVectorHolder< T > base_type
Definition: VectorHolder.h:16
base_type * cloneEmpty() const override
Definition: VectorHolder.h:33
const ref_vector_type::const_iterator & dc(const const_iterator_imp *o) const
Definition: VectorHolder.h:107
void push_back(const BaseHolder< T > *r) override
Definition: VectorHolder.h:63
base_type::size_type size_type
Definition: VectorHolder.h:17
ref_vector_type refVector_
Definition: VectorHolder.h:85
bool isAvailable() const override
Definition: VectorHolder.h:77
base_type::element_type element_type
Definition: VectorHolder.h:18
std::unique_ptr< RefVectorHolderBase > vectorHolder() const override
Definition: VectorHolder.h:71
VectorHolder(VectorHolder const &rh)
Definition: VectorHolder.h:24
const_iterator_imp_specific(const typename REFV::const_iterator &it)
Definition: VectorHolder.h:93
void swap(BaseVectorHolder &)
The Signals That Services Can Subscribe To This is based on ActivityRegistry h
Helper function to determine trigger accepts.
Definition: Activities.doc:4
bool empty() const override
Definition: VectorHolder.h:35
EDProductGetter const * productGetter() const override
Definition: VectorHolder.h:41
base_type * clone() const override
Definition: VectorHolder.h:32
~VectorHolder() noexceptoverride
Definition: VectorHolder.h:31
void swap(BaseHolder< T > &lhs, BaseHolder< T > &rhs)
Definition: BaseHolder.h:111