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 #include <typeinfo>
28 
31 
32 namespace edm {
33 
34  template <typename T>
35  class Handle : public HandleBase {
36  public:
37  typedef T element_type;
38 
39  // Default constructed handles are invalid.
40  Handle();
41 
42  Handle(T const* prod, Provenance const* prov);
43 
44 #if defined( __GXX_EXPERIMENTAL_CXX0X__)
45  Handle(std::shared_ptr<HandleExceptionFactory> &&);
46  Handle(Handle const&) = default;
47 
48  Handle& operator=(Handle&&) = default;
49  Handle& operator=(Handle const&) = default;
50 #endif
51 
52  ~Handle();
53 
54  T const* product() const;
55  T const* operator->() const; // alias for product()
56  T const& operator*() const;
57 
58  private:
59  };
60 
61  template <class T>
63  { }
64 
65  template <class T>
66  Handle<T>::Handle(T const* prod, Provenance const* prov) : HandleBase(prod, prov) {
67  }
68 
69 #if defined( __GXX_EXPERIMENTAL_CXX0X__)
70  template <class T>
71  Handle<T>::Handle(std::shared_ptr<edm::HandleExceptionFactory> && iWhyFailed) :
72  HandleBase(std::move(iWhyFailed))
73  { }
74 #endif
75 
76  template <class T>
78 
79  template <class T>
80  T const*
81  Handle<T>::product() const {
82  return static_cast<T const*>(productStorage());
83  }
84 
85  template <class T>
86  T const*
88  return product();
89  }
90 
91  template <class T>
92  T const&
94  return *product();
95  }
96 }
97 #endif
Handle()
Definition: Handle.h:62
void const * productStorage() const
Definition: HandleBase.cc:7
T element_type
Definition: Handle.h:37
~Handle()
Definition: Handle.h:77
T const & operator*() const
Definition: Handle.h:93
T const * product() const
Definition: Handle.h:81
T const * operator->() const
Definition: Handle.h:87
HLT enums.
long double T
def move(src, dest)
Definition: eostools.py:510
HandleBase & operator=(HandleBase const &rhs)
Definition: HandleBase.h:68