CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
RefHolderBase.h
Go to the documentation of this file.
1 #ifndef DataFormats_Common_RefHolderBase_h
2 #define DataFormats_Common_RefHolderBase_h
3 /* \class edm::reftobase::Base
4  *
5  *
6  */
7 #include <memory>
8 #include <typeinfo>
9 
10 namespace edm {
11  class ProductID;
12  class EDProductGetter;
13  namespace reftobase {
14 
15  class RefVectorHolderBase;
16 
17  class RefHolderBase {
18  public:
19  RefHolderBase();
20  template <class T>
21  T const* getPtr() const;
22  virtual ~RefHolderBase();
23  virtual RefHolderBase* clone() const = 0;
24 
25  virtual ProductID id() const = 0;
26  virtual size_t key() const = 0;
27 
28  // Check to see if the Ref hidden in 'rhs' is equal to the Ref
29  // hidden in 'this'. They can not be equal if they are of
30  // different types.
31  virtual bool isEqualTo(RefHolderBase const& rhs) const = 0;
32 
33  // If the type of Ref I contain matches the type contained in
34  // 'fillme', set the Ref in 'fillme' equal to mine and return
35  // true. If not, write the name of the type I really contain to
36  // msg, and return false.
37 
38  virtual bool fillRefIfMyTypeMatches(RefHolderBase& ref, std::string& msg) const = 0;
39 
40  virtual std::unique_ptr<RefVectorHolderBase> makeVectorHolder() const = 0;
41  virtual EDProductGetter const* productGetter() const = 0;
42 
45  virtual bool isAvailable() const = 0;
46 
47  virtual bool isTransient() const = 0;
48 
49  private:
50  // "cast" the real type of the element (the T of contained Ref),
51  // and cast it to the type specified by toType.
52  // Return 0 if the real type is not toType nor a subclass of
53  // toType.
54  virtual void const* pointerToType(std::type_info const& toType) const = 0;
55  };
56 
57  //------------------------------------------------------------------
58  // Implementation of RefHolderBase
59  //------------------------------------------------------------------
60 
62 
63  template <class T>
64  T const* RefHolderBase::getPtr() const {
65  return static_cast<T const*>(pointerToType(typeid(T)));
66  }
67 
68  } // namespace reftobase
69 } // namespace edm
70 
71 #endif
virtual void const * pointerToType(std::type_info const &toType) const =0
virtual bool isTransient() const =0
virtual size_t key() const =0
virtual bool isAvailable() const =0
T const * getPtr() const
Definition: RefHolderBase.h:64
virtual ProductID id() const =0
virtual EDProductGetter const * productGetter() const =0
virtual bool fillRefIfMyTypeMatches(RefHolderBase &ref, std::string &msg) const =0
virtual RefHolderBase * clone() const =0
tuple msg
Definition: mps_check.py:285
virtual bool isEqualTo(RefHolderBase const &rhs) const =0
long double T
virtual std::unique_ptr< RefVectorHolderBase > makeVectorHolder() const =0