CMS 3D CMS Logo

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

Generated on Tue Jun 9 17:29:56 2009 for CMSSW by  doxygen 1.5.4