00001 #ifndef DataFormats_Common_BaseHolder_h 00002 #define DataFormats_Common_BaseHolder_h 00003 00004 #include "DataFormats/Common/interface/EDProductGetter.h" 00005 #include <string> 00006 00007 namespace edm { 00008 class ProductID; 00009 class RefHolderBase; 00010 00011 namespace reftobase { 00012 template<typename T> class BaseVectorHolder; 00013 class RefVectorHolderBase; 00014 00015 //------------------------------------------------------------------ 00016 // Class template BaseHolder<T> 00017 // 00018 // BaseHolder<T> is an abstract base class that manages a single 00019 // edm::Ref to an element of type T in a collection in the Event; 00020 // the purpose of this abstraction is to hide the type of the 00021 // collection from code that can not know about that type. 00022 // 00023 //------------------------------------------------------------------ 00024 template <typename T> 00025 class BaseHolder { 00026 public: 00027 BaseHolder(); 00028 virtual ~BaseHolder(); 00029 virtual BaseHolder<T>* clone() const = 0; 00030 00031 void swap(BaseHolder&); 00032 00033 // Return the address of the element to which the hidden Ref 00034 // refers. 00035 virtual T const* getPtr() const = 0; 00036 00037 // Return the ProductID of the collection to which the hidden 00038 // Ref refers. 00039 virtual ProductID id() const = 0; 00040 virtual size_t key() const = 0; 00041 // Check to see if the Ref hidden in 'rhs' is equal to the Ref 00042 // hidden in 'this'. They can not be equal if they are of 00043 // different types. Note that the equality test also returns 00044 // false if dynamic type of 'rhs' is different from the dynamic 00045 // type of 'this', *even when the hiddens Refs are actually 00046 // equivalent*. 00047 virtual bool isEqualTo(BaseHolder<T> const& rhs) const = 0; 00048 00049 // If the type of Ref I contain matches the type contained in 00050 // 'fillme', set the Ref in 'fillme' equal to mine and return 00051 // true. If not, write the name of the type I really contain to 00052 // msg, and return false. 00053 virtual bool fillRefIfMyTypeMatches(RefHolderBase& fillme, 00054 std::string& msg) const = 0; 00055 virtual std::auto_ptr<RefHolderBase> holder() const = 0; 00056 00057 virtual std::auto_ptr<BaseVectorHolder<T> > makeVectorHolder() const = 0; 00058 virtual std::auto_ptr<RefVectorHolderBase> makeVectorBaseHolder() const = 0; 00059 00060 virtual EDProductGetter const* productGetter() const = 0; 00061 virtual bool hasProductCache() const = 0; 00062 virtual void const * product() const = 0; 00063 00066 virtual bool isAvailable() const = 0; 00067 00068 protected: 00069 // We want the following called only by derived classes. 00070 BaseHolder(BaseHolder const& other); 00071 BaseHolder& operator= (BaseHolder const& rhs); 00072 00073 private: 00074 }; 00075 00076 //------------------------------------------------------------------ 00077 // Implementation of BaseHolder<T> 00078 //------------------------------------------------------------------ 00079 00080 template <typename T> 00081 BaseHolder<T>::BaseHolder() 00082 { } 00083 00084 template <typename T> 00085 BaseHolder<T>::BaseHolder(BaseHolder const& other) 00086 { 00087 // Nothing to do. 00088 } 00089 00090 template <typename T> 00091 BaseHolder<T>& 00092 BaseHolder<T>::operator= (BaseHolder<T> const& other) 00093 { 00094 // No data to assign. 00095 return *this; 00096 } 00097 00098 template <typename T> 00099 BaseHolder<T>::~BaseHolder() 00100 { 00101 // nothing to do. 00102 } 00103 00104 template <typename T> 00105 void 00106 BaseHolder<T>::swap(BaseHolder<T>& other) { 00107 // nothing to do. 00108 } 00109 00110 // Free swap function 00111 template <typename T> 00112 inline 00113 void 00114 swap(BaseHolder<T>& lhs, BaseHolder<T>& rhs) { 00115 lhs.swap(rhs); 00116 } 00117 } 00118 } 00119 00120 #endif