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) : callback_{iCallback} {
44  //The callback fills the data directly. This is done so that the callback does not have to
45  // hold onto a temporary copy of the result of the callback since the callback is allowed
46  // to return multiple items where only one item is needed by this Proxy
47  iCallback->holdOntoPointer(&data_);
48  }
49 
50  ~CallbackProxy() override {
51  DataT* dummy(nullptr);
52  callback_->holdOntoPointer(dummy);
53  }
54 
55  const void* getImpl(const EventSetupRecordImpl& iRecord, const DataKey&) override {
56  assert(iRecord.key() == RecordT::keyForClass());
57  record_type rec;
58  rec.setImpl(&iRecord, callback_->transitionID(), callback_->getTokenIndices());
59  (*callback_)(rec);
61  }
62 
63  void invalidateCache() override {
64  data_ = DataT{};
65  callback_->newRecordComing();
66  }
67 
68  // Delete copy operations
69  CallbackProxy(const CallbackProxy&) = delete;
70  const CallbackProxy& operator=(const CallbackProxy&) = delete;
71 
72  private:
73  DataT data_{};
75  };
76 
77 } // namespace edm::eventsetup
78 
79 #endif
const void * getImpl(const EventSetupRecordImpl &iRecord, const DataKey &) override
Definition: CallbackProxy.h:55
edm::propagate_const< std::shared_ptr< CallbackT > > callback_
Definition: CallbackProxy.h:74
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