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>
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(boost::shared_ptr<RefVectorHolderBase> p);
25  virtual ~IndirectVectorHolder();
27  void swap(IndirectVectorHolder& other);
28  virtual BaseVectorHolder<T>* clone() const;
29  virtual BaseVectorHolder<T>* cloneEmpty() const;
30  virtual ProductID id() const;
31  virtual EDProductGetter const* productGetter() const;
32  virtual bool empty() const;
33  virtual size_type size() const;
34  virtual void clear();
35  virtual base_ref_type const at(size_type idx) const;
36  virtual std::auto_ptr<reftobase::RefVectorHolderBase> vectorHolder() const {
37  return std::auto_ptr<reftobase::RefVectorHolderBase>( helper_->clone() );
38  }
39  virtual void push_back( const BaseHolder<T> * r ) {
40  typedef IndirectHolder<T> holder_type;
41  const holder_type * h = dynamic_cast<const holder_type *>( r );
42  if( h == 0 )
44  "In IndirectHolder<T> trying to push_back wrong reference type");
45  helper_->push_back( h->helper_ );
46  }
47  virtual const void * product() const {
48  return helper_->product();
49  }
50 
53  virtual bool isAvailable() const { return helper_->isAvailable(); }
54 
55  //Used by ROOT storage
57 
58  private:
61 
62  public:
63  struct const_iterator_imp_specific : public const_iterator_imp {
64  typedef ptrdiff_t difference_type;
66  explicit const_iterator_imp_specific( const typename RefVectorHolderBase::const_iterator & it ) : i ( it ) { }
69  void increase() { ++i; }
70  void decrease() { --i; }
71  void increase( difference_type d ) { i += d; }
72  void decrease( difference_type d ) { i -= d; }
73  bool equal_to( const const_iterator_imp * o ) const { return i == dc( o ); }
74  bool less_than( const const_iterator_imp * o ) const { return i < dc( o ); }
75  void assign( const const_iterator_imp * o ) { i = dc( o ); }
76  base_ref_type deref() const {
77  return base_ref_type( * i );
78  }
79  difference_type difference( const const_iterator_imp * o ) const { return i - dc( o ); }
80  private:
81  const typename RefVectorHolderBase::const_iterator & dc( const const_iterator_imp * o ) const {
82  if ( o == 0 ) {
84  "In IndirectVectorHolder trying to dereference a null pointer");
85  }
86  const const_iterator_imp_specific * oo = dynamic_cast<const const_iterator_imp_specific *>( o );
87  if ( oo == 0 ) {
89  "In IndirectVectorHolder trying to cast iterator to wrong type ");
90  }
91  return oo->i;
92  }
94  };
95 
98  }
99  const_iterator end() const {
101  }
102  };
103 
104  template <typename T>
106 
107  template <typename T>
108  IndirectVectorHolder<T>::IndirectVectorHolder(boost::shared_ptr<RefVectorHolderBase> p) :
109  BaseVectorHolder<T>(), helper_(p->clone()) { }
110 
111  template <typename T>
113  BaseVectorHolder<T>(), helper_(p) { }
114 
115  template <typename T>
117  BaseVectorHolder<T>(), helper_( other.helper_->clone() ) { }
118 
119  template <typename T>
121  delete helper_;
122  }
123 
124  template <typename T>
126  this->BaseVectorHolder<T>::swap(other);
127  std::swap(helper_, other.helper_);
128  }
129 
130  template <typename T>
134  swap(temp);
135  return *this;
136  }
137 
138  template <typename T>
141  return new IndirectVectorHolder<T>(*this);
142  }
143 
144  template <typename T>
147  return new IndirectVectorHolder<T>( helper_->cloneEmpty() );
148  }
149 
150  template <typename T>
151  ProductID
153  return helper_->id();
154  }
155 
156  template <typename T>
158  return helper_->productGetter();
159  }
160 
161  template <typename T>
163  return helper_->empty();
164  }
165 
166  template <typename T>
168  return helper_->size();
169  }
170 
171  template <typename T>
173  return helper_->clear();
174  }
175 
176  template <typename T>
178  return helper_ ? helper_->template getRef<T>( idx ) : typename IndirectVectorHolder<T>::base_ref_type();
179  }
180 
181  // Free swap function
182  template <typename T>
183  inline
185  lhs.swap(rhs);
186  }
187  }
188 }
189 
190 #endif
191 
192 
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:32
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
void swap(IndirectVectorHolder &other)
virtual const_iterator begin() const =0
The Signals That Services Can Subscribe To This is based on ActivityRegistry h
Helper function to determine trigger accepts.
Definition: Activities.doc:4
TEveGeoShape * clone(const TEveElement *element, TEveElement *parent)
Definition: eve_macros.cc:135
#define private
Definition: FWFileEntry.h:18
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