test
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
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 auto_ptr<RefHolderBase> in
27  // this constructor, so that the cloning can be avoided. I'm not
28  // sure if use of auto_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()) {}
33  IndirectHolder(IndirectHolder const& other);
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::auto_ptr<RefHolderBase> holder() const override;
47  virtual std::auto_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
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  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::auto_ptr<RefHolderBase> IndirectHolder<T>::holder() const {
156  return std::auto_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::auto_ptr<BaseVectorHolder<T> > IndirectHolder<T>::makeVectorHolder() const {
177  std::auto_ptr<RefVectorHolderBase> p = helper_->makeVectorHolder();
178  std::shared_ptr<RefVectorHolderBase> sp( p.release() );
179  return std::auto_ptr<BaseVectorHolder<T> >( new IndirectVectorHolder<T>( sp ) );
180  }
181  }
182 }
183 
184 #endif
virtual bool isTransient() const =0
FWCore Framework interface EventSetupRecordImplementation h
Helper function to determine trigger accepts.
virtual bool fillRefIfMyTypeMatches(RefHolderBase &fillme, std::string &msg) const override
virtual T const * getPtr() const override
virtual BaseHolder< T > * clone() const override
virtual bool isAvailable() const override
virtual bool isAvailable() const =0
#define nullptr
#define CMS_CLASS_VERSION(_version_)
Definition: classes.h:31
virtual std::auto_ptr< RefHolderBase > holder() const override
IndirectHolder(std::unique_ptr< U > p)
void swap(BaseHolder &)
Definition: BaseHolder.h:108
virtual bool isTransient() const override
virtual size_t key() const override
IndirectHolder & operator=(IndirectHolder const &rhs)
void swap(edm::DataFrameContainer &lhs, edm::DataFrameContainer &rhs)
virtual ProductID id() const override
virtual EDProductGetter const * productGetter() const override
virtual bool isEqualTo(BaseHolder< T > const &rhs) const override
virtual std::auto_ptr< BaseVectorHolder< T > > makeVectorHolder() const override
void swap(IndirectHolder &other)
string const
Definition: compareJSON.py:14
Definition: sp.h:21
ProductIndex id() const
Definition: ProductID.h:38
long double T
def template
Definition: svgfig.py:520
void swap(BaseHolder< T > &lhs, BaseHolder< T > &rhs)
Definition: BaseHolder.h:116