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> &&);
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 
60  template <class T>
61  Handle<T>::Handle(T const* prod, Provenance const* prov) : HandleBase(prod, prov) {
62  }
63 
64  template <class T>
65  Handle<T>::Handle(std::shared_ptr<edm::HandleExceptionFactory> && iWhyFailed) :
66  HandleBase(std::move(iWhyFailed))
67  { }
68 
69  template <class T>
71 
72  template <class T>
73  T const*
74  Handle<T>::product() const {
75  return static_cast<T const*>(productStorage());
76  }
77 
78  template <class T>
79  T const*
81  return product();
82  }
83 
84  template <class T>
85  T const&
87  return *product();
88  }
89 }
90 #endif
Handle()
Definition: Handle.h:57
void const * productStorage() const
Definition: HandleBase.cc:7
~Handle()
Definition: Handle.h:70
Handle & operator=(Handle &&)=default
T const & operator*() const
Definition: Handle.h:86
T const * product() const
Definition: Handle.h:74
T const * operator->() const
Definition: Handle.h:80
HLT enums.
long double T
def move(src, dest)
Definition: eostools.py:511