CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
IndirectVectorHolder.h
Go to the documentation of this file.
1 #ifndef DataFormats_Common_IndirectVectorHolder_h
2 #define DataFormats_Common_IndirectVectorHolder_h
8 #include <memory>
9 
10 namespace edm {
11  namespace reftobase {
12 
13  template <typename T>
14  class IndirectVectorHolder : public BaseVectorHolder<T> {
15  public:
17  typedef typename base_type::size_type size_type;
20  typedef typename base_type::const_iterator const_iterator;
21 
24  IndirectVectorHolder(std::shared_ptr<RefVectorHolderBase> p);
26  virtual ~IndirectVectorHolder();
28  void swap(IndirectVectorHolder& other);
31  virtual ProductID id() const GCC11_OVERRIDE;
32  virtual EDProductGetter const* productGetter() const GCC11_OVERRIDE;
33  virtual bool empty() const GCC11_OVERRIDE;
34  virtual size_type size() const GCC11_OVERRIDE;
35  virtual void clear() GCC11_OVERRIDE;
36  virtual base_ref_type const at(size_type idx) const GCC11_OVERRIDE;
37  virtual std::auto_ptr<reftobase::RefVectorHolderBase> vectorHolder() const GCC11_OVERRIDE {
38  return std::auto_ptr<reftobase::RefVectorHolderBase>( helper_->clone() );
39  }
40  virtual void push_back( const BaseHolder<T> * r ) GCC11_OVERRIDE {
41  typedef IndirectHolder<T> holder_type;
42  const holder_type * h = dynamic_cast<const holder_type *>( r );
43  if( h == 0 )
45  "In IndirectHolder<T> trying to push_back wrong reference type");
46  helper_->push_back( h->helper_ );
47  }
48 
51  virtual bool isAvailable() const GCC11_OVERRIDE { return helper_->isAvailable(); }
52 
53  //Used by ROOT storage
55 
56  private:
59 
60  public:
61  struct const_iterator_imp_specific : public const_iterator_imp {
62  typedef ptrdiff_t difference_type;
64  explicit const_iterator_imp_specific( const typename RefVectorHolderBase::const_iterator & it ) : i ( it ) { }
67  void increase() { ++i; }
68  void decrease() { --i; }
69  void increase( difference_type d ) { i += d; }
70  void decrease( difference_type d ) { i -= d; }
71  bool equal_to( const const_iterator_imp * o ) const { return i == dc( o ); }
72  bool less_than( const const_iterator_imp * o ) const { return i < dc( o ); }
73  void assign( const const_iterator_imp * o ) { i = dc( o ); }
74  base_ref_type deref() const {
75  return base_ref_type( * i );
76  }
77  difference_type difference( const const_iterator_imp * o ) const { return i - dc( o ); }
78  private:
79  const typename RefVectorHolderBase::const_iterator & dc( const const_iterator_imp * o ) const {
80  if ( o == 0 ) {
82  "In IndirectVectorHolder trying to dereference a null pointer");
83  }
84  const const_iterator_imp_specific * oo = dynamic_cast<const const_iterator_imp_specific *>( o );
85  if ( oo == 0 ) {
87  "In IndirectVectorHolder trying to cast iterator to wrong type ");
88  }
89  return oo->i;
90  }
92  };
93 
95  return const_iterator( new const_iterator_imp_specific( helper_->begin() ) );
96  }
98  return const_iterator( new const_iterator_imp_specific( helper_->end() ) );
99  }
100  };
101 
102  template <typename T>
104 
105  template <typename T>
106  IndirectVectorHolder<T>::IndirectVectorHolder(std::shared_ptr<RefVectorHolderBase> p) :
107  BaseVectorHolder<T>(), helper_(p->clone()) { }
108 
109  template <typename T>
111  BaseVectorHolder<T>(), helper_(p) { }
112 
113  template <typename T>
115  BaseVectorHolder<T>(), helper_( other.helper_->clone() ) { }
116 
117  template <typename T>
119  delete helper_;
120  }
121 
122  template <typename T>
124  this->BaseVectorHolder<T>::swap(other);
125  std::swap(helper_, other.helper_);
126  }
127 
128  template <typename T>
132  swap(temp);
133  return *this;
134  }
135 
136  template <typename T>
139  return new IndirectVectorHolder<T>(*this);
140  }
141 
142  template <typename T>
145  return new IndirectVectorHolder<T>( helper_->cloneEmpty() );
146  }
147 
148  template <typename T>
149  ProductID
151  return helper_->id();
152  }
153 
154  template <typename T>
156  return helper_->productGetter();
157  }
158 
159  template <typename T>
161  return helper_->empty();
162  }
163 
164  template <typename T>
166  return helper_->size();
167  }
168 
169  template <typename T>
171  return helper_->clear();
172  }
173 
174  template <typename T>
176  return helper_ ? helper_->template getRef<T>( idx ) : typename IndirectVectorHolder<T>::base_ref_type();
177  }
178 
179  // Free swap function
180  template <typename T>
181  inline
183  lhs.swap(rhs);
184  }
185  }
186 }
187 
188 #endif
189 
190 
int i
Definition: DBlmapReader.cc:9
#define GCC11_OVERRIDE
virtual std::auto_ptr< reftobase::RefVectorHolderBase > vectorHolder() const
virtual RefVectorHolderBase * clone() const =0
virtual void push_back(const BaseHolder< T > *r)
base_type::const_iterator const_iterator
difference_type difference(const const_iterator_imp *o) const
virtual BaseVectorHolder< T > * clone() const
#define CMS_CLASS_VERSION(_version_)
Definition: classes.h:31
static void throwThis(Code category, char const *message0="", char const *message1="", char const *message2="", char const *message3="", char const *message4="")
tuple d
Definition: ztail.py:151
IndirectVectorHolder & operator=(IndirectVectorHolder const &rhs)
virtual BaseVectorHolder< T > * cloneEmpty() const
void swap(edm::DataFrameContainer &lhs, edm::DataFrameContainer &rhs)
const_iterator_imp_specific(const typename RefVectorHolderBase::const_iterator &it)
const RefVectorHolderBase::const_iterator & dc(const const_iterator_imp *o) const
The Signals That Services Can Subscribe To This is based on ActivityRegistry h
Helper function to determine trigger accepts.
Definition: Activities.doc:4
void swap(IndirectVectorHolder &other)
virtual const_iterator begin() const =0
tuple idx
DEBUGGING if hasattr(process,&quot;trackMonIterativeTracking2012&quot;): print &quot;trackMonIterativeTracking2012 D...
string const
Definition: compareJSON.py:14
TEveGeoShape * clone(const TEveElement *element, TEveElement *parent)
Definition: eve_macros.cc:135
#define private
Definition: FWFileEntry.h:17
virtual base_ref_type const at(size_type idx) const
virtual const_iterator end() const =0
virtual void push_back(RefHolderBase const *r)=0
virtual bool isAvailable() const =0
ProductIndex id() const
Definition: ProductID.h:38
void swap(BaseVectorHolder &)
long double T
virtual EDProductGetter const * productGetter() const
void swap(BaseHolder< T > &lhs, BaseHolder< T > &rhs)
Definition: BaseHolder.h:116