CMS 3D CMS Logo

IndirectVectorHolder.h
Go to the documentation of this file.
1 #ifndef DataFormats_Common_IndirectVectorHolder_h
2 #define DataFormats_Common_IndirectVectorHolder_h
7 #include <memory>
8 
9 namespace edm {
10  namespace reftobase {
11 
12  template <typename T>
13  class IndirectVectorHolder : public BaseVectorHolder<T> {
14  public:
16  typedef typename base_type::size_type size_type;
20 
23  IndirectVectorHolder(std::shared_ptr<RefVectorHolderBase> p);
25  ~IndirectVectorHolder() override;
28  BaseVectorHolder<T>* clone() const override;
29  BaseVectorHolder<T>* cloneEmpty() const override;
30  ProductID id() const override;
31  EDProductGetter const* productGetter() const override;
32  bool empty() const override;
33  size_type size() const override;
34  void clear() override;
35  base_ref_type const at(size_type idx) const override;
36  std::unique_ptr<reftobase::RefVectorHolderBase> vectorHolder() const override {
37  return std::unique_ptr<reftobase::RefVectorHolderBase>( helper_->clone() );
38  }
39  void push_back( const BaseHolder<T> * r ) override {
40  typedef IndirectHolder<T> holder_type;
41  const holder_type * h = dynamic_cast<const holder_type *>( r );
42  if( h == nullptr )
44  "In IndirectHolder<T> trying to push_back wrong reference type");
45  helper_->push_back( h->helper_ );
46  }
47 
50  bool isAvailable() const override { return helper_->isAvailable(); }
51 
52  //Used by ROOT storage
54 
55  private:
56  typedef typename base_type::const_iterator_imp const_iterator_imp;
58 
59  public:
60  struct const_iterator_imp_specific : public const_iterator_imp {
61  typedef ptrdiff_t difference_type;
63  explicit const_iterator_imp_specific( const typename RefVectorHolderBase::const_iterator & it ) : i ( it ) { }
65  const_iterator_imp_specific * clone() const override { return new const_iterator_imp_specific( i ); }
66  void increase() override { ++i; }
67  void decrease() override { --i; }
68  void increase( difference_type d ) override { i += d; }
69  void decrease( difference_type d ) override { i -= d; }
70  bool equal_to( const const_iterator_imp * o ) const override { return i == dc( o ); }
71  bool less_than( const const_iterator_imp * o ) const override { return i < dc( o ); }
72  void assign( const const_iterator_imp * o ) override { i = dc( o ); }
73  base_ref_type deref() const override {
74  return base_ref_type( * i );
75  }
76  difference_type difference( const const_iterator_imp * o ) const override { return i - dc( o ); }
77  private:
78  const typename RefVectorHolderBase::const_iterator & dc( const const_iterator_imp * o ) const {
79  if ( o == nullptr ) {
81  "In IndirectVectorHolder trying to dereference a null pointer");
82  }
83  const const_iterator_imp_specific * oo = dynamic_cast<const const_iterator_imp_specific *>( o );
84  if ( oo == nullptr ) {
86  "In IndirectVectorHolder trying to cast iterator to wrong type ");
87  }
88  return oo->i;
89  }
91  };
92 
93  const_iterator begin() const override {
95  }
96  const_iterator end() const override {
98  }
99  };
100 
101  template <typename T>
103 
104  template <typename T>
105  IndirectVectorHolder<T>::IndirectVectorHolder(std::shared_ptr<RefVectorHolderBase> p) :
106  BaseVectorHolder<T>(), helper_(p->clone()) { }
107 
108  template <typename T>
110  BaseVectorHolder<T>(), helper_(p) { }
111 
112  template <typename T>
114  BaseVectorHolder<T>(), helper_( other.helper_->clone() ) { }
115 
116  template <typename T>
118  delete helper_;
119  }
120 
121  template <typename T>
123  this->BaseVectorHolder<T>::swap(other);
124  std::swap(helper_, other.helper_);
125  }
126 
127  template <typename T>
131  swap(temp);
132  return *this;
133  }
134 
135  template <typename T>
138  return new IndirectVectorHolder<T>(*this);
139  }
140 
141  template <typename T>
144  return new IndirectVectorHolder<T>( helper_->cloneEmpty() );
145  }
146 
147  template <typename T>
148  ProductID
150  return helper_->id();
151  }
152 
153  template <typename T>
155  return helper_->productGetter();
156  }
157 
158  template <typename T>
160  return helper_->empty();
161  }
162 
163  template <typename T>
165  return helper_->size();
166  }
167 
168  template <typename T>
170  return helper_->clear();
171  }
172 
173  template <typename T>
175  return helper_ ? helper_->template getRef<T>( idx ) : typename IndirectVectorHolder<T>::base_ref_type();
176  }
177 
178  // Free swap function
179  template <typename T>
180  inline
182  lhs.swap(rhs);
183  }
184  }
185 }
186 
187 #endif
188 
189 
virtual ProductID id() const =0
bool less_than(const const_iterator_imp *o) const override
difference_type difference(const const_iterator_imp *o) const override
FWCore Framework interface EventSetupRecordImplementation h
Helper function to determine trigger accepts.
#define nullptr
void push_back(const BaseHolder< T > *r) override
virtual const_iterator begin() const =0
base_type::const_iterator const_iterator
EDProductGetter const * productGetter() const override
#define CMS_CLASS_VERSION(_version_)
BaseVectorHolder< T > * cloneEmpty() const override
virtual size_type size() const =0
BaseVectorHolder< T > * clone() const override
static void throwThis(Code category, char const *message0="", char const *message1="", char const *message2="", char const *message3="", char const *message4="")
Definition: EDMException.cc:83
virtual bool empty() const =0
virtual bool isAvailable() const =0
IndirectVectorHolder & operator=(IndirectVectorHolder const &rhs)
base_ref_type const at(size_type idx) const override
void swap(edm::DataFrameContainer &lhs, edm::DataFrameContainer &rhs)
virtual EDProductGetter const * productGetter() const =0
const_iterator_imp_specific(const typename RefVectorHolderBase::const_iterator &it)
std::unique_ptr< reftobase::RefVectorHolderBase > vectorHolder() const override
const RefVectorHolderBase::const_iterator & dc(const const_iterator_imp *o) const
void swap(IndirectVectorHolder &other)
virtual const_iterator end() const =0
bool equal_to(const const_iterator_imp *o) const override
virtual RefVectorHolderBase * cloneEmpty() const =0
const_iterator begin() const override
const_iterator end() const override
HLT enums.
virtual void push_back(RefHolderBase const *r)=0
void swap(BaseVectorHolder &)
long double T
virtual RefVectorHolderBase * clone() const =0