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 // $Id: Callback.h,v 1.9 2006/10/21 02:48:59 wmtan Exp $
20 //
21 
22 // system include files
23 #include <vector>
24 // user include files
26 
27 // forward declarations
28 namespace edm {
29  namespace eventsetup {
30 
31  //need a virtual distructor since owner of callback only knows
32  // about the base class. Other users of callback know the specific
33  // type
34  struct CallbackBase { virtual ~CallbackBase() {} };
35 
36  // The default decorator that does nothing
37  template< typename TRecord>
39  void pre(const TRecord&) {}
40  void post(const TRecord&) {}
41  };
42 
43  template<typename T, //producer's type
44  typename TReturn, //return type of the producer's method
45  typename TRecord, //the record passed in as an argument
46  typename TDecorator //allows customization using pre/post calls
47  =CallbackSimpleDecorator<TRecord> >
48  class Callback : public CallbackBase {
49  public:
50  typedef TReturn (T ::* method_type)(const TRecord&);
51 
52  Callback(T* iProd,
53  method_type iMethod,
54  const TDecorator& iDec = TDecorator()) :
55  proxyData_(produce::size< TReturn >::value, static_cast<void*>(0)),
56  producer_(iProd),
57  method_(iMethod),
59  decorator_(iDec) {}
60 
61 
62  // ---------- const member functions ---------------------
63 
64  // ---------- static member functions --------------------
65 
66  // ---------- member functions ---------------------------
67 
68 
69  void operator()(const TRecord& iRecord) {
71  decorator_.pre(iRecord);
72  storeReturnedValues((producer_->*method_)(iRecord));
74  decorator_.post(iRecord);
75  }
76  }
77 
78  template<class DataT>
79  void holdOntoPointer(DataT* iData) {
81  }
82 
83  void storeReturnedValues(TReturn iReturn) {
84  //std::cout <<" storeReturnedValues "<< iReturn <<" " <<iReturn->value_ <<std::endl;
86  setData(iReturn, static_cast<typename type::head_type*>(0), static_cast<const typename type::tail_type *>(0));
87  }
88 
89  template<class RemainingContainerT, class DataT, class ProductsT>
90  void setData(ProductsT& iProducts, const RemainingContainerT*, const DataT*) {
91  DataT* temp = reinterpret_cast< DataT*>(proxyData_[produce::find_index<TReturn,DataT>::value]) ;
92  if(0 != temp) { copyFromTo(iProducts, *temp); }
93  setData(iProducts, static_cast< const typename RemainingContainerT::head_type *>(0),
94  static_cast< const typename RemainingContainerT::tail_type *>(0));
95  }
96  template<class DataT, class ProductsT>
97  void setData(ProductsT& iProducts, const produce::Null*, const DataT*) {
98 
99  DataT* temp = reinterpret_cast< DataT*>(proxyData_[produce::find_index<TReturn,DataT>::value]) ;
100  //std::cout <<" setData["<< produce::find_index<TReturn,DataT>::value<<"] "<< temp <<std::endl;
101  if(0 != temp) { copyFromTo(iProducts, *temp); }
102  }
104  wasCalledForThisRecord_ = false;
105  }
106 
107  private:
108  Callback(const Callback&); // stop default
109 
110  const Callback& operator=(const Callback&); // stop default
111 
112  std::vector<void*> proxyData_;
116  TDecorator decorator_;
117  };
118  }
119 }
120 
121 #endif
void storeReturnedValues(TReturn iReturn)
Definition: Callback.h:83
type
Definition: HCALResponse.h:22
void setData(ProductsT &iProducts, const RemainingContainerT *, const DataT *)
Definition: Callback.h:90
void holdOntoPointer(DataT *iData)
Definition: Callback.h:79
std::vector< void * > proxyData_
Definition: Callback.h:112
void setData(ProductsT &iProducts, const produce::Null *, const DataT *)
Definition: Callback.h:97
TReturn(T::* method_type)(const TRecord &)
Definition: Callback.h:50
Callback(T *iProd, method_type iMethod, const TDecorator &iDec=TDecorator())
Definition: Callback.h:52
void operator()(const TRecord &iRecord)
Definition: Callback.h:69
void copyFromTo(FromT &iFrom, ToT &iTo)
const Callback & operator=(const Callback &)
long double T
tuple size
Write out results.