CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
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 "boost/shared_ptr.hpp"
24 #include <cassert>
25 
26 // user include files
29 
31 
32 // forward declarations
33 namespace edm {
34  namespace eventsetup {
35 
36  template<class CallbackT, class RecordT, class DataT>
37  class CallbackProxy : public DataProxy {
38 
39  public:
41  typedef RecordT record_type;
42 
43  CallbackProxy(boost::shared_ptr<CallbackT>& iCallback) :
44  data_(),
45  callback_(iCallback) {
46  //The callback fills the data directly. This is done so that the callback does not have to
47  // hold onto a temporary copy of the result of the callback since the callback is allowed
48  // to return multiple items where only one item is needed by this Proxy
49  iCallback->holdOntoPointer(&data_) ; }
50  virtual ~CallbackProxy() {
51  DataT* dummy(nullptr);
52  callback_->holdOntoPointer(dummy) ;
53  }
54  // ---------- const member functions ---------------------
55 
56  // ---------- static member functions --------------------
57 
58  // ---------- member functions ---------------------------
59  const void* getImpl(const EventSetupRecord& iRecord, const DataKey&) {
60  assert(iRecord.key() == RecordT::keyForClass());
61  (*callback_)(static_cast<const record_type&>(iRecord));
62  return &(*data_);
63  }
64 
65  void invalidateCache() {
66  data_ = DataT();
67  callback_->newRecordComing();
68  }
69  private:
70  CallbackProxy(const CallbackProxy&); // stop default
71 
72  const CallbackProxy& operator=(const CallbackProxy&); // stop default
73 
74  // ---------- member data --------------------------------
75  DataT data_;
76  boost::shared_ptr<CallbackT> callback_;
77  };
78 
79  }
80 }
81 
82 #endif
const CallbackProxy & operator=(const CallbackProxy &)
virtual EventSetupRecordKey key() const =0
assert(m_qm.get())
const void * getImpl(const EventSetupRecord &iRecord, const DataKey &)
Definition: CallbackProxy.h:59
CallbackProxy(boost::shared_ptr< CallbackT > &iCallback)
Definition: CallbackProxy.h:43
produce::smart_pointer_traits< DataT >::type value_type
Definition: CallbackProxy.h:40
boost::shared_ptr< CallbackT > callback_
Definition: CallbackProxy.h:76