Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-12-24 02:18:30

0001 #ifndef DataFormats_Common_RefHolderBase_h
0002 #define DataFormats_Common_RefHolderBase_h
0003 /* \class edm::reftobase::Base
0004  *
0005  *
0006  */
0007 #include <memory>
0008 #include <typeinfo>
0009 
0010 namespace edm {
0011   class ProductID;
0012   class EDProductGetter;
0013   namespace reftobase {
0014 
0015     class RefVectorHolderBase;
0016 
0017     class RefHolderBase {
0018     public:
0019       RefHolderBase();
0020       template <class T>
0021       T const* getPtr() const;
0022       virtual ~RefHolderBase();
0023       virtual RefHolderBase* clone() const = 0;
0024 
0025       virtual ProductID id() const = 0;
0026       virtual size_t key() const = 0;
0027 
0028       // Check to see if the Ref hidden in 'rhs' is equal to the Ref
0029       // hidden in 'this'. They can not be equal if they are of
0030       // different types.
0031       virtual bool isEqualTo(RefHolderBase const& rhs) const = 0;
0032 
0033       virtual std::unique_ptr<RefVectorHolderBase> makeVectorHolder() const = 0;
0034       virtual EDProductGetter const* productGetter() const = 0;
0035 
0036       /// Checks if product collection is in memory or available
0037       /// in the Event. No type checking is done.
0038       virtual bool isAvailable() const = 0;
0039 
0040       virtual bool isTransient() const = 0;
0041 
0042     private:
0043       // "cast" the real type of the element (the T of contained Ref),
0044       // and cast it to the type specified by toType.
0045       // Return 0 if the real type is not toType nor a subclass of
0046       // toType.
0047       virtual void const* pointerToType(std::type_info const& toType) const = 0;
0048     };
0049 
0050     //------------------------------------------------------------------
0051     // Implementation of RefHolderBase
0052     //------------------------------------------------------------------
0053 
0054     inline RefHolderBase::~RefHolderBase() {}
0055 
0056     template <class T>
0057     T const* RefHolderBase::getPtr() const {
0058       return static_cast<T const*>(pointerToType(typeid(T)));
0059     }
0060 
0061   }  // namespace reftobase
0062 }  // namespace edm
0063 
0064 #endif