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  std::unique_ptr<RefHolderBase> holder() const override;
47  std::unique_ptr<BaseVectorHolder<T> > makeVectorHolder() const override;
48  EDProductGetter const* productGetter() const override;
49 
52  bool isAvailable() const override { return helper_->isAvailable(); }
53 
54  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 IndirectHolder<T>::IndirectHolder(std::shared_ptr<RefHolderBase> p) : BaseHolder<T>(), helper_(p->clone()) {}
69 
70  template <typename T>
72  : BaseHolder<T>(other), helper_(other.helper_->clone()) {}
73 
74  template <typename T>
76  this->BaseHolder<T>::swap(other);
77  std::swap(helper_, other.helper_);
78  }
79 
80  template <typename T>
82  IndirectHolder temp(rhs);
83  swap(temp);
84  return *this;
85  }
86 
87  template <typename T>
89  delete helper_;
90  }
91 
92  template <typename T>
94  return new IndirectHolder<T>(*this);
95  }
96 
97  template <typename T>
98  T const* IndirectHolder<T>::getPtr() const {
99  return helper_->template getPtr<T>();
100  }
101 
102  template <typename T>
104  return helper_->id();
105  }
106 
107  template <typename T>
108  size_t IndirectHolder<T>::key() const {
109  return helper_->key();
110  }
111 
112  template <typename T>
114  return helper_->productGetter();
115  }
116 
117  template <typename T>
119  IndirectHolder const* h = dynamic_cast<IndirectHolder const*>(&rhs);
120  return h && helper_->isEqualTo(*h->helper_);
121  }
122 
123  template <typename T>
124  std::unique_ptr<RefHolderBase> IndirectHolder<T>::holder() const {
125  return std::unique_ptr<RefHolderBase>(helper_->clone());
126  }
127 
128  // Free swap function
129  template <typename T>
130  inline void swap(IndirectHolder<T>& lhs, IndirectHolder<T>& rhs) {
131  lhs.swap(rhs);
132  }
133  } // namespace reftobase
134 
135 } // namespace edm
136 
139 
140 namespace edm {
141  namespace reftobase {
142  template <typename T>
143  std::unique_ptr<BaseVectorHolder<T> > IndirectHolder<T>::makeVectorHolder() const {
144  std::unique_ptr<RefVectorHolderBase> p = helper_->makeVectorHolder();
145  std::shared_ptr<RefVectorHolderBase> sp(p.release());
146  return std::unique_ptr<BaseVectorHolder<T> >(new IndirectVectorHolder<T>(sp));
147  }
148  } // namespace reftobase
149 } // namespace edm
150 
151 #endif
std::unique_ptr< RefHolderBase > holder() const override
bool isAvailable() const override
virtual bool isTransient() const =0
bool isTransient() 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:99
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)
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:105