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  virtual ~CallbackProxy() {
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 EventSetupRecord& iRecord, const DataKey&) {
61  assert(iRecord.key() == RecordT::keyForClass());
62  (*callback_)(static_cast<const record_type&>(iRecord));
63  return &(*data_);
64  }
65 
66  void invalidateCache() {
67  data_ = DataT();
68  callback_->newRecordComing();
69  }
70  private:
71  CallbackProxy(const CallbackProxy&); // stop default
72 
73  const CallbackProxy& operator=(const CallbackProxy&); // stop default
74 
75  // ---------- member data --------------------------------
76  DataT data_;
78  };
79 
80  }
81 }
82 
83 #endif
const CallbackProxy & operator=(const CallbackProxy &)
virtual EventSetupRecordKey key() const =0
const void * getImpl(const EventSetupRecord &iRecord, const DataKey &)
Definition: CallbackProxy.h:60
edm::propagate_const< std::shared_ptr< CallbackT > > callback_
Definition: CallbackProxy.h:77
produce::smart_pointer_traits< DataT >::type value_type
Definition: CallbackProxy.h:41
HLT enums.
CallbackProxy(std::shared_ptr< CallbackT > &iCallback)
Definition: CallbackProxy.h:44