CMS 3D CMS Logo

ValidHandle.h
Go to the documentation of this file.
1 #ifndef DataFormats_Common_ValidHandle_h
2 #define DataFormats_Common_ValidHandle_h
3 
4 /*----------------------------------------------------------------------
5 
6 Handle: Non-owning "smart pointer" for reference to products and
7 their provenances.
8 
9 The data product is always guaranteed to be valid for this handle type.
10 ----------------------------------------------------------------------*/
11 
12 #include <utility>
14 
15 namespace edm {
16  namespace vhhelper {
17  void throwIfNotValid(const void*) noexcept(false);
18  }
19  template <typename T>
20  class ValidHandle {
21  public:
22  using element_type = T;
23 
24  ValidHandle() = delete;
25  ValidHandle(T const* prod, ProductID id) noexcept(false) : product_(prod), id_(std::move(id)) {
27  }
28 
29  //NOTE: C++ disallows references to null
30  ValidHandle(T const& prod, ProductID id) noexcept(true) : product_(&prod), id_(std::move(id)) {}
31  ValidHandle(const ValidHandle<T>&) = default;
32  ValidHandle<T>& operator=(ValidHandle<T> const& rhs) = default;
33  ~ValidHandle() = default;
34 
35  ProductID const& id() const noexcept(true) { return id_; }
36 
37  T const* product() const noexcept(true) { return product_; }
38 
39  T const* operator->() const noexcept(true) { return product(); }
40  T const& operator*() const noexcept(true) { return *product(); }
41 
42  private:
43  T const* product_;
45  };
46 
51  template <typename U>
52  auto makeValid(const U& iOtherHandleType) noexcept(false) {
53  vhhelper::throwIfNotValid(iOtherHandleType.product());
54  //because of the check, we know this is valid and do not have to check again
55  return ValidHandle<typename U::element_type>(*iOtherHandleType.product(), iOtherHandleType.id());
56  }
57 } // namespace edm
58 
59 #endif
edm
HLT enums.
Definition: AlignableModifier.h:19
watchdog.const
const
Definition: watchdog.py:83
edm::ValidHandle::ValidHandle
ValidHandle()=delete
edm::ValidHandle::~ValidHandle
~ValidHandle()=default
edm::ValidHandle::operator=
ValidHandle< T > & operator=(ValidHandle< T > const &rhs)=default
dumpMFGeometry_cfg.prod
prod
Definition: dumpMFGeometry_cfg.py:24
ProductID.h
edm::ValidHandle::id
ProductID const & id() const noexcept(true)
Definition: ValidHandle.h:35
mitigatedMETSequence_cff.U
U
Definition: mitigatedMETSequence_cff.py:36
funct::true
true
Definition: Factorize.h:173
edm::ValidHandle::id_
ProductID id_
Definition: ValidHandle.h:44
edm::ValidHandle::operator*
T const & operator*() const noexcept(true)
Definition: ValidHandle.h:40
edm::ValidHandle::operator->
T const * operator->() const noexcept(true)
Definition: ValidHandle.h:39
edm::vhhelper::throwIfNotValid
void throwIfNotValid(const void *) noexcept(false)
Definition: ValidHandle.cc:5
edm::ValidHandle::ValidHandle
ValidHandle(T const &prod, ProductID id) noexcept(true)
Definition: ValidHandle.h:30
edm::makeValid
auto makeValid(const U &iOtherHandleType) noexcept(false)
Definition: ValidHandle.h:52
eostools.move
def move(src, dest)
Definition: eostools.py:511
std
Definition: JetResolutionObject.h:76
edm::ValidHandle::ValidHandle
ValidHandle(T const *prod, ProductID id) noexcept(false)
Definition: ValidHandle.h:25
T
long double T
Definition: Basic3DVectorLD.h:48
edm::ValidHandle::product_
T const * product_
Definition: ValidHandle.h:43
edm::ValidHandle::product
T const * product() const noexcept(true)
Definition: ValidHandle.h:37
edm::ValidHandle::element_type
T element_type
Definition: ValidHandle.h:22
edm::ProductID
Definition: ProductID.h:27
edm::ValidHandle
Definition: ValidHandle.h:20