CMS 3D CMS Logo

/afs/cern.ch/work/a/aaltunda/public/www/CMSSW_6_2_5/src/DataFormats/Common/interface/OrphanHandle.h

Go to the documentation of this file.
00001 #ifndef DataFormats_Common_OrphanHandle_h
00002 #define DataFormats_Common_OrphanHandle_h
00003 
00004 /*----------------------------------------------------------------------
00005   
00006 OrphanHandle: Non-owning "smart pointer" for reference to EDProducts.
00007 
00008 This is a very preliminary version, and lacks safety features and elegance.
00009 
00010 If the pointed-to EDProduct is destroyed, use of the OrphanHandle
00011 becomes undefined. There is no way to query the OrphanHandle to
00012 discover if this has happened.
00013 
00014 OrphanHandles can have:
00015   -- Product pointer null and id == 0;
00016   -- Product pointer valid and id != 0;
00017 
00018 To check validity, one can use the isValid() function.
00019 
00020 ----------------------------------------------------------------------*/
00021 
00022 #include "DataFormats/Common/interface/OrphanHandleBase.h"
00023 
00024 namespace edm {
00025   template <typename T>
00026   class OrphanHandle : public OrphanHandleBase {
00027   public:
00028     typedef T element_type;
00029 
00030     // Default constructed handles are invalid.
00031     OrphanHandle();
00032 
00033     OrphanHandle(T const* prod, ProductID const& id);
00034 
00035     ~OrphanHandle();
00036 
00037     T const* product() const;
00038     T const* operator->() const; // alias for product()
00039     T const& operator*() const;
00040 
00041   private:
00042   };
00043 
00044   template <class T>
00045   OrphanHandle<T>::OrphanHandle() : OrphanHandleBase()
00046   { }
00047 
00048   template <class T>
00049   OrphanHandle<T>::OrphanHandle(T const* prod, ProductID const& theId) : OrphanHandleBase(prod, theId) {
00050   }
00051 
00052   template <class T>
00053   OrphanHandle<T>::~OrphanHandle() {}
00054 
00055   template <class T>
00056   T const* 
00057   OrphanHandle<T>::product() const {
00058     return static_cast<T const*>(productStorage());
00059   }
00060 
00061   template <class T>
00062   T const* 
00063   OrphanHandle<T>::operator->() const {
00064     return product();
00065   }
00066 
00067   template <class T>
00068   T const& 
00069   OrphanHandle<T>::operator*() const {
00070     return *product();
00071   }
00072 
00073 }
00074 #endif