CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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>
12  class RefToBase;
13 
14  namespace reftobase {
15 
16  template <typename T>
18  class RefVectorHolderBase;
19  class RefHolderBase;
20 
21  //------------------------------------------------------------------
22  // Class template IndirectHolder<T>
23  //------------------------------------------------------------------
24 
25  template <typename T>
26  class IndirectHolder : public BaseHolder<T> {
27  public:
28  // It may be better to use unique_ptr<RefHolderBase> in
29  // this constructor, so that the cloning can be avoided. I'm not
30  // sure if use of unique_ptr here causes any troubles elsewhere.
31  IndirectHolder() : BaseHolder<T>(), helper_(nullptr) {}
32  IndirectHolder(std::shared_ptr<RefHolderBase> p);
33  template <typename U>
34  IndirectHolder(std::unique_ptr<U> p) : helper_(p.release()) {}
35  IndirectHolder(IndirectHolder const& other);
37  void swap(IndirectHolder& other);
38  ~IndirectHolder() override;
39 
40  BaseHolder<T>* clone() const override;
41  T const* getPtr() const override;
42  ProductID id() const override;
43  size_t key() const override;
44  bool isEqualTo(BaseHolder<T> const& rhs) const override;
45 
46  bool fillRefIfMyTypeMatches(RefHolderBase& fillme, std::string& msg) const override;
47  std::unique_ptr<RefHolderBase> holder() const override;
48  std::unique_ptr<BaseVectorHolder<T> > makeVectorHolder() const override;
49  EDProductGetter const* productGetter() const override;
50 
53  bool isAvailable() const override { return helper_->isAvailable(); }
54 
55  bool isTransient() const override { return helper_->isTransient(); }
56 
57  //Used by ROOT storage
59 
60  private:
61  friend class RefToBase<T>;
62  friend class IndirectVectorHolder<T>;
64  };
65  //------------------------------------------------------------------
66  // Implementation of IndirectHolder<T>
67  //------------------------------------------------------------------
68  template <typename T>
69  inline IndirectHolder<T>::IndirectHolder(std::shared_ptr<RefHolderBase> p) : BaseHolder<T>(), helper_(p->clone()) {}
70 
71  template <typename T>
73  : BaseHolder<T>(other), helper_(other.helper_->clone()) {}
74 
75  template <typename T>
77  this->BaseHolder<T>::swap(other);
78  std::swap(helper_, other.helper_);
79  }
80 
81  template <typename T>
83  IndirectHolder temp(rhs);
84  swap(temp);
85  return *this;
86  }
87 
88  template <typename T>
90  delete helper_;
91  }
92 
93  template <typename T>
95  return new IndirectHolder<T>(*this);
96  }
97 
98  template <typename T>
99  T const* IndirectHolder<T>::getPtr() const {
100  return helper_->template getPtr<T>();
101  }
102 
103  template <typename T>
105  return helper_->id();
106  }
107 
108  template <typename T>
109  size_t IndirectHolder<T>::key() const {
110  return helper_->key();
111  }
112 
113  template <typename T>
115  return helper_->productGetter();
116  }
117 
118  template <typename T>
120  IndirectHolder const* h = dynamic_cast<IndirectHolder const*>(&rhs);
121  return h && helper_->isEqualTo(*h->helper_);
122  }
123 
124  template <typename T>
126  return helper_->fillRefIfMyTypeMatches(fillme, msg);
127  }
128 
129  template <typename T>
130  std::unique_ptr<RefHolderBase> IndirectHolder<T>::holder() const {
131  return std::unique_ptr<RefHolderBase>(helper_->clone());
132  }
133 
134  // Free swap function
135  template <typename T>
136  inline void swap(IndirectHolder<T>& lhs, IndirectHolder<T>& rhs) {
137  lhs.swap(rhs);
138  }
139  } // namespace reftobase
140 
141 } // namespace edm
142 
145 
146 namespace edm {
147  namespace reftobase {
148  template <typename T>
149  std::unique_ptr<BaseVectorHolder<T> > IndirectHolder<T>::makeVectorHolder() const {
150  std::unique_ptr<RefVectorHolderBase> p = helper_->makeVectorHolder();
151  std::shared_ptr<RefVectorHolderBase> sp(p.release());
152  return std::unique_ptr<BaseVectorHolder<T> >(new IndirectVectorHolder<T>(sp));
153  }
154  } // namespace reftobase
155 } // namespace edm
156 
157 #endif
std::unique_ptr< RefHolderBase > holder() const override
bool isAvailable() const override
virtual bool isTransient() const =0
bool isTransient() const override
bool fillRefIfMyTypeMatches(RefHolderBase &fillme, std::string &msg) const override
T const * getPtr() const override
BaseHolder< T > * clone() const override
virtual bool isAvailable() const =0
#define CMS_CLASS_VERSION(_version_)
IndirectHolder(std::unique_ptr< U > p)
void swap(BaseHolder &)
Definition: BaseHolder.h:105
size_t key() const override
IndirectHolder & operator=(IndirectHolder const &rhs)
void swap(edm::DataFrameContainer &lhs, edm::DataFrameContainer &rhs)
ProductID id() const override
EDProductGetter const * productGetter() const override
bool isEqualTo(BaseHolder< T > const &rhs) const override
void swap(IndirectHolder &other)
tuple msg
Definition: mps_check.py:285
std::unique_ptr< BaseVectorHolder< T > > makeVectorHolder() const override
ProductIndex id() const
Definition: ProductID.h:35
The Signals That Services Can Subscribe To This is based on ActivityRegistry h
Helper function to determine trigger accepts.
Definition: Activities.doc:4
long double T
def template
Definition: svgfig.py:521
void swap(BaseHolder< T > &lhs, BaseHolder< T > &rhs)
Definition: BaseHolder.h:111