CMS 3D CMS Logo

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