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 
9 namespace edm {
10  class ProductID;
11 
12  namespace reftobase {
13  class RefHolderBase;
14  template <typename T>
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  virtual std::unique_ptr<RefHolderBase> holder() const = 0;
53 
54  virtual std::unique_ptr<BaseVectorHolder<T> > makeVectorHolder() const = 0;
55 
56  virtual EDProductGetter const* productGetter() const = 0;
57 
60  virtual bool isAvailable() const = 0;
61 
62  virtual bool isTransient() const = 0;
63 
64  //Used by ROOT storage
66 
67  protected:
68  // We want the following called only by derived classes.
71 
72  private:
73  };
74 
75  //------------------------------------------------------------------
76  // Implementation of BaseHolder<T>
77  //------------------------------------------------------------------
78 
79  template <typename T>
81 
82  template <typename T>
84  // Nothing to do.
85  }
86 
87  template <typename T>
89  // No data to assign.
90  return *this;
91  }
92 
93  template <typename T>
95  // nothing to do.
96  }
97 
98  template <typename T>
100  // nothing to do.
101  }
102 
103  // Free swap function
104  template <typename T>
105  inline void swap(BaseHolder<T>& lhs, BaseHolder<T>& rhs) {
106  lhs.swap(rhs);
107  }
108  } // namespace reftobase
109 } // namespace edm
110 
111 #endif
virtual BaseHolder< T > * clone() const =0
virtual bool isTransient() const =0
virtual bool isEqualTo(BaseHolder< T > const &rhs) const =0
virtual T const * getPtr() const =0
virtual bool isAvailable() const =0
#define CMS_CLASS_VERSION(_version_)
void swap(BaseHolder &)
Definition: BaseHolder.h:99
virtual size_t key() const =0
virtual ProductID id() const =0
virtual std::unique_ptr< BaseVectorHolder< T > > makeVectorHolder() const =0
def template(fileName, svg, replaceme="REPLACEME")
Definition: svgfig.py:521
virtual EDProductGetter const * productGetter() const =0
HLT enums.
long double T
BaseHolder & operator=(BaseHolder const &rhs)
Definition: BaseHolder.h:88
virtual std::unique_ptr< RefHolderBase > holder() const =0