Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
WrappedFunction.h
Go to the documentation of this file.
1// @(#)root/mathcore:$Id$
2// Authors: L. Moneta, A. Zsenei 08/2005
3
4 /**********************************************************************
5 * *
6 * Copyright (c) 2004 CERN *
7 * All rights reserved. *
8 * *
9 * For the licensing terms see $ROOTSYS/LICENSE. *
10 * For the list of contributors see $ROOTSYS/README/CREDITS. *
11 * *
12 **********************************************************************/
13
14#ifndef ROOT_Math_WrappedFunction
15#define ROOT_Math_WrappedFunction
16
17#include "IFunction.h"
18
19
20namespace ROOT {
21namespace Math {
22
23
24
25
27
29
30typedef double(*FreeMultiFunctionPtr)(const double*);
31
32/**
33 Template class to wrap any C++ callable object which takes one argument
34 i.e. implementing operator() (double x) in a One-dimensional function interface.
35 It provides a ROOT::Math::IGenFunction-like signature
36
37 Note: If you want to wrap just the reference (to avoid copying) you need to use
38 Func& or const Func & as template parameter. The former should be used when the
39 operator() is not a const method of Func
40
41 @ingroup GenFunc
42
43 */
44template< typename Func = FreeFunctionPtr >
46
47
48 public:
49
50 /**
51 construct from the pointer to the object and the member function
52 */
54 fFunc( f )
55 { /* no op */ }
56
57 // use default copy constructor and assignment operator
58
59 /// clone (required by the interface)
60 WrappedFunction * Clone() const override {
61 return new WrappedFunction(fFunc);
62 }
63
64 // virtual ~WrappedFunction() { /**/ }
65
66private:
67
68 double DoEval (double x) const override {
69 return fFunc( x );
70 }
71
72
73 Func fFunc;
74
75
76}; // WrappedFunction
77
78
79/**
80 Template class to wrap any member function of a class
81 taking a double and returning a double in a 1D function interface
82 For example, if you have a class like:
83 struct X {
84 double Eval(double x);
85 };
86 you can wrapped in the following way:
87 WrappedMemFunction<X, double ( X::* ) (double) > f;
88
89
90 @ingroup GenFunc
91
92 */
93
94template<typename FuncObj, typename MemFuncPtr >
96
97
98 public:
99
100 /**
101 construct from the pointer to the object and the member function
102 */
103 WrappedMemFunction( FuncObj & obj, MemFuncPtr memFn ) :
104 fObj(&obj),
105 fMemFunc( memFn )
106 { /* no op */ }
107
108 // use default copy constructor and assignment operator
109
110 /// clone (required by the interface)
111 WrappedMemFunction * Clone() const override {
112 return new WrappedMemFunction(*fObj,fMemFunc);
113 }
114
115
116private:
117
118 double DoEval (double x) const override {
119 return ((*fObj).*fMemFunc)( x );
120 }
121
122
123 FuncObj * fObj;
124 MemFuncPtr fMemFunc;
125
126
127}; // WrappedMemFunction
128
129
130/**
131 Template class to wrap any C++ callable object
132 implementing operator() (const double * x) in a multi-dimensional function interface.
133 It provides a ROOT::Math::IGenMultiFunction-like signature
134
135 Note: If you want to wrap just the reference (to avoid copying) you need to use
136 Func& or const Func & as template parameter. The former should be used when the
137 operator() is not a const method of Func
138
139 @ingroup GenFunc
140
141 */
142template< typename Func = FreeMultiFunctionPtr >
144
145
146 public:
147
148 /**
149 construct from the pointer to the object and the member function
150 */
151 WrappedMultiFunction( Func f , unsigned int dim = 1) :
152 fFunc( f ),
153 fDim( dim)
154 { /* no op */ }
155
156 // use default copy constructor and assignment operator
157
158 /// clone (required by the interface)
159 WrappedMultiFunction * Clone() const override {
160 return new WrappedMultiFunction(fFunc,fDim);
161 }
162
163 unsigned int NDim() const override { return fDim; }
164
165 // virtual ~WrappedFunction() { /**/ }
166
167private:
168
169 double DoEval (const double * x) const override {
170 return fFunc( x );
171 }
172
173
174 Func fFunc;
175 unsigned int fDim;
176
177
178}; // WrappedMultiFunction
179
180
181template<typename FuncObj, typename MemFuncPtr >
183
184
185 public:
186
187 /**
188 construct from the pointer to the object and the member function
189 */
190 WrappedMemMultiFunction( FuncObj & obj, MemFuncPtr memFn, unsigned int dim = 1 ) :
191 fObj(&obj),
192 fMemFunc( memFn ),
193 fDim(dim)
194 { /* no op */ }
195
196 // use default copy constructor and assignment operator
197
198 /// clone (required by the interface)
199 WrappedMemMultiFunction * Clone() const override {
201 }
202
203
204 unsigned int NDim() const override { return fDim; }
205
206private:
207
208 double DoEval (const double * x) const override {
209 return ((*fObj).*fMemFunc)( x );
210 }
211
212
213 FuncObj * fObj;
214 MemFuncPtr fMemFunc;
215 unsigned int fDim;
216
217
218}; // WrappedMemMultiFunction
219
220
221} // namespace Math
222} // namespace ROOT
223
224
225
226#endif // ROOT_Math_WrappedFunction
#define f(i)
Definition RSha256.hxx:104
Documentation for the abstract class IBaseFunctionMultiDim.
Definition IFunction.h:61
Interface (abstract class) for generic functions objects of one-dimension Provides a method to evalua...
Definition IFunction.h:112
Template class to wrap any C++ callable object which takes one argument i.e.
double DoEval(double x) const override
implementation of the evaluation function. Must be implemented by derived classes
WrappedFunction * Clone() const override
clone (required by the interface)
WrappedFunction(Func f)
construct from the pointer to the object and the member function
Template class to wrap any member function of a class taking a double and returning a double in a 1D ...
double DoEval(double x) const override
implementation of the evaluation function. Must be implemented by derived classes
WrappedMemFunction(FuncObj &obj, MemFuncPtr memFn)
construct from the pointer to the object and the member function
WrappedMemFunction * Clone() const override
clone (required by the interface)
WrappedMemMultiFunction * Clone() const override
clone (required by the interface)
WrappedMemMultiFunction(FuncObj &obj, MemFuncPtr memFn, unsigned int dim=1)
construct from the pointer to the object and the member function
double DoEval(const double *x) const override
unsigned int NDim() const override
Retrieve the dimension of the function.
Template class to wrap any C++ callable object implementing operator() (const double * x) in a multi-...
WrappedMultiFunction(Func f, unsigned int dim=1)
construct from the pointer to the object and the member function
WrappedMultiFunction * Clone() const override
clone (required by the interface)
double DoEval(const double *x) const override
unsigned int NDim() const override
Retrieve the dimension of the function.
Double_t x[n]
Definition legend1.C:17
Namespace for new Math classes and functions.
double(* FreeMultiFunctionPtr)(const double *)
double(* FreeFunctionPtr)(double)
tbb::task_arena is an alias of tbb::interface7::task_arena, which doesn't allow to forward declare tb...