CMS 3D CMS Logo

CallbackProxy.h
Go to the documentation of this file.
1 #ifndef Framework_CallbackProxy_h
2 #define Framework_CallbackProxy_h
3 // -*- C++ -*-
4 //
5 // Package: Framework
6 // Class : CallbackProxy
7 //
17 //
18 // Author: Chris Jones
19 // Created: Fri Apr 8 11:50:21 CDT 2005
20 //
21 
22 // system include files
23 #include <cassert>
24 #include <memory>
25 
26 // user include files
29 
32 
33 // forward declarations
34 namespace edm::eventsetup {
35 
36  template<class CallbackT, class RecordT, class DataT>
37  class CallbackProxy : public DataProxy {
38  public:
41  using record_type = RecordT;
42 
43  CallbackProxy(std::shared_ptr<CallbackT>& iCallback) :
44  callback_{iCallback} {
45  //The callback fills the data directly. This is done so that the callback does not have to
46  // hold onto a temporary copy of the result of the callback since the callback is allowed
47  // to return multiple items where only one item is needed by this Proxy
48  iCallback->holdOntoPointer(&data_);
49  }
50 
51  ~CallbackProxy() override {
52  DataT* dummy(nullptr);
53  callback_->holdOntoPointer(dummy);
54  }
55 
56  const void* getImpl(const EventSetupRecordImpl& iRecord, const DataKey&) override {
57  assert(iRecord.key() == RecordT::keyForClass());
58  record_type rec;
59  rec.setImpl(&iRecord);
60  (*callback_)(rec);
62  }
63 
64  void invalidateCache() override {
65  data_ = DataT{};
66  callback_->newRecordComing();
67  }
68 
69  // Delete copy operations
70  CallbackProxy(const CallbackProxy&) = delete;
71  const CallbackProxy& operator=(const CallbackProxy&) = delete;
72 
73  private:
74  DataT data_{};
76  };
77 
78 }
79 
80 #endif
const void * getImpl(const EventSetupRecordImpl &iRecord, const DataKey &) override
Definition: CallbackProxy.h:56
edm::propagate_const< std::shared_ptr< CallbackT > > callback_
Definition: CallbackProxy.h:75
static auto getPointer(T &iPtr) -> decltype(&*iPtr)
typename smart_pointer_traits::type value_type
Definition: CallbackProxy.h:40
const CallbackProxy & operator=(const CallbackProxy &)=delete
CallbackProxy(std::shared_ptr< CallbackT > &iCallback)
Definition: CallbackProxy.h:43
EventSetupRecordKey const & key() const