Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:03:54

0001 #ifndef DataFormats_Common_TestHandle_h
0002 #define DataFormats_Common_TestHandle_h
0003 
0004 /*----------------------------------------------------------------------
0005   
0006 TestHandle: Non-owning "smart pointer" for reference to EDProducts.
0007 
0008 
0009 This is a very preliminary version, and lacks safety features and
0010 elegance.
0011 
0012 If the pointed-to EDProduct is destroyed, use of the TestHandle
0013 becomes undefined. There is no way to query the TestHandle to
0014 discover if this has happened.
0015 
0016 TestHandles can have:
0017   -- Product pointer null and id == 0;
0018   -- Product pointer valid and id != 0;
0019 
0020 To check validity, one can use the isValid() function.
0021 
0022 ----------------------------------------------------------------------*/
0023 
0024 #include "DataFormats/Common/interface/OrphanHandleBase.h"
0025 
0026 namespace edm {
0027 
0028   template <typename T>
0029   class TestHandle : public OrphanHandleBase {
0030   public:
0031     typedef T element_type;
0032 
0033     // Default constructed handles are invalid.
0034     TestHandle();
0035 
0036     TestHandle(T const* prod, ProductID const& id);
0037 
0038     ~TestHandle();
0039 
0040     T const* product() const;
0041     T const* operator->() const;  // alias for product()
0042     T const& operator*() const;
0043 
0044   private:
0045   };
0046 
0047   template <class T>
0048   TestHandle<T>::TestHandle() : OrphanHandleBase() {}
0049 
0050   template <class T>
0051   TestHandle<T>::TestHandle(T const* prod, ProductID const& theId) : OrphanHandleBase(prod, theId) {}
0052 
0053   template <class T>
0054   TestHandle<T>::~TestHandle() {}
0055 
0056   template <class T>
0057   T const* TestHandle<T>::product() const {
0058     return static_cast<T const*>(productStorage());
0059   }
0060 
0061   template <class T>
0062   T const* TestHandle<T>::operator->() const {
0063     return product();
0064   }
0065 
0066   template <class T>
0067   T const& TestHandle<T>::operator*() const {
0068     return *product();
0069   }
0070 
0071 }  // namespace edm
0072 #endif