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 {
35  namespace eventsetup {
36 
37  template<class CallbackT, class RecordT, class DataT>
38  class CallbackProxy : public DataProxy {
39 
40  public:
42  typedef RecordT record_type;
43 
44  CallbackProxy(std::shared_ptr<CallbackT>& iCallback) :
45  data_(),
46  callback_(iCallback) {
47  //The callback fills the data directly. This is done so that the callback does not have to
48  // hold onto a temporary copy of the result of the callback since the callback is allowed
49  // to return multiple items where only one item is needed by this Proxy
50  iCallback->holdOntoPointer(&data_) ; }
51  ~CallbackProxy() override {
52  DataT* dummy(nullptr);
53  callback_->holdOntoPointer(dummy) ;
54  }
55  // ---------- const member functions ---------------------
56 
57  // ---------- static member functions --------------------
58 
59  // ---------- member functions ---------------------------
60  const void* getImpl(const EventSetupRecordImpl& iRecord, const DataKey&) override {
61  assert(iRecord.key() == RecordT::keyForClass());
62  record_type rec;
63  rec.setImpl(&iRecord);
64  (*callback_)(rec);
65  return &(*data_);
66  }
67 
68  void invalidateCache() override {
69  data_ = DataT();
70  callback_->newRecordComing();
71  }
72  private:
73  CallbackProxy(const CallbackProxy&) = delete; // stop default
74 
75  const CallbackProxy& operator=(const CallbackProxy&) = delete; // stop default
76 
77  // ---------- member data --------------------------------
78  DataT data_;
80  };
81 
82  }
83 }
84 
85 #endif
const void * getImpl(const EventSetupRecordImpl &iRecord, const DataKey &) override
Definition: CallbackProxy.h:60
edm::propagate_const< std::shared_ptr< CallbackT > > callback_
Definition: CallbackProxy.h:79
produce::smart_pointer_traits< DataT >::type value_type
Definition: CallbackProxy.h:41
HLT enums.
const CallbackProxy & operator=(const CallbackProxy &)=delete
CallbackProxy(std::shared_ptr< CallbackT > &iCallback)
Definition: CallbackProxy.h:44
EventSetupRecordKey const & key() const