CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
IndirectHolder.h
Go to the documentation of this file.
1 #ifndef DataFormats_Common_IndirectHolder_h
2 #define DataFormats_Common_IndirectHolder_h
8 
9 #include <memory>
10 
11 namespace edm {
12  template<typename T> class RefToBase;
13 
14  namespace reftobase {
15 
16  template<typename T> class IndirectVectorHolder;
17  class RefVectorHolderBase;
18  class RefHolderBase;
19 
20  //------------------------------------------------------------------
21  // Class template IndirectHolder<T>
22  //------------------------------------------------------------------
23 
24  template <typename T>
25  class IndirectHolder : public BaseHolder<T> {
26  public:
27  // It may be better to use auto_ptr<RefHolderBase> in
28  // this constructor, so that the cloning can be avoided. I'm not
29  // sure if use of auto_ptr here causes any troubles elsewhere.
31  IndirectHolder(std::shared_ptr<RefHolderBase> p);
32  IndirectHolder(IndirectHolder const& other);
34  void swap(IndirectHolder& other);
35  virtual ~IndirectHolder();
36 
37  virtual BaseHolder<T>* clone() const;
38  virtual T const* getPtr() const;
39  virtual ProductID id() const;
40  virtual size_t key() const;
41  virtual bool isEqualTo(BaseHolder<T> const& rhs) const;
42 
43  virtual bool fillRefIfMyTypeMatches(RefHolderBase& fillme,
44  std::string& msg) const;
45  virtual std::auto_ptr<RefHolderBase> holder() const;
46  virtual std::auto_ptr<BaseVectorHolder<T> > makeVectorHolder() const;
47  virtual std::auto_ptr<RefVectorHolderBase> makeVectorBaseHolder() const;
48  virtual EDProductGetter const* productGetter() const;
49  virtual bool hasProductCache() const;
50  virtual void const * product() const;
51 
54  virtual bool isAvailable() const { return helper_->isAvailable(); }
55 
56  //Used by ROOT storage
58 
59  private:
60  friend class RefToBase<T>;
61  friend class IndirectVectorHolder<T>;
63  };
64  //------------------------------------------------------------------
65  // Implementation of IndirectHolder<T>
66  //------------------------------------------------------------------
67  template <typename T>
68  inline
69  IndirectHolder<T>::IndirectHolder(std::shared_ptr<RefHolderBase> p) :
70  BaseHolder<T>(), helper_(p->clone())
71  { }
72 
73  template <typename T>
74  inline
76  BaseHolder<T>(other), helper_(other.helper_->clone())
77  { }
78 
79  template <typename T>
80  inline
81  void
83  {
84  this->BaseHolder<T>::swap(other);
85  std::swap(helper_, other.helper_);
86  }
87 
88  template <typename T>
89  inline
92  {
93  IndirectHolder temp(rhs);
94  swap(temp);
95  return *this;
96  }
97 
98  template <typename T>
100  {
101  delete helper_;
102  }
103 
104  template <typename T>
105  BaseHolder<T>*
107  {
108  return new IndirectHolder<T>(*this);
109  }
110 
111  template <typename T>
112  T const*
114  {
115  return helper_-> template getPtr<T>();
116  }
117 
118  template <typename T>
119  ProductID
121  {
122  return helper_->id();
123  }
124 
125  template <typename T>
126  size_t
128  {
129  return helper_->key();
130  }
131 
132  template <typename T>
133  inline
135  return helper_->productGetter();
136  }
137 
138  template <typename T>
139  inline
141  return helper_->hasProductCache();
142  }
143 
144  template <typename T>
145  inline
146  void const * IndirectHolder<T>::product() const {
147  return helper_->product();
148  }
149 
150  template <typename T>
151  bool
153  {
154  IndirectHolder const* h = dynamic_cast<IndirectHolder const*>(&rhs);
155  return h && helper_->isEqualTo(*h->helper_);
156  }
157 
158  template <typename T>
159  bool
161  std::string& msg) const
162  {
163  return helper_->fillRefIfMyTypeMatches(fillme, msg);
164  }
165 
166  template <typename T>
167  std::auto_ptr<RefHolderBase> IndirectHolder<T>::holder() const {
168  return std::auto_ptr<RefHolderBase>( helper_->clone() );
169  }
170 
171  // Free swap function
172  template <typename T>
173  inline
174  void
176  lhs.swap(rhs);
177  }
178  }
179 
180 }
181 
184 
185 namespace edm {
186  namespace reftobase {
187  template <typename T>
188  std::auto_ptr<BaseVectorHolder<T> > IndirectHolder<T>::makeVectorHolder() const {
189  std::auto_ptr<RefVectorHolderBase> p = helper_->makeVectorHolder();
190  std::shared_ptr<RefVectorHolderBase> sp( p.release() );
191  return std::auto_ptr<BaseVectorHolder<T> >( new IndirectVectorHolder<T>( sp ) );
192  }
193 
194  template <typename T>
195  std::auto_ptr<RefVectorHolderBase> IndirectHolder<T>::makeVectorBaseHolder() const {
196  return helper_->makeVectorHolder();
197  }
198  }
199 }
200 
201 #endif
virtual bool fillRefIfMyTypeMatches(RefHolderBase &fillme, std::string &msg) const
virtual size_t key() const
virtual BaseHolder< T > * clone() const
virtual std::auto_ptr< BaseVectorHolder< T > > makeVectorHolder() const
virtual bool isAvailable() const =0
virtual bool isAvailable() const
virtual EDProductGetter const * productGetter() const
#define CMS_CLASS_VERSION(_version_)
Definition: classes.h:31
void swap(BaseHolder &)
Definition: BaseHolder.h:109
IndirectHolder & operator=(IndirectHolder const &rhs)
void swap(edm::DataFrameContainer &lhs, edm::DataFrameContainer &rhs)
virtual T const * getPtr() const
virtual std::auto_ptr< RefVectorHolderBase > makeVectorBaseHolder() const
The Signals That Services Can Subscribe To This is based on ActivityRegistry h
Helper function to determine trigger accepts.
Definition: Activities.doc:4
virtual void const * product() const
void swap(IndirectHolder &other)
string const
Definition: compareJSON.py:14
virtual bool hasProductCache() const
virtual ProductID id() const
#define private
Definition: FWFileEntry.h:17
virtual bool isEqualTo(BaseHolder< T > const &rhs) const
ProductIndex id() const
Definition: ProductID.h:38
virtual std::auto_ptr< RefHolderBase > holder() const
long double T
def template
Definition: svgfig.py:520
void swap(BaseHolder< T > &lhs, BaseHolder< T > &rhs)
Definition: BaseHolder.h:117