CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_4_1_8_patch9/src/DataFormats/Common/interface/BaseHolder.h

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