CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
BaseHolder.h
Go to the documentation of this file.
1 #ifndef DataFormats_Common_BaseHolder_h
2 #define DataFormats_Common_BaseHolder_h
3 
6 #include <string>
7 #include <memory>
8 
9 namespace edm {
10  class ProductID;
11  class RefHolderBase;
12 
13  namespace reftobase {
14  template<typename T> class BaseVectorHolder;
15  class RefVectorHolderBase;
16 
17  //------------------------------------------------------------------
18  // Class template BaseHolder<T>
19  //
20  // BaseHolder<T> is an abstract base class that manages a single
21  // edm::Ref to an element of type T in a collection in the Event;
22  // the purpose of this abstraction is to hide the type of the
23  // collection from code that can not know about that type.
24  //
25  //------------------------------------------------------------------
26  template <typename T>
27  class BaseHolder {
28  public:
29  BaseHolder();
30  virtual ~BaseHolder();
31  virtual BaseHolder<T>* clone() const = 0;
32 
33  void swap(BaseHolder&);
34 
35  // Return the address of the element to which the hidden Ref
36  // refers.
37  virtual T const* getPtr() const = 0;
38 
39  // Return the ProductID of the collection to which the hidden
40  // Ref refers.
41  virtual ProductID id() const = 0;
42  virtual size_t key() const = 0;
43  // Check to see if the Ref hidden in 'rhs' is equal to the Ref
44  // hidden in 'this'. They can not be equal if they are of
45  // different types. Note that the equality test also returns
46  // false if dynamic type of 'rhs' is different from the dynamic
47  // type of 'this', *even when the hiddens Refs are actually
48  // equivalent*.
49  virtual bool isEqualTo(BaseHolder<T> const& rhs) const = 0;
50 
51  // If the type of Ref I contain matches the type contained in
52  // 'fillme', set the Ref in 'fillme' equal to mine and return
53  // true. If not, write the name of the type I really contain to
54  // msg, and return false.
55  virtual bool fillRefIfMyTypeMatches(RefHolderBase& fillme,
56  std::string& msg) const = 0;
57  virtual std::auto_ptr<RefHolderBase> holder() const = 0;
58 
59  virtual std::auto_ptr<BaseVectorHolder<T> > makeVectorHolder() const = 0;
60  virtual std::auto_ptr<RefVectorHolderBase> makeVectorBaseHolder() const = 0;
61 
62  virtual EDProductGetter const* productGetter() const = 0;
63  virtual bool hasProductCache() const = 0;
64  virtual void const * product() const = 0;
65 
68  virtual bool isAvailable() 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  {
92  // Nothing to do.
93  }
94 
95  template <typename T>
98  {
99  // No data to assign.
100  return *this;
101  }
102 
103  template <typename T>
105  {
106  // nothing to do.
107  }
108 
109  template <typename T>
110  void
112  // nothing to do.
113  }
114 
115  // Free swap function
116  template <typename T>
117  inline
118  void
120  lhs.swap(rhs);
121  }
122  }
123 }
124 
125 #endif
virtual BaseHolder< T > * clone() const =0
virtual std::auto_ptr< RefVectorHolderBase > makeVectorBaseHolder() 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_)
virtual void const * product() const =0
virtual std::auto_ptr< BaseVectorHolder< T > > makeVectorHolder() const =0
void swap(BaseHolder &)
Definition: BaseHolder.h:111
virtual size_t key() const =0
virtual ProductID id() const =0
virtual std::auto_ptr< RefHolderBase > holder() const =0
virtual bool fillRefIfMyTypeMatches(RefHolderBase &fillme, std::string &msg) const =0
virtual EDProductGetter const * productGetter() const =0
virtual bool hasProductCache() const =0
long double T
BaseHolder & operator=(BaseHolder const &rhs)
Definition: BaseHolder.h:97
void swap(BaseHolder< T > &lhs, BaseHolder< T > &rhs)
Definition: BaseHolder.h:119