File indexing completed on 2023-03-17 10:49:27
0001 #ifndef DataFormats_Common_ValidHandle_h
0002 #define DataFormats_Common_ValidHandle_h
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012 #include <utility>
0013 #include "DataFormats/Provenance/interface/ProductID.h"
0014
0015 namespace edm {
0016 namespace vhhelper {
0017 void throwIfNotValid(const void*) noexcept(false);
0018 }
0019 template <typename T>
0020 class ValidHandle {
0021 public:
0022 using element_type = T;
0023
0024 ValidHandle() = delete;
0025 ValidHandle(T const* prod, ProductID id) noexcept(false) : product_(prod), id_(id) {
0026 vhhelper::throwIfNotValid(prod);
0027 }
0028
0029
0030 ValidHandle(T const& prod, ProductID id) noexcept(true) : product_(&prod), id_(id) {}
0031 ValidHandle(const ValidHandle<T>&) = default;
0032 ValidHandle<T>& operator=(ValidHandle<T> const& rhs) = default;
0033 ~ValidHandle() = default;
0034
0035 ProductID const& id() const noexcept(true) { return id_; }
0036
0037 T const* product() const noexcept(true) { return product_; }
0038
0039 T const* operator->() const noexcept(true) { return product(); }
0040 T const& operator*() const noexcept(true) { return *product(); }
0041
0042 private:
0043 T const* product_;
0044 ProductID id_;
0045 };
0046
0047
0048
0049
0050
0051 template <typename U>
0052 auto makeValid(const U& iOtherHandleType) noexcept(false) {
0053 vhhelper::throwIfNotValid(iOtherHandleType.product());
0054
0055 return ValidHandle<typename U::element_type>(*iOtherHandleType.product(), iOtherHandleType.id());
0056 }
0057 }
0058
0059 #endif