CMS 3D CMS Logo

ESValidHandle.h
Go to the documentation of this file.
1 #ifndef FWCore_Framework_ESValidHandle_h
2 #define FWCore_Framework_ESValidHandle_h
3 // -*- C++ -*-
4 //
5 // Package: Framework
6 // Class : ESValidHandle
7 //
16 //
17 // Author: Chris Jones
18 // Created: Tue Feb 5 14:47:35 EST 2019
19 //
20 
21 // system include files
22 
23 // user include files
25 
26 #include <exception>
27 #include <memory>
28 #include <utility>
29 
30 namespace edm {
31 
32  namespace esvhhelper {
33  void throwIfNotValid(const void*) noexcept(false);
34  }
35 
36  template <typename T>
37  class ESValidHandle {
38  public:
39  typedef T value_type;
40 
41  ESValidHandle() = delete;
43  : data_{&iData}, description_{desc} {}
44 
45  ESValidHandle(ESValidHandle<T> const&) = default;
46  ESValidHandle(ESValidHandle<T>&&) = default;
47  ESValidHandle& operator=(ESValidHandle<T> const&) = default;
49 
50  // ---------- const member functions ---------------------
51  T const* product() const noexcept { return data_; }
52  T const* operator->() const noexcept { return product(); }
53  T const& operator*() const noexcept { return *product(); }
54  // ---------- static member functions --------------------
55  static constexpr bool transientAccessOnly = false;
56 
57  // ---------- member functions ---------------------------
58  private:
59  T const* data_{nullptr};
61  };
62 
67  template <typename U>
68  auto makeESValid(const U& iOtherHandleType) noexcept(false) {
69  esvhhelper::throwIfNotValid(iOtherHandleType.product());
70  //because of the check, we know this is valid and do not have to check again
71  return ESValidHandle<typename U::value_type>(*iOtherHandleType.product(), iOtherHandleType.description());
72  }
73 
74 } // namespace edm
75 #endif
ESValidHandle & operator=(ESValidHandle< T > const &)=default
static constexpr bool transientAccessOnly
Definition: ESValidHandle.h:55
ESValidHandle(T const &iData, edm::eventsetup::ComponentDescription const *desc) noexcept
Definition: ESValidHandle.h:42
T const * product() const noexcept
Definition: ESValidHandle.h:51
void throwIfNotValid(const void *) noexcept(false)
Definition: ESValidHandle.cc:5
ESValidHandle()=delete
auto makeESValid(const U &iOtherHandleType) noexcept(false)
Definition: ESValidHandle.h:68
T const & operator*() const noexcept
Definition: ESValidHandle.h:53
HLT enums.
long double T
T const * operator->() const noexcept
Definition: ESValidHandle.h:52
edm::eventsetup::ComponentDescription const * description_
Definition: ESValidHandle.h:60