CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_1/src/DataFormats/Common/interface/RefHolderBase.h

Go to the documentation of this file.
00001 #ifndef DataFormats_Common_RefHolderBase_h
00002 #define DataFormats_Common_RefHolderBase_h
00003 /* \class edm::reftobase::Base
00004  *
00005  *
00006  */
00007 #include "Reflex/Type.h"
00008 #include "FWCore/Utilities/interface/UseReflex.h"
00009 #include <memory>
00010 
00011 namespace edm {
00012   class ProductID;
00013   class EDProductGetter;
00014   namespace reftobase {
00015 
00016     class RefVectorHolderBase;
00017 
00018     class RefHolderBase {
00019     public:
00020       RefHolderBase() { }
00021       template <class T> T const* getPtr() const;
00022       virtual ~RefHolderBase();
00023       virtual RefHolderBase* clone() const = 0;
00024 
00025       virtual ProductID id() const = 0;
00026       virtual size_t key() const = 0;
00027 
00028       // Check to see if the Ref hidden in 'rhs' is equal to the Ref
00029       // hidden in 'this'. They can not be equal if they are of
00030       // different types.
00031       virtual bool isEqualTo(RefHolderBase const& rhs) const = 0;
00032 
00033       // If the type of Ref I contain matches the type contained in
00034       // 'fillme', set the Ref in 'fillme' equal to mine and return
00035       // true. If not, write the name of the type I really contain to
00036       // msg, and return false.
00037 
00038       virtual bool fillRefIfMyTypeMatches(RefHolderBase& ref,
00039                                           std::string& msg) const = 0;
00040 
00041       virtual std::auto_ptr<RefVectorHolderBase> makeVectorHolder() const = 0;
00042       virtual EDProductGetter const* productGetter() const = 0;
00043       virtual bool hasProductCache() const = 0;
00044       virtual void const * product() const = 0;
00045 
00048       virtual bool isAvailable() const = 0;
00049 
00050     private:
00051       // "cast" the real type of the element (the T of contained Ref),
00052       // and cast it to the type specified by toType, using Reflex.
00053       // Return 0 if the real type is not toType nor a subclass of
00054       // toType.
00055       virtual void const* pointerToType(Reflex::Type const& toType) const = 0;
00056     };
00057 
00058     //------------------------------------------------------------------
00059     // Implementation of RefHolderBase
00060     //------------------------------------------------------------------
00061 
00062     inline
00063     RefHolderBase::~RefHolderBase()
00064     { }
00065 
00066     template <class T>
00067     T const*
00068     RefHolderBase::getPtr() const
00069     {
00070       static Reflex::Type s_type(Reflex::Type::ByTypeInfo(typeid(T)));
00071       return static_cast<T const*>(pointerToType(s_type));
00072     }
00073 
00074   }
00075 }
00076 
00077 #endif