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  IndirectHolder(IndirectHolder const& other);
33  void swap(IndirectHolder& other);
34  virtual ~IndirectHolder();
35 
36  virtual BaseHolder<T>* clone() const;
37  virtual T const* getPtr() const;
38  virtual ProductID id() const;
39  virtual size_t key() const;
40  virtual bool isEqualTo(BaseHolder<T> const& rhs) const;
41 
42  virtual bool fillRefIfMyTypeMatches(RefHolderBase& fillme,
43  std::string& msg) const;
44  virtual std::auto_ptr<RefHolderBase> holder() const;
45  virtual std::auto_ptr<BaseVectorHolder<T> > makeVectorHolder() const;
46  virtual std::auto_ptr<RefVectorHolderBase> makeVectorBaseHolder() const;
47  virtual EDProductGetter const* productGetter() const;
48  virtual bool hasProductCache() const;
49  virtual void const * product() const;
50 
53  virtual bool isAvailable() const { return helper_->isAvailable(); }
54 
55  //Used by ROOT storage
57 
58  private:
59  friend class RefToBase<T>;
60  friend class IndirectVectorHolder<T>;
62  };
63  //------------------------------------------------------------------
64  // Implementation of IndirectHolder<T>
65  //------------------------------------------------------------------
66  template <typename T>
67  inline
68  IndirectHolder<T>::IndirectHolder(std::shared_ptr<RefHolderBase> p) :
69  BaseHolder<T>(), helper_(p->clone())
70  { }
71 
72  template <typename T>
73  inline
75  BaseHolder<T>(other), helper_(other.helper_->clone())
76  { }
77 
78  template <typename T>
79  inline
80  void
82  {
83  this->BaseHolder<T>::swap(other);
84  std::swap(helper_, other.helper_);
85  }
86 
87  template <typename T>
88  inline
91  {
92  IndirectHolder temp(rhs);
93  swap(temp);
94  return *this;
95  }
96 
97  template <typename T>
99  {
100  delete helper_;
101  }
102 
103  template <typename T>
104  BaseHolder<T>*
106  {
107  return new IndirectHolder<T>(*this);
108  }
109 
110  template <typename T>
111  T const*
113  {
114  return helper_-> template getPtr<T>();
115  }
116 
117  template <typename T>
118  ProductID
120  {
121  return helper_->id();
122  }
123 
124  template <typename T>
125  size_t
127  {
128  return helper_->key();
129  }
130 
131  template <typename T>
132  inline
134  return helper_->productGetter();
135  }
136 
137  template <typename T>
138  inline
140  return helper_->hasProductCache();
141  }
142 
143  template <typename T>
144  inline
145  void const * IndirectHolder<T>::product() const {
146  return helper_->product();
147  }
148 
149  template <typename T>
150  bool
152  {
153  IndirectHolder const* h = dynamic_cast<IndirectHolder const*>(&rhs);
154  return h && helper_->isEqualTo(*h->helper_);
155  }
156 
157  template <typename T>
158  bool
160  std::string& msg) const
161  {
162  return helper_->fillRefIfMyTypeMatches(fillme, msg);
163  }
164 
165  template <typename T>
166  std::auto_ptr<RefHolderBase> IndirectHolder<T>::holder() const {
167  return std::auto_ptr<RefHolderBase>( helper_->clone() );
168  }
169 
170  // Free swap function
171  template <typename T>
172  inline
173  void
175  lhs.swap(rhs);
176  }
177  }
178 
179 }
180 
183 
184 namespace edm {
185  namespace reftobase {
186  template <typename T>
187  std::auto_ptr<BaseVectorHolder<T> > IndirectHolder<T>::makeVectorHolder() const {
188  std::auto_ptr<RefVectorHolderBase> p = helper_->makeVectorHolder();
189  std::shared_ptr<RefVectorHolderBase> sp( p.release() );
190  return std::auto_ptr<BaseVectorHolder<T> >( new IndirectVectorHolder<T>( sp ) );
191  }
192 
193  template <typename T>
194  std::auto_ptr<RefVectorHolderBase> IndirectHolder<T>::makeVectorBaseHolder() const {
195  return helper_->makeVectorHolder();
196  }
197  }
198 }
199 
200 #endif
virtual bool fillRefIfMyTypeMatches(RefHolderBase &fillme, std::string &msg) const
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
void swap(BaseHolder &)
Definition: BaseHolder.h:109
IndirectHolder & operator=(IndirectHolder const &rhs)
void swap(edm::DataFrameContainer &lhs, edm::DataFrameContainer &rhs)
virtual T const * getPtr() const
virtual std::auto_ptr< RefVectorHolderBase > makeVectorBaseHolder() const
The Signals That Services Can Subscribe To This is based on ActivityRegistry h
Helper function to determine trigger accepts.
Definition: Activities.doc:4
virtual void const * product() const
void swap(IndirectHolder &other)
string const
Definition: compareJSON.py:14
virtual bool hasProductCache() 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:117