CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros 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>
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 
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(); }
43  void swap(VectorHolder& other) noexcept {
44  this->BaseVectorHolder<T>::swap(other);
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 
61  return const_iterator( new const_iterator_imp_specific( refVector_.begin() ) );
62  }
63  const_iterator end() const {
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::auto_ptr<RefVectorHolderBase> vectorHolder() const {
75  return std::auto_ptr<RefVectorHolderBase>( new RefVectorHolder<REFV>( refVector_ ) );
76  }
77  virtual const void * product() const {
78  return refVector_.product();
79  }
80 
83  virtual bool isAvailable() const { return refVector_.isAvailable(); }
84 
85  //Used by ROOT storage
87 
88  private:
90 
92 
93  // the following structure is public
94  // to allow reflex dictionary to compile
95  public:
96  struct const_iterator_imp_specific : public const_iterator_imp {
97  typedef ptrdiff_t difference_type;
99  explicit const_iterator_imp_specific( const typename REFV::const_iterator & it ) : i ( it ) { }
102  void increase() { ++i; }
103  void decrease() { --i; }
104  void increase( difference_type d ) { i += d; }
105  void decrease( difference_type d ) { i -= d; }
106  bool equal_to( const const_iterator_imp * o ) const { return i == dc( o ); }
107  bool less_than( const const_iterator_imp * o ) const { return i < dc( o ); }
108  void assign( const const_iterator_imp * o ) { i = dc( o ); }
109  base_ref_type deref() const { return base_ref_type( * i ); }
110  difference_type difference( const const_iterator_imp * o ) const { return i - dc( o ); }
111  private:
112  const typename ref_vector_type::const_iterator & dc( const const_iterator_imp * o ) const {
113  if ( o == 0 )
115  "In RefToBaseVector<T> trying to dereference a null pointer");
116  const const_iterator_imp_specific * oo = dynamic_cast<const const_iterator_imp_specific *>( o );
117  if ( oo == 0 )
119  "In RefToBaseVector<T> trying to cast iterator to wrong type ");
120  return oo->i;
121  }
122  typename ref_vector_type::const_iterator i;
123  };
124  };
125 
126  // Free swap function
127  template <typename T, typename REFV>
128  inline
129  void
131  lhs.swap(rhs);
132  }
133  }
134 }
135 
136 #endif
nocap nocap const skelname & operator=(const skelname &)
int i
Definition: DBlmapReader.cc:9
base_type::const_iterator const_iterator
Definition: VectorHolder.h:21
const_iterator end() const
Definition: VectorHolder.h:63
virtual const void * product() const
Definition: VectorHolder.h:77
VectorHolder & operator=(VectorHolder const &rhs)
Definition: VectorHolder.h:47
const_iterator_imp_specific * clone() const
Definition: VectorHolder.h:101
#define CMS_CLASS_VERSION(_version_)
Definition: classes.h:32
size_type size() const
Definition: VectorHolder.h:37
VectorHolder(const ProductID &iId)
Definition: VectorHolder.h:31
VectorHolder(const ref_vector_type &iRefVector)
Definition: VectorHolder.h:30
static void throwThis(Code category, char const *message0="", char const *message1="", char const *message2="", char const *message3="", char const *message4="")
virtual base_type * cloneEmpty() const
Definition: VectorHolder.h:34
base_type::base_ref_type base_ref_type
Definition: VectorHolder.h:20
virtual base_type * clone() const
Definition: VectorHolder.h:33
virtual bool isAvailable() const
Definition: VectorHolder.h:83
BaseVectorHolder< T > base_type
Definition: VectorHolder.h:17
const ref_vector_type::const_iterator & dc(const const_iterator_imp *o) const
Definition: VectorHolder.h:112
virtual void push_back(const BaseHolder< T > *r)
Definition: VectorHolder.h:66
base_type::size_type size_type
Definition: VectorHolder.h:18
ref_vector_type refVector_
Definition: VectorHolder.h:91
ProductID id() const
Definition: VectorHolder.h:41
#define noexcept
base_ref_type const at(size_type idx) const
Definition: VectorHolder.h:35
The Signals That Services Can Subscribe To This is based on ActivityRegistry h
Helper function to determine trigger accepts.
Definition: Activities.doc:4
difference_type difference(const const_iterator_imp *o) const
Definition: VectorHolder.h:110
bool equal_to(const const_iterator_imp *o) const
Definition: VectorHolder.h:106
base_type::element_type element_type
Definition: VectorHolder.h:19
VectorHolder(VectorHolder const &rh)
Definition: VectorHolder.h:25
EDProductGetter const * productGetter() const
Definition: VectorHolder.h:42
#define private
Definition: FWFileEntry.h:18
const_iterator_imp_specific(const typename REFV::const_iterator &it)
Definition: VectorHolder.h:99
virtual std::auto_ptr< RefVectorHolderBase > vectorHolder() const
Definition: VectorHolder.h:74
void swap(BaseVectorHolder &)
const_iterator begin() const
Definition: VectorHolder.h:60
void swap(BaseHolder< T > &lhs, BaseHolder< T > &rhs)
Definition: BaseHolder.h:117
void swap(VectorHolder &other)
Definition: VectorHolder.h:43
bool less_than(const const_iterator_imp *o) const
Definition: VectorHolder.h:107