CMS 3D CMS Logo

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