CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_3/src/DataFormats/Common/interface/TestHandle.h

Go to the documentation of this file.
00001 #ifndef DataFormats_Common_TestHandle_h
00002 #define DataFormats_Common_TestHandle_h
00003 
00004 /*----------------------------------------------------------------------
00005   
00006 TestHandle: 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 TestHandle
00013 becomes undefined. There is no way to query the TestHandle to
00014 discover if this has happened.
00015 
00016 TestHandles 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 
00028   template <typename T>
00029   class TestHandle : public OrphanHandleBase {
00030   public:
00031     typedef T element_type;
00032 
00033     // Default constructed handles are invalid.
00034     TestHandle();
00035 
00036     TestHandle(T const* prod, ProductID const& id);
00037 
00038     ~TestHandle();
00039 
00040     T const* product() const;
00041     T const* operator->() const; // alias for product()
00042     T const& operator*() const;
00043 
00044   private:
00045   };
00046 
00047   template <class T>
00048   TestHandle<T>::TestHandle() : OrphanHandleBase()
00049   { }
00050 
00051   template <class T>
00052   TestHandle<T>::TestHandle(T const* prod, ProductID const& theId) : OrphanHandleBase(prod, theId) {
00053   }
00054 
00055   template <class T>
00056   TestHandle<T>::~TestHandle() {}
00057 
00058   template <class T>
00059   T const* 
00060   TestHandle<T>::product() const {
00061     return static_cast<T const*>(productStorage());
00062   }
00063 
00064   template <class T>
00065   T const* 
00066   TestHandle<T>::operator->() const {
00067     return product();
00068   }
00069 
00070   template <class T>
00071   T const& 
00072   TestHandle<T>::operator*() const {
00073     return *product();
00074   }
00075 
00076 }
00077 #endif