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 "boost/shared_ptr.hpp"
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(boost::shared_ptr<RefHolderBase> p);
32  IndirectHolder(IndirectHolder const& other);
34  void swap(IndirectHolder& other);
35  virtual ~IndirectHolder();
36 
37  virtual BaseHolder<T>* clone() const;
38  virtual T const* getPtr() const;
39  virtual ProductID id() const;
40  virtual size_t key() const;
41  virtual bool isEqualTo(BaseHolder<T> const& rhs) const;
42 
43  virtual bool fillRefIfMyTypeMatches(RefHolderBase& fillme,
44  std::string& msg) const;
45  virtual std::auto_ptr<RefHolderBase> holder() const;
46  virtual std::auto_ptr<BaseVectorHolder<T> > makeVectorHolder() const;
47  virtual std::auto_ptr<RefVectorHolderBase> makeVectorBaseHolder() const;
48  virtual EDProductGetter const* productGetter() const;
49  virtual bool hasProductCache() const;
50  virtual void const * product() const;
51 
54  virtual bool isAvailable() const { return helper_->isAvailable(); }
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 
68  template <typename T>
69  inline
70  IndirectHolder<T>::IndirectHolder(boost::shared_ptr<RefHolderBase> p) :
71  BaseHolder<T>(), helper_(p->clone())
72  { }
73 
74  template <typename T>
75  inline
77  BaseHolder<T>(other), helper_(other.helper_->clone())
78  { }
79 
80  template <typename T>
81  inline
82  void
84  {
85  this->BaseHolder<T>::swap(other);
86  std::swap(helper_, other.helper_);
87  }
88 
89  template <typename T>
90  inline
93  {
94  IndirectHolder temp(rhs);
95  swap(temp);
96  return *this;
97  }
98 
99  template <typename T>
101  {
102  delete helper_;
103  }
104 
105  template <typename T>
106  BaseHolder<T>*
108  {
109  return new IndirectHolder<T>(*this);
110  }
111 
112  template <typename T>
113  T const*
115  {
116  return helper_-> template getPtr<T>();
117  }
118 
119  template <typename T>
120  ProductID
122  {
123  return helper_->id();
124  }
125 
126  template <typename T>
127  size_t
129  {
130  return helper_->key();
131  }
132 
133  template <typename T>
134  inline
136  return helper_->productGetter();
137  }
138 
139  template <typename T>
140  inline
142  return helper_->hasProductCache();
143  }
144 
145  template <typename T>
146  inline
147  void const * IndirectHolder<T>::product() const {
148  return helper_->product();
149  }
150 
151  template <typename T>
152  bool
154  {
155  IndirectHolder const* h = dynamic_cast<IndirectHolder const*>(&rhs);
156  return h && helper_->isEqualTo(*h->helper_);
157  }
158 
159  template <typename T>
160  bool
162  std::string& msg) const
163  {
164  return helper_->fillRefIfMyTypeMatches(fillme, msg);
165  }
166 
167  template <typename T>
168  std::auto_ptr<RefHolderBase> IndirectHolder<T>::holder() const {
169  return std::auto_ptr<RefHolderBase>( helper_->clone() );
170  }
171 
172  // Free swap function
173  template <typename T>
174  inline
175  void
177  lhs.swap(rhs);
178  }
179  }
180 
181 }
182 
185 
186 namespace edm {
187  namespace reftobase {
188  template <typename T>
189  std::auto_ptr<BaseVectorHolder<T> > IndirectHolder<T>::makeVectorHolder() const {
190  std::auto_ptr<RefVectorHolderBase> p = helper_->makeVectorHolder();
191  boost::shared_ptr<RefVectorHolderBase> sp( p );
192  return std::auto_ptr<BaseVectorHolder<T> >( new IndirectVectorHolder<T>( sp ) );
193  }
194 
195  template <typename T>
196  std::auto_ptr<RefVectorHolderBase> IndirectHolder<T>::makeVectorBaseHolder() const {
197  return helper_->makeVectorHolder();
198  }
199  }
200 }
201 
202 #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_)
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
virtual void const * product() const
void swap(IndirectHolder &other)
The Signals That Services Can Subscribe To This is based on ActivityRegistry h
Helper function to determine trigger accepts.
Definition: Activities.doc:4
string const
Definition: compareJSON.py:14
virtual bool hasProductCache() const
virtual ProductID id() const
#define private
Definition: FWFileEntry.h:18
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