CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
Callback.h
Go to the documentation of this file.
1 #ifndef Framework_Callback_h
2 #define Framework_Callback_h
3 // -*- C++ -*-
4 //
5 // Package: Framework
6 // Class : Callback
7 //
16 //
17 // Author: Chris Jones
18 // Created: Sun Apr 17 14:30:24 EDT 2005
19 //
20 
21 // system include files
22 #include <vector>
23 // user include files
25 
26 // forward declarations
27 namespace edm {
28  namespace eventsetup {
29 
30  //need a virtual distructor since owner of callback only knows
31  // about the base class. Other users of callback know the specific
32  // type
33  struct CallbackBase { virtual ~CallbackBase() {} };
34 
35  // The default decorator that does nothing
36  template< typename TRecord>
38  void pre(const TRecord&) {}
39  void post(const TRecord&) {}
40  };
41 
42  template<typename T, //producer's type
43  typename TReturn, //return type of the producer's method
44  typename TRecord, //the record passed in as an argument
45  typename TDecorator //allows customization using pre/post calls
46  =CallbackSimpleDecorator<TRecord> >
47  class Callback : public CallbackBase {
48  public:
49  typedef TReturn (T ::* method_type)(const TRecord&);
50 
51  Callback(T* iProd,
52  method_type iMethod,
53  const TDecorator& iDec = TDecorator()) :
54  proxyData_(produce::size< TReturn >::value, static_cast<void*>(nullptr)),
55  producer_(iProd),
56  method_(iMethod),
58  decorator_(iDec) {}
59 
60 
61  // ---------- const member functions ---------------------
62 
63  // ---------- static member functions --------------------
64 
65  // ---------- member functions ---------------------------
66 
67 
68  void operator()(const TRecord& iRecord) {
70  decorator_.pre(iRecord);
71  storeReturnedValues((producer_->*method_)(iRecord));
73  decorator_.post(iRecord);
74  }
75  }
76 
77  template<class DataT>
78  void holdOntoPointer(DataT* iData) {
80  }
81 
82  void storeReturnedValues(TReturn iReturn) {
83  //std::cout <<" storeReturnedValues "<< iReturn <<" " <<iReturn->value_ <<std::endl;
85  setData(iReturn, static_cast<typename type::head_type*>(nullptr), static_cast<const typename type::tail_type *>(nullptr));
86  }
87 
88  template<class RemainingContainerT, class DataT, class ProductsT>
89  void setData(ProductsT& iProducts, const RemainingContainerT*, const DataT*) {
90  DataT* temp = reinterpret_cast< DataT*>(proxyData_[produce::find_index<TReturn,DataT>::value]) ;
91  if(0 != temp) { copyFromTo(iProducts, *temp); }
92  setData(iProducts, static_cast< const typename RemainingContainerT::head_type *>(nullptr),
93  static_cast< const typename RemainingContainerT::tail_type *>(nullptr));
94  }
95  template<class DataT, class ProductsT>
96  void setData(ProductsT& iProducts, const produce::Null*, const DataT*) {
97 
98  DataT* temp = reinterpret_cast< DataT*>(proxyData_[produce::find_index<TReturn,DataT>::value]) ;
99  //std::cout <<" setData["<< produce::find_index<TReturn,DataT>::value<<"] "<< temp <<std::endl;
100  if(0 != temp) { copyFromTo(iProducts, *temp); }
101  }
103  wasCalledForThisRecord_ = false;
104  }
105 
106  private:
107  Callback(const Callback&); // stop default
108 
109  const Callback& operator=(const Callback&); // stop default
110 
111  std::vector<void*> proxyData_;
115  TDecorator decorator_;
116  };
117  }
118 }
119 
120 #endif
void storeReturnedValues(TReturn iReturn)
Definition: Callback.h:82
type
Definition: HCALResponse.h:21
void setData(ProductsT &iProducts, const RemainingContainerT *, const DataT *)
Definition: Callback.h:89
void holdOntoPointer(DataT *iData)
Definition: Callback.h:78
std::vector< void * > proxyData_
Definition: Callback.h:111
#define nullptr
void setData(ProductsT &iProducts, const produce::Null *, const DataT *)
Definition: Callback.h:96
TReturn(T::* method_type)(const TRecord &)
Definition: Callback.h:49
Callback(T *iProd, method_type iMethod, const TDecorator &iDec=TDecorator())
Definition: Callback.h:51
void operator()(const TRecord &iRecord)
Definition: Callback.h:68
void copyFromTo(FromT &iFrom, ToT &iTo)
const Callback & operator=(const Callback &)
long double T
tuple size
Write out results.