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;
21  typedef typename base_type::const_iterator const_iterator;
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  virtual ~VectorHolder() noexcept {}
33  virtual base_type* clone() const { return new VectorHolder(*this); }
34  virtual base_type* cloneEmpty() const { return new VectorHolder(refVector_.id()); }
35  base_ref_type const at(size_type idx) const { return base_ref_type( refVector_.at( idx ) ); }
36  bool empty() const { return refVector_.empty(); }
37  size_type size() const { return refVector_.size(); }
38  //size_type capacity() const { return refVector_.capacity(); }
39  //void reserve(size_type n) { refVector_.reserve(n); }
40  void clear() { refVector_.clear(); }
41  ProductID id() const { return refVector_.id(); }
42  EDProductGetter const* productGetter() const { 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 {
61  return const_iterator( new const_iterator_imp_specific( refVector_.begin() ) );
62  }
63  const_iterator end() const {
64  return const_iterator( new const_iterator_imp_specific( refVector_.end() ) );
65  }
66  virtual void push_back( const BaseHolder<T> * r ) {
67  typedef Holder<T, typename REFV::value_type > holder_type;
68  const holder_type * h = dynamic_cast<const holder_type *>( r );
69  if( h == 0 )
71  "In VectorHolder<T, REFV> trying to push_back wrong reference type");
72  refVector_.push_back( h->getRef() );
73  }
74  virtual std::unique_ptr<RefVectorHolderBase> vectorHolder() const {
75  return std::unique_ptr<RefVectorHolderBase>( new RefVectorHolder<REFV>( refVector_ ) );
76  }
77 
80  virtual bool isAvailable() const { 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 ) { }
99  void increase() { ++i; }
100  void decrease() { --i; }
101  void increase( difference_type d ) { i += d; }
102  void decrease( difference_type d ) { i -= d; }
103  bool equal_to( const const_iterator_imp * o ) const { return i == dc( o ); }
104  bool less_than( const const_iterator_imp * o ) const { return i < dc( o ); }
105  void assign( const const_iterator_imp * o ) { i = dc( o ); }
106  base_ref_type deref() const { return base_ref_type( * i ); }
107  difference_type difference( const const_iterator_imp * o ) const { return i - dc( o ); }
108  private:
109  const typename ref_vector_type::const_iterator & dc( const const_iterator_imp * o ) const {
110  if ( o == 0 )
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 == 0 )
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
int i
Definition: DBlmapReader.cc:9
size_type size() const
Definition: VectorHolder.h:37
const_iterator_imp_specific * clone() const
Definition: VectorHolder.h:98
const_iterator begin() const
Definition: VectorHolder.h:60
VectorHolder(VectorHolder const &rh)
Definition: VectorHolder.h:25
#define noexcept
BaseVectorHolder< T > base_type
Definition: VectorHolder.h:17
base_type::const_iterator const_iterator
Definition: VectorHolder.h:21
#define CMS_CLASS_VERSION(_version_)
Definition: classes.h:31
bool less_than(const const_iterator_imp *o) const
Definition: VectorHolder.h:104
virtual void push_back(const BaseHolder< T > *r)
Definition: VectorHolder.h:66
static void throwThis(Code category, char const *message0="", char const *message1="", char const *message2="", char const *message3="", char const *message4="")
base_type::base_ref_type base_ref_type
Definition: VectorHolder.h:20
VectorHolder(const ref_vector_type &iRefVector)
Definition: VectorHolder.h:30
virtual bool isAvailable() const
Definition: VectorHolder.h:80
bool equal_to(const const_iterator_imp *o) const
Definition: VectorHolder.h:103
VectorHolder & operator=(VectorHolder const &rhs)
Definition: VectorHolder.h:47
EDProductGetter const * productGetter() const
Definition: VectorHolder.h:42
base_type::size_type size_type
Definition: VectorHolder.h:18
virtual std::unique_ptr< RefVectorHolderBase > vectorHolder() const
Definition: VectorHolder.h:74
virtual base_type * cloneEmpty() const
Definition: VectorHolder.h:34
const_iterator end() const
Definition: VectorHolder.h:63
base_ref_type const at(size_type idx) const
Definition: VectorHolder.h:35
virtual base_type * clone() const
Definition: VectorHolder.h:33
ProductID id() const
Definition: VectorHolder.h:41
void swap(VectorHolder &other)
Definition: VectorHolder.h:43
HLT enums.
difference_type difference(const const_iterator_imp *o) const
Definition: VectorHolder.h:107
const ref_vector_type::const_iterator & dc(const const_iterator_imp *o) const
Definition: VectorHolder.h:109
VectorHolder(const ProductID &iId)
Definition: VectorHolder.h:31
ref_vector_type refVector_
Definition: VectorHolder.h:88
void swap(BaseVectorHolder &)
const_iterator_imp_specific(const typename REFV::const_iterator &it)
Definition: VectorHolder.h:96
def move(src, dest)
Definition: eostools.py:510