CMS 3D CMS Logo

IndirectHolder.h
Go to the documentation of this file.
1 #ifndef DataFormats_Common_IndirectHolder_h
2 #define DataFormats_Common_IndirectHolder_h
7 
8 #include <memory>
9 
10 namespace edm {
11  template<typename T> class RefToBase;
12 
13  namespace reftobase {
14 
15  template<typename T> class IndirectVectorHolder;
16  class RefVectorHolderBase;
17  class RefHolderBase;
18 
19  //------------------------------------------------------------------
20  // Class template IndirectHolder<T>
21  //------------------------------------------------------------------
22 
23  template <typename T>
24  class IndirectHolder : public BaseHolder<T> {
25  public:
26  // It may be better to use unique_ptr<RefHolderBase> in
27  // this constructor, so that the cloning can be avoided. I'm not
28  // sure if use of unique_ptr here causes any troubles elsewhere.
30  IndirectHolder(std::shared_ptr<RefHolderBase> p);
31  template< typename U>
32  IndirectHolder(std::unique_ptr<U> p): helper_(p.release()) {}
35  void swap(IndirectHolder& other);
36  virtual ~IndirectHolder();
37 
38  virtual BaseHolder<T>* clone() const override;
39  virtual T const* getPtr() const override;
40  virtual ProductID id() const override;
41  virtual size_t key() const override;
42  virtual bool isEqualTo(BaseHolder<T> const& rhs) const override;
43 
44  virtual bool fillRefIfMyTypeMatches(RefHolderBase& fillme,
45  std::string& msg) const override;
46  virtual std::unique_ptr<RefHolderBase> holder() const override;
47  virtual std::unique_ptr<BaseVectorHolder<T> > makeVectorHolder() const override;
48  virtual EDProductGetter const* productGetter() const override;
49 
52  virtual bool isAvailable() const override { return helper_->isAvailable(); }
53 
54  virtual bool isTransient() const override { return helper_->isTransient(); }
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
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  bool
141  {
142  IndirectHolder const* h = dynamic_cast<IndirectHolder const*>(&rhs);
143  return h && helper_->isEqualTo(*h->helper_);
144  }
145 
146  template <typename T>
147  bool
149  std::string& msg) const
150  {
151  return helper_->fillRefIfMyTypeMatches(fillme, msg);
152  }
153 
154  template <typename T>
155  std::unique_ptr<RefHolderBase> IndirectHolder<T>::holder() const {
156  return std::unique_ptr<RefHolderBase>( helper_->clone() );
157  }
158 
159  // Free swap function
160  template <typename T>
161  inline
162  void
164  lhs.swap(rhs);
165  }
166  }
167 
168 }
169 
172 
173 namespace edm {
174  namespace reftobase {
175  template <typename T>
176  std::unique_ptr<BaseVectorHolder<T> > IndirectHolder<T>::makeVectorHolder() const {
177  std::unique_ptr<RefVectorHolderBase> p = helper_->makeVectorHolder();
178  std::shared_ptr<RefVectorHolderBase> sp( p.release() );
179  return std::unique_ptr<BaseVectorHolder<T> >( new IndirectVectorHolder<T>( sp ) );
180  }
181  }
182 }
183 
184 #endif
virtual BaseHolder< T > * clone() const override
virtual EDProductGetter const * productGetter() const =0
virtual ProductID id() const =0
virtual size_t key() const override
virtual std::unique_ptr< RefHolderBase > holder() const override
virtual bool isAvailable() const override
#define nullptr
#define CMS_CLASS_VERSION(_version_)
Definition: classes.h:31
virtual std::unique_ptr< RefVectorHolderBase > makeVectorHolder() const =0
virtual bool isEqualTo(RefHolderBase const &rhs) const =0
virtual ProductID id() const override
IndirectHolder(std::unique_ptr< U > p)
void swap(BaseHolder &)
Definition: BaseHolder.h:108
virtual bool isEqualTo(BaseHolder< T > const &rhs) const override
virtual EDProductGetter const * productGetter() const override
virtual T const * getPtr() const override
IndirectHolder & operator=(IndirectHolder const &rhs)
virtual size_t key() const =0
void swap(edm::DataFrameContainer &lhs, edm::DataFrameContainer &rhs)
virtual std::unique_ptr< BaseVectorHolder< T > > makeVectorHolder() const override
virtual bool fillRefIfMyTypeMatches(RefHolderBase &fillme, std::string &msg) const override
def template(fileName, svg, replaceme="REPLACEME")
Definition: svgfig.py:520
void swap(IndirectHolder &other)
virtual bool isAvailable() const =0
HLT enums.
virtual bool isTransient() const override
virtual bool fillRefIfMyTypeMatches(RefHolderBase &ref, std::string &msg) const =0
virtual RefHolderBase * clone() const =0
virtual bool isTransient() const =0
long double T