File indexing completed on 2024-04-06 12:13:10
0001 #ifndef Subsystem_Package_TestHandle_h
0002 #define Subsystem_Package_TestHandle_h
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022 #include <memory>
0023
0024
0025 #include "DataFormats/Common/interface/BasicHandle.h"
0026 #include "FWCore/Utilities/interface/Exception.h"
0027
0028
0029
0030 namespace edm {
0031 namespace test {
0032 template <typename T>
0033 class TestHandle {
0034 public:
0035 explicit TestHandle(T const* product) : product_{product} {}
0036
0037 explicit TestHandle(std::shared_ptr<HandleExceptionFactory const> iFailed)
0038 : product_{nullptr}, whyFailedFactory_{std::move(iFailed)} {}
0039
0040 operator bool() { return product_ != nullptr; }
0041
0042 bool isValid() const { return product_ != nullptr; }
0043
0044 T const* product() const { return productStorage(); }
0045
0046 T const* operator->() const { return product(); }
0047
0048 T const& operator*() const { return *product(); }
0049
0050 private:
0051 T const* productStorage() const {
0052 if (product_) {
0053 return product_;
0054 }
0055 throw *(whyFailedFactory_->make());
0056 }
0057
0058 T const* product_;
0059 std::shared_ptr<HandleExceptionFactory const> whyFailedFactory_;
0060 };
0061
0062 }
0063 }
0064
0065 #endif