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 #ifndef __GCCXML__
33  template< typename U>
34  IndirectHolder(std::unique_ptr<U> p): helper_(p.release()) {}
35 #endif
36  IndirectHolder(IndirectHolder const& other);
38  void swap(IndirectHolder& other);
39  virtual ~IndirectHolder();
40 
42  virtual T const* getPtr() const GCC11_OVERRIDE;
43  virtual ProductID id() const GCC11_OVERRIDE;
44  virtual size_t key() const GCC11_OVERRIDE;
45  virtual bool isEqualTo(BaseHolder<T> const& rhs) const GCC11_OVERRIDE;
46 
47  virtual bool fillRefIfMyTypeMatches(RefHolderBase& fillme,
48  std::string& msg) const GCC11_OVERRIDE;
49  virtual std::auto_ptr<RefHolderBase> holder() const GCC11_OVERRIDE;
50  virtual std::auto_ptr<BaseVectorHolder<T> > makeVectorHolder() const GCC11_OVERRIDE;
51  virtual EDProductGetter const* productGetter() const GCC11_OVERRIDE;
52 
55  virtual bool isAvailable() const GCC11_OVERRIDE { return helper_->isAvailable(); }
56 
57  virtual bool isTransient() const GCC11_OVERRIDE { return helper_->isTransient(); }
58 
59  //Used by ROOT storage
61 
62  private:
63  friend class RefToBase<T>;
64  friend class IndirectVectorHolder<T>;
66  };
67  //------------------------------------------------------------------
68  // Implementation of IndirectHolder<T>
69  //------------------------------------------------------------------
70  template <typename T>
71  inline
72  IndirectHolder<T>::IndirectHolder(std::shared_ptr<RefHolderBase> p) :
73  BaseHolder<T>(), helper_(p->clone())
74  { }
75 
76  template <typename T>
77  inline
79  BaseHolder<T>(other), helper_(other.helper_->clone())
80  { }
81 
82  template <typename T>
83  inline
84  void
86  {
87  this->BaseHolder<T>::swap(other);
88  std::swap(helper_, other.helper_);
89  }
90 
91  template <typename T>
92  inline
95  {
96  IndirectHolder temp(rhs);
97  swap(temp);
98  return *this;
99  }
100 
101  template <typename T>
103  {
104  delete helper_;
105  }
106 
107  template <typename T>
108  BaseHolder<T>*
110  {
111  return new IndirectHolder<T>(*this);
112  }
113 
114  template <typename T>
115  T const*
117  {
118  return helper_-> template getPtr<T>();
119  }
120 
121  template <typename T>
122  ProductID
124  {
125  return helper_->id();
126  }
127 
128  template <typename T>
129  size_t
131  {
132  return helper_->key();
133  }
134 
135  template <typename T>
136  inline
138  return helper_->productGetter();
139  }
140 
141  template <typename T>
142  bool
144  {
145  IndirectHolder const* h = dynamic_cast<IndirectHolder const*>(&rhs);
146  return h && helper_->isEqualTo(*h->helper_);
147  }
148 
149  template <typename T>
150  bool
152  std::string& msg) const
153  {
154  return helper_->fillRefIfMyTypeMatches(fillme, msg);
155  }
156 
157  template <typename T>
158  std::auto_ptr<RefHolderBase> IndirectHolder<T>::holder() const {
159  return std::auto_ptr<RefHolderBase>( helper_->clone() );
160  }
161 
162  // Free swap function
163  template <typename T>
164  inline
165  void
167  lhs.swap(rhs);
168  }
169  }
170 
171 }
172 
175 
176 namespace edm {
177  namespace reftobase {
178  template <typename T>
179  std::auto_ptr<BaseVectorHolder<T> > IndirectHolder<T>::makeVectorHolder() const {
180  std::auto_ptr<RefVectorHolderBase> p = helper_->makeVectorHolder();
181  std::shared_ptr<RefVectorHolderBase> sp( p.release() );
182  return std::auto_ptr<BaseVectorHolder<T> >( new IndirectVectorHolder<T>( sp ) );
183  }
184  }
185 }
186 
187 #endif
#define GCC11_OVERRIDE
virtual bool fillRefIfMyTypeMatches(RefHolderBase &fillme, std::string &msg) const
virtual bool isTransient() const =0
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
IndirectHolder(std::unique_ptr< U > p)
void swap(BaseHolder &)
Definition: BaseHolder.h:108
IndirectHolder & operator=(IndirectHolder const &rhs)
void swap(edm::DataFrameContainer &lhs, edm::DataFrameContainer &rhs)
virtual T const * getPtr() const
The Signals That Services Can Subscribe To This is based on ActivityRegistry h
Helper function to determine trigger accepts.
Definition: Activities.doc:4
void swap(IndirectHolder &other)
string const
Definition: compareJSON.py:14
virtual bool isTransient() 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:116