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
7 #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);
29  virtual BaseVectorHolder<T>* clone() const;
30  virtual BaseVectorHolder<T>* cloneEmpty() const;
31  virtual ProductID id() const;
32  virtual EDProductGetter const* productGetter() const;
33  virtual bool empty() const;
34  virtual size_type size() const;
35  virtual void clear();
36  virtual base_ref_type const at(size_type idx) const;
37  virtual std::auto_ptr<reftobase::RefVectorHolderBase> vectorHolder() const {
38  return std::auto_ptr<reftobase::RefVectorHolderBase>( helper_->clone() );
39  }
40  virtual void push_back( const BaseHolder<T> * r ) {
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  virtual const void * product() const {
49  return helper_->product();
50  }
51 
54  virtual bool isAvailable() const { return helper_->isAvailable(); }
55 
56  //Used by ROOT storage
58 
59  private:
62 
63  public:
64  struct const_iterator_imp_specific : public const_iterator_imp {
65  typedef ptrdiff_t difference_type;
67  explicit const_iterator_imp_specific( const typename RefVectorHolderBase::const_iterator & it ) : i ( it ) { }
70  void increase() { ++i; }
71  void decrease() { --i; }
72  void increase( difference_type d ) { i += d; }
73  void decrease( difference_type d ) { i -= d; }
74  bool equal_to( const const_iterator_imp * o ) const { return i == dc( o ); }
75  bool less_than( const const_iterator_imp * o ) const { return i < dc( o ); }
76  void assign( const const_iterator_imp * o ) { i = dc( o ); }
77  base_ref_type deref() const {
78  return base_ref_type( * i );
79  }
80  difference_type difference( const const_iterator_imp * o ) const { return i - dc( o ); }
81  private:
82  const typename RefVectorHolderBase::const_iterator & dc( const const_iterator_imp * o ) const {
83  if ( o == 0 ) {
85  "In IndirectVectorHolder trying to dereference a null pointer");
86  }
87  const const_iterator_imp_specific * oo = dynamic_cast<const const_iterator_imp_specific *>( o );
88  if ( oo == 0 ) {
90  "In IndirectVectorHolder trying to cast iterator to wrong type ");
91  }
92  return oo->i;
93  }
95  };
96 
98  return const_iterator( new const_iterator_imp_specific( helper_->begin() ) );
99  }
100  const_iterator end() const {
101  return const_iterator( new const_iterator_imp_specific( helper_->end() ) );
102  }
103  };
104 
105  template <typename T>
107 
108  template <typename T>
109  IndirectVectorHolder<T>::IndirectVectorHolder(std::shared_ptr<RefVectorHolderBase> p) :
110  BaseVectorHolder<T>(), helper_(p->clone()) { }
111 
112  template <typename T>
114  BaseVectorHolder<T>(), helper_(p) { }
115 
116  template <typename T>
118  BaseVectorHolder<T>(), helper_( other.helper_->clone() ) { }
119 
120  template <typename T>
122  delete helper_;
123  }
124 
125  template <typename T>
127  this->BaseVectorHolder<T>::swap(other);
128  std::swap(helper_, other.helper_);
129  }
130 
131  template <typename T>
135  swap(temp);
136  return *this;
137  }
138 
139  template <typename T>
142  return new IndirectVectorHolder<T>(*this);
143  }
144 
145  template <typename T>
148  return new IndirectVectorHolder<T>( helper_->cloneEmpty() );
149  }
150 
151  template <typename T>
152  ProductID
154  return helper_->id();
155  }
156 
157  template <typename T>
159  return helper_->productGetter();
160  }
161 
162  template <typename T>
164  return helper_->empty();
165  }
166 
167  template <typename T>
169  return helper_->size();
170  }
171 
172  template <typename T>
174  return helper_->clear();
175  }
176 
177  template <typename T>
179  return helper_ ? helper_->template getRef<T>( idx ) : typename IndirectVectorHolder<T>::base_ref_type();
180  }
181 
182  // Free swap function
183  template <typename T>
184  inline
186  lhs.swap(rhs);
187  }
188  }
189 }
190 
191 #endif
192 
193 
int i
Definition: DBlmapReader.cc:9
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="")
virtual void const * product() const =0
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)
virtual const void * product() const
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...
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:117