Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 12:52:59

0001 #ifndef DataFormats_Common_Handle_h
0002 #define DataFormats_Common_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     Handle(Handle const&) = default;
0044     Handle& operator=(Handle&&) = default;
0045     Handle& operator=(Handle const&) = default;
0046 
0047     ~Handle();
0048 
0049     T const* product() const;
0050     T const* operator->() const;  // alias for product()
0051     T const& operator*() const;
0052 
0053   private:
0054   };
0055 
0056   template <class T>
0057   Handle<T>::Handle() : HandleBase() {}
0058 
0059   template <class T>
0060   Handle<T>::Handle(T const* prod, Provenance const* prov) : HandleBase(prod, prov) {}
0061 
0062   template <class T>
0063   Handle<T>::Handle(std::shared_ptr<edm::HandleExceptionFactory const>&& iWhyFailed)
0064       : HandleBase(std::move(iWhyFailed)) {}
0065 
0066   template <class T>
0067   Handle<T>::~Handle() {}
0068 
0069   template <class T>
0070   T const* Handle<T>::product() const {
0071     return static_cast<T const*>(productStorage());
0072   }
0073 
0074   template <class T>
0075   T const* Handle<T>::operator->() const {
0076     return product();
0077   }
0078 
0079   template <class T>
0080   T const& Handle<T>::operator*() const {
0081     return *product();
0082   }
0083 }  // namespace edm
0084 #endif