CMS 3D CMS Logo

Holder.h

Go to the documentation of this file.
00001 
00002 #ifndef DataFormats_Common_Holder_h
00003 #define DataFormats_Common_Holder_h
00004 #include "DataFormats/Common/interface/BaseHolder.h"
00005 #include "DataFormats/Common/interface/RefHolder.h"
00006 
00007 namespace edm {
00008   namespace reftobase {
00009    //------------------------------------------------------------------
00010     // Class template Holder<T,REF>
00011     //------------------------------------------------------------------
00012 
00013     template <class T, class REF>
00014     class Holder : public BaseHolder<T> {
00015     public:
00016       Holder();
00017       Holder(Holder const& other);
00018       explicit Holder(REF const& iRef);
00019       Holder& operator= (Holder const& rhs);
00020       void swap(Holder& other);
00021       virtual ~Holder();
00022       virtual BaseHolder<T>* clone() const;
00023 
00024       virtual T const* getPtr() const;
00025       virtual ProductID id() const;
00026       virtual size_t key() const;
00027       virtual bool isEqualTo(BaseHolder<T> const& rhs) const;
00028       REF const& getRef() const;
00029 
00030       virtual bool fillRefIfMyTypeMatches(RefHolderBase& fillme,
00031                                           std::string& msg) const;
00032 
00033       virtual std::auto_ptr<RefHolderBase> holder() const {
00034         return std::auto_ptr<RefHolderBase>( new RefHolder<REF>( ref_ ) );
00035       }
00036       virtual std::auto_ptr<BaseVectorHolder<T> > makeVectorHolder() const;
00037       virtual std::auto_ptr<RefVectorHolderBase> makeVectorBaseHolder() const;
00038       virtual EDProductGetter const* productGetter() const;
00039       virtual bool hasProductCache() const;
00040       virtual void const * product() const;
00041 
00044       virtual bool isAvailable() const { return ref_.isAvailable(); }
00045 
00046     private:
00047       REF ref_;
00048     };
00049 
00050     //------------------------------------------------------------------
00051     // Implementation of Holder<T,REF>
00052     //------------------------------------------------------------------
00053 
00054     template <class T, class REF>
00055     inline
00056     Holder<T,REF>::Holder() : 
00057       ref_()
00058     {  }
00059 
00060     template <class T, class REF>
00061     inline
00062     Holder<T,REF>::Holder(Holder const& other) :
00063       ref_(other.ref_)
00064     { }
00065 
00066     template <class T, class REF>
00067     inline
00068     Holder<T,REF>::Holder(REF const& r) :
00069       ref_(r)
00070     { }
00071 
00072     template <class T, class REF>
00073     inline
00074     Holder<T,REF> &
00075     Holder<T,REF>::operator=(Holder const& rhs)
00076     {
00077       Holder temp(rhs);
00078       swap(temp);
00079       return *this;
00080     }
00081 
00082     template <class T, class REF>
00083     inline
00084     void
00085     Holder<T,REF>::swap(Holder& other)
00086     {
00087       std::swap(ref_, other.ref_);
00088     }
00089 
00090     template <class T, class REF>
00091     inline
00092     Holder<T,REF>::~Holder()
00093     { }
00094 
00095     template <class T, class REF>
00096     inline
00097     BaseHolder<T>*
00098     Holder<T,REF>::clone() const 
00099     {
00100       return new Holder(*this);
00101     }
00102 
00103     template <class T, class REF>
00104     inline
00105     T const*
00106     Holder<T,REF>::getPtr() const
00107     {
00108       return ref_.operator->();
00109     }
00110 
00111     template <class T, class REF>
00112     inline
00113     ProductID
00114     Holder<T,REF>::id() const
00115     {
00116       return ref_.id();
00117     }
00118 
00119     template <class T, class REF>
00120     inline
00121     bool
00122     Holder<T,REF>::isEqualTo(BaseHolder<T> const& rhs) const
00123     {
00124       Holder const* h = dynamic_cast<Holder const*>(&rhs);
00125       return h && (getRef() == h->getRef());
00126       //       if (h == 0) return false;
00127       //       return getRef() == h->getRef();
00128     }
00129 
00130     template <class T, class REF>
00131     inline
00132     REF const&
00133     Holder<T,REF>::getRef() const
00134     {
00135       return ref_;
00136     }
00137 
00138     template <class T, class REF>
00139     inline
00140     EDProductGetter const* Holder<T,REF>::productGetter() const {
00141       return ref_.productGetter();
00142     }
00143 
00144     template <class T, class REF>
00145     inline
00146     bool Holder<T,REF>::hasProductCache() const {
00147       return ref_.hasProductCache();
00148     }
00149 
00150     template <class T, class REF>
00151     inline
00152     void const * Holder<T,REF>::product() const {
00153       return ref_.product();
00154     }
00155 
00156     template <class T, class REF>
00157     bool
00158     Holder<T,REF>::fillRefIfMyTypeMatches(RefHolderBase& fillme,
00159                                           std::string& msg) const
00160     {
00161       RefHolder<REF>* h = dynamic_cast<RefHolder<REF>*>(&fillme);
00162       bool conversion_worked = (h != 0);
00163 
00164       if (conversion_worked)
00165         h->setRef(ref_);
00166       else
00167         msg = typeid(REF).name();
00168 
00169       return conversion_worked;
00170     }
00171 
00172   }
00173 }
00174 
00175 #include "DataFormats/Common/interface/HolderToVectorTrait.h"
00176 #include "DataFormats/Common/interface/Ref.h"
00177 
00178 namespace edm {
00179   namespace reftobase {
00180 
00181     template <typename T, typename REF>
00182     std::auto_ptr<BaseVectorHolder<T> > Holder<T,REF>::makeVectorHolder() const {
00183       typedef typename HolderToVectorTrait<T, REF>::type helper;
00184       return helper::makeVectorHolder();
00185     }
00186 
00187     template <typename T, typename REF>
00188     std::auto_ptr<RefVectorHolderBase> Holder<T,REF>::makeVectorBaseHolder() const {
00189       typedef typename HolderToVectorTrait<T, REF>::type helper;
00190       return helper::makeVectorBaseHolder();
00191     }
00192 
00193   }
00194 }
00195 
00196 #include "DataFormats/Common/interface/RefKeyTrait.h"
00197 
00198 namespace edm {
00199   namespace reftobase {
00200 
00201     template <class T, class REF>
00202     inline
00203     size_t
00204     Holder<T,REF>::key() const
00205     {
00206       typedef typename RefKeyTrait<REF>::type helper;
00207       return helper::key( ref_ );
00208     }
00209     
00210   }
00211 }
00212 #endif

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