CMS 3D CMS Logo

Handle.h
Go to the documentation of this file.
1 #ifndef DataFormats_Common_Handle_h
2 #define DataFormats_Common_Handle_h
3 
4 /*----------------------------------------------------------------------
5 
6 Handle: Non-owning "smart pointer" for reference to Products and
7 their Provenances.
8 
9 This is a very preliminary version, and lacks safety features and
10 elegance.
11 
12 If the pointed-to Product or Provenance is destroyed, use of the
13 Handle becomes undefined. There is no way to query the Handle to
14 discover if this has happened.
15 
16 Handles can have:
17  -- Product and Provenance pointers both null;
18  -- Both pointers valid
19 
20 To check validity, one can use the isValid() function.
21 
22 If failedToGet() returns true then the requested data is not available
23 If failedToGet() returns false but isValid() is also false then no attempt
24  to get data has occurred
25 
26 ----------------------------------------------------------------------*/
27 
29 
30 namespace edm {
31 
32  template <typename T>
33  class Handle : public HandleBase {
34  public:
35  using element_type = T;
36 
37  // Default constructed handles are invalid.
38  Handle();
39 
40  Handle(T const* prod, Provenance const* prov);
41 
42  Handle(std::shared_ptr<HandleExceptionFactory const>&&);
43  Handle(Handle const&) = default;
44  Handle& operator=(Handle&&) = default;
45  Handle& operator=(Handle const&) = default;
46 
47  ~Handle();
48 
49  T const* product() const;
50  T const* operator->() const; // alias for product()
51  T const& operator*() const;
52 
53  private:
54  };
55 
56  template <class T>
58 
59  template <class T>
60  Handle<T>::Handle(T const* prod, Provenance const* prov) : HandleBase(prod, prov) {}
61 
62  template <class T>
63  Handle<T>::Handle(std::shared_ptr<edm::HandleExceptionFactory const>&& iWhyFailed)
64  : HandleBase(std::move(iWhyFailed)) {}
65 
66  template <class T>
68 
69  template <class T>
70  T const* Handle<T>::product() const {
71  return static_cast<T const*>(productStorage());
72  }
73 
74  template <class T>
75  T const* Handle<T>::operator->() const {
76  return product();
77  }
78 
79  template <class T>
80  T const& Handle<T>::operator*() const {
81  return *product();
82  }
83 } // namespace edm
84 #endif
Handle()
Definition: Handle.h:57
T const * product() const
Definition: Handle.h:70
T const * operator->() const
Definition: Handle.h:75
~Handle()
Definition: Handle.h:67
Handle & operator=(Handle &&)=default
T const & operator*() const
Definition: Handle.h:80
HLT enums.
MatrixMeschach operator*(const MatrixMeschach &mat1, const MatrixMeschach &mat2)
long double T
def move(src, dest)
Definition: eostools.py:511