Back to home page

Project CMSSW displayed by LXR

 
 

    


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

0001 #ifndef DataFormats_Common_interface_Handle_h
0002 #define DataFormats_Common_interface_Handle_h
0003 
0004 /*----------------------------------------------------------------------
0005   
0006 Handle: Non-owning "smart pointer" for reference to Products and
0007 their Provenances.
0008 
0009 This is a very preliminary version, and lacks safety features and
0010 elegance.
0011 
0012 If the pointed-to Product or Provenance is destroyed, use of the
0013 Handle becomes undefined. There is no way to query the Handle to
0014 discover if this has happened.
0015 
0016 Handles can have:
0017   -- Product and Provenance pointers both null;
0018   -- Both pointers valid
0019 
0020 To check validity, one can use the isValid() function.
0021 
0022 If failedToGet() returns true then the requested data is not available
0023 If failedToGet() returns false but isValid() is also false then no attempt 
0024   to get data has occurred
0025 
0026 ----------------------------------------------------------------------*/
0027 
0028 #include "DataFormats/Common/interface/HandleBase.h"
0029 
0030 namespace edm {
0031 
0032   template <typename T>
0033   class Handle : public HandleBase {
0034   public:
0035     using element_type = T;
0036 
0037     // Default constructed handles are invalid.
0038     Handle();
0039 
0040     Handle(T const* prod, Provenance const* prov);
0041 
0042     Handle(std::shared_ptr<HandleExceptionFactory const>&&);
0043 
0044     T const* product() const;
0045     T const* operator->() const;  // alias for product()
0046     T const& operator*() const;
0047   };
0048 
0049   template <class T>
0050   Handle<T>::Handle() : HandleBase() {}
0051 
0052   template <class T>
0053   Handle<T>::Handle(T const* prod, Provenance const* prov) : HandleBase(prod, prov) {}
0054 
0055   template <class T>
0056   Handle<T>::Handle(std::shared_ptr<edm::HandleExceptionFactory const>&& iWhyFailed)
0057       : HandleBase(std::move(iWhyFailed)) {}
0058 
0059   template <class T>
0060   T const* Handle<T>::product() const {
0061     return static_cast<T const*>(productStorage());
0062   }
0063 
0064   template <class T>
0065   T const* Handle<T>::operator->() const {
0066     return product();
0067   }
0068 
0069   template <class T>
0070   T const& Handle<T>::operator*() const {
0071     return *product();
0072   }
0073 
0074 }  // namespace edm
0075 
0076 #endif  // DataFormats_Common_interface_Handle_h