CMS 3D CMS Logo

BaseHolder.h
Go to the documentation of this file.
1 #ifndef DataFormats_Common_BaseHolder_h
2 #define DataFormats_Common_BaseHolder_h
3 
6 
7 #include <memory>
8 #include <string>
9 
10 namespace edm {
11  class ProductID;
12 
13  namespace reftobase {
14  class RefHolderBase;
15  template <typename T>
17  class RefVectorHolderBase;
18 
19  //------------------------------------------------------------------
20  // Class template BaseHolder<T>
21  //
22  // BaseHolder<T> is an abstract base class that manages a single
23  // edm::Ref to an element of type T in a collection in the Event;
24  // the purpose of this abstraction is to hide the type of the
25  // collection from code that can not know about that type.
26  //
27  //------------------------------------------------------------------
28  template <typename T>
29  class BaseHolder {
30  public:
31  BaseHolder();
32  virtual ~BaseHolder();
33  virtual BaseHolder<T>* clone() const = 0;
34 
35  void swap(BaseHolder&);
36 
37  // Return the address of the element to which the hidden Ref
38  // refers.
39  virtual T const* getPtr() const = 0;
40 
41  // Return the ProductID of the collection to which the hidden
42  // Ref refers.
43  virtual ProductID id() const = 0;
44  virtual size_t key() const = 0;
45  // Check to see if the Ref hidden in 'rhs' is equal to the Ref
46  // hidden in 'this'. They can not be equal if they are of
47  // different types. Note that the equality test also returns
48  // false if dynamic type of 'rhs' is different from the dynamic
49  // type of 'this', *even when the hiddens Refs are actually
50  // equivalent*.
51  virtual bool isEqualTo(BaseHolder<T> const& rhs) const = 0;
52 
53  // If the type of Ref I contain matches the type contained in
54  // 'fillme', set the Ref in 'fillme' equal to mine and return
55  // true. If not, write the name of the type I really contain to
56  // msg, and return false.
57  virtual bool fillRefIfMyTypeMatches(RefHolderBase& fillme, std::string& msg) const = 0;
58  virtual std::unique_ptr<RefHolderBase> holder() const = 0;
59 
60  virtual std::unique_ptr<BaseVectorHolder<T> > makeVectorHolder() const = 0;
61 
62  virtual EDProductGetter const* productGetter() const = 0;
63 
66  virtual bool isAvailable() const = 0;
67 
68  virtual bool isTransient() const = 0;
69 
70  //Used by ROOT storage
72 
73  protected:
74  // We want the following called only by derived classes.
77 
78  private:
79  };
80 
81  //------------------------------------------------------------------
82  // Implementation of BaseHolder<T>
83  //------------------------------------------------------------------
84 
85  template <typename T>
87 
88  template <typename T>
90  // Nothing to do.
91  }
92 
93  template <typename T>
95  // No data to assign.
96  return *this;
97  }
98 
99  template <typename T>
101  // nothing to do.
102  }
103 
104  template <typename T>
106  // nothing to do.
107  }
108 
109  // Free swap function
110  template <typename T>
111  inline void swap(BaseHolder<T>& lhs, BaseHolder<T>& rhs) {
112  lhs.swap(rhs);
113  }
114  } // namespace reftobase
115 } // namespace edm
116 
117 #endif
virtual std::unique_ptr< RefHolderBase > holder() const =0
virtual EDProductGetter const * productGetter() const =0
virtual bool isTransient() const =0
virtual T const * getPtr() const =0
virtual bool isAvailable() const =0
#define CMS_CLASS_VERSION(_version_)
virtual std::unique_ptr< BaseVectorHolder< T > > makeVectorHolder() const =0
virtual ProductID id() const =0
void swap(BaseHolder &)
Definition: BaseHolder.h:105
def template(fileName, svg, replaceme="REPLACEME")
Definition: svgfig.py:521
virtual size_t key() const =0
virtual BaseHolder< T > * clone() const =0
tuple msg
Definition: mps_check.py:285
HLT enums.
virtual bool fillRefIfMyTypeMatches(RefHolderBase &fillme, std::string &msg) const =0
long double T
virtual bool isEqualTo(BaseHolder< T > const &rhs) const =0
BaseHolder & operator=(BaseHolder const &rhs)
Definition: BaseHolder.h:94