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> class BaseVectorHolder;
16  class RefVectorHolderBase;
17 
18  //------------------------------------------------------------------
19  // Class template BaseHolder<T>
20  //
21  // BaseHolder<T> is an abstract base class that manages a single
22  // edm::Ref to an element of type T in a collection in the Event;
23  // the purpose of this abstraction is to hide the type of the
24  // collection from code that can not know about that type.
25  //
26  //------------------------------------------------------------------
27  template <typename T>
28  class BaseHolder {
29  public:
30  BaseHolder();
31  virtual ~BaseHolder();
32  virtual BaseHolder<T>* clone() const = 0;
33 
34  void swap(BaseHolder&);
35 
36  // Return the address of the element to which the hidden Ref
37  // refers.
38  virtual T const* getPtr() const = 0;
39 
40  // Return the ProductID of the collection to which the hidden
41  // Ref refers.
42  virtual ProductID id() const = 0;
43  virtual size_t key() const = 0;
44  // Check to see if the Ref hidden in 'rhs' is equal to the Ref
45  // hidden in 'this'. They can not be equal if they are of
46  // different types. Note that the equality test also returns
47  // false if dynamic type of 'rhs' is different from the dynamic
48  // type of 'this', *even when the hiddens Refs are actually
49  // equivalent*.
50  virtual bool isEqualTo(BaseHolder<T> const& rhs) const = 0;
51 
52  // If the type of Ref I contain matches the type contained in
53  // 'fillme', set the Ref in 'fillme' equal to mine and return
54  // true. If not, write the name of the type I really contain to
55  // msg, and return false.
56  virtual bool fillRefIfMyTypeMatches(RefHolderBase& fillme,
57  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.
75  BaseHolder(BaseHolder const& other);
76  BaseHolder& operator=(BaseHolder const& rhs);
77 
78  private:
79  };
80 
81  //------------------------------------------------------------------
82  // Implementation of BaseHolder<T>
83  //------------------------------------------------------------------
84 
85  template <typename T>
87  }
88 
89  template <typename T>
91  // Nothing to do.
92  }
93 
94  template <typename T>
97  // No data to assign.
98  return *this;
99  }
100 
101  template <typename T>
103  // nothing to do.
104  }
105 
106  template <typename T>
107  void
109  // nothing to do.
110  }
111 
112  // Free swap function
113  template <typename T>
114  inline
115  void
117  lhs.swap(rhs);
118  }
119  }
120 }
121 
122 #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_)
Definition: classes.h:31
virtual std::unique_ptr< BaseVectorHolder< T > > makeVectorHolder() const =0
virtual ProductID id() const =0
void swap(BaseHolder &)
Definition: BaseHolder.h:108
def template(fileName, svg, replaceme="REPLACEME")
Definition: svgfig.py:520
virtual size_t key() const =0
virtual BaseHolder< T > * clone() const =0
tuple msg
Definition: mps_check.py:278
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:96