Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2025-03-05 03:13:49

0001 #ifndef DataFormats_Common_interface_OrphanHandle_h
0002 #define DataFormats_Common_interface_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 
0026   template <typename T>
0027   class OrphanHandle : public OrphanHandleBase {
0028   public:
0029     using element_type = T;
0030 
0031     // Default constructed handles are invalid.
0032     OrphanHandle();
0033 
0034     OrphanHandle(T const* prod, ProductID const& id);
0035 
0036     T const* product() const;
0037     T const* operator->() const;  // alias for product()
0038     T const& operator*() const;
0039   };
0040 
0041   template <class T>
0042   OrphanHandle<T>::OrphanHandle() : OrphanHandleBase() {}
0043 
0044   template <class T>
0045   OrphanHandle<T>::OrphanHandle(T const* prod, ProductID const& theId) : OrphanHandleBase(prod, theId) {}
0046 
0047   template <class T>
0048   T const* OrphanHandle<T>::product() const {
0049     return static_cast<T const*>(productStorage());
0050   }
0051 
0052   template <class T>
0053   T const* OrphanHandle<T>::operator->() const {
0054     return product();
0055   }
0056 
0057   template <class T>
0058   T const& OrphanHandle<T>::operator*() const {
0059     return *product();
0060   }
0061 
0062 }  // namespace edm
0063 
0064 #endif  // DataFormats_Common_interface_OrphanHandle_h