Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2023-03-17 10:49:24

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