casacore
Loading...
Searching...
No Matches
WrapperData.h
Go to the documentation of this file.
1//# WrapperData.h: Aid in constructing function objects from C++ functions
2//# Copyright (C) 2001,2002
3//# Associated Universities, Inc. Washington DC, USA.
4//#
5//# This library is free software; you can redistribute it and/or modify it
6//# under the terms of the GNU Library General Public License as published by
7//# the Free Software Foundation; either version 2 of the License, or (at your
8//# option) any later version.
9//#
10//# This library is distributed in the hope that it will be useful, but WITHOUT
11//# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12//# FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
13//# License for more details.
14//#
15//# You should have received a copy of the GNU Library General Public License
16//# along with this library; if not, write to the Free Software Foundation,
17//# Inc., 675 Massachusetts Ave, Cambridge, MA 02139, USA.
18//#
19//# Correspondence concerning AIPS++ should be addressed as follows:
20//# Internet email: casa-feedback@nrao.edu.
21//# Postal address: AIPS++ Project Office
22//# National Radio Astronomy Observatory
23//# 520 Edgemont Road
24//# Charlottesville, VA 22903-2475 USA
25
26#ifndef SCIMATH_WRAPPERDATA_H
27#define SCIMATH_WRAPPERDATA_H
28
29//# Includes
30#include <casacore/casa/aips.h>
31#include <casacore/scimath/Functionals/WrapperBase.h>
32
33namespace casacore { //# NAMESPACE CASACORE - BEGIN
34
35//# Forward declarations
36
37// <summary> Aid in constructing function objects from C++ functions
38// </summary>
39//
40// <use visibility=local>
41//
42// <reviewed reviewer="UNKNOWN" date="before2004/08/25" tests="" demos="">
43// </reviewed>
44//
45// <prerequisite>
46// <li> <linkto class="Function">Function</linkto> class
47// <li> <linkto class="FunctionParam">FunctionParam</linkto>
48// </prerequisite>
49//
50// <synopsis>
51// This class is provided to enable compile time selection of the
52// appropriate function call. Each template incarnation represent a
53// function call interface definition.
54// </synopsis>
55//
56// <example>
57// <srcblock>
58// Float func(const Vector<Float>& x) {return x(0)*x(1);} // x*y
59// // Convert C++ functions to Functionals
60// FunctionWrapper<Float> Func(func, 2);
61// </srcblock>
62//
63
64template <class T, class U, class V, Bool hasX, Bool hasParam>
65class WrapperData : public WrapperBase<T>
66{
67public:
68 //# Constructors
69 // Default constructor: to allow arrays of functions
71
72 // Destructor
73 virtual ~WrapperData() {}
74
75 //# Operators
76 // Evaluate the function at <src>x</src>.
77 // <group>
78 virtual T eval(typename Function<T>::FunctionArg, const V&) const {}
79 // </group>
80
81 //# Member functions
82
83protected:
84 //# Make members of parent classes known.
85 using WrapperBase<T>::ndim_p;
86 using WrapperBase<T>::arg_p;
87};
88
89
90#define WrapperData_TT WrapperData
91
92// <summary> Specialization for calls with argument and parameter
93// </summary>
94// <synopsis> Note that the actual name of the class is
95// <src>WrapperData</src>. The special name is only for the use of
96// cxx2html.
97// </synopsis>
98
99template <class T>
100class WrapperData_TT<T,T,T,True,True> : public WrapperBase<T>
101{
102 typedef WrapperData_TT<T,T,T,True,True> myData;
103
104public:
105 //# Constructors
106 // Standard constructor
107 explicit WrapperData_TT(T(*f)(const T&, const T&), uInt dim=1) :
108 WrapperBase<T>(dim), pf_p(f) {}
109
110 // Destructor
111 virtual ~WrapperData_TT() {}
112
113 //# Operators
114 // Evaluate the function at <src>x</src>.
115 virtual T eval(typename Function<T>::FunctionArg x,
116 const Vector<T> &par) const {
117 if (pf_p) {
118 return
119 pf_p((*static_cast<const typename Function<T>::FunctionArg>(x)),
120 par[0]);
121 }
122 return T(0); }
123
124 //# Member functions
125
126protected:
127 //# Data
128 // Function to call
129 T (*pf_p)(const T&, const T&);
130
131private:
132 // Copy constructor and assignment (not implemented)
133 // <group>
134 WrapperData_TT(const myData &other);
135 myData &operator=(const myData &other);
136 // </group>
137
138protected:
139 //# Make members of parent classes known.
140 using WrapperBase<T>::ndim_p;
141 using WrapperBase<T>::arg_p;
142};
143
144#undef WrapperData_TT
145
146
147#define WrapperData_VT WrapperData
148
149// <summary> Specialization for calls with argument and parameter
150// </summary>
151// <synopsis> Note that the actual name of the class is
152// <src>WrapperData</src>. The special name is only for the use of
153// cxx2html.
154// </synopsis>
155
156template <class T>
157class WrapperData_VT<T,Vector<T>,T,True,True> : public WrapperBase<T>
158{
159 typedef WrapperData_VT<T,Vector<T>,T,True,True> myData;
160
161public:
162 explicit WrapperData_VT(T(*f)(const Vector<T>&, const T&), uInt dim=1) :
163 WrapperBase<T>(dim), pf_p(f) {}
164 virtual ~WrapperData_VT() {}
165 virtual T eval(typename Function<T>::FunctionArg x,
166 const Vector<T> &par) const {
167 if (pf_p) {
168 for (uInt i=0; i<ndim_p; ++i) arg_p[i] = x[i];
169 return pf_p(arg_p, par[0]); }
170 return T(0); }
171
172protected:
173 T (*pf_p)(const Vector<T>&, const T&);
174
175private:
176 WrapperData_VT(const myData &other);
177 myData &operator=(const myData &other);
178
179protected:
180 //# Make members of parent classes known.
181 using WrapperBase<T>::ndim_p;
182 using WrapperBase<T>::arg_p;
183};
184
185#undef WrapperData_VT
186
187
188#define WrapperData_TV WrapperData
189
190// <summary> Specialization for calls with argument and parameters
191// </summary>
192// <synopsis> Note that the actual name of the class is
193// <src>WrapperData</src>. The special name is only for the use of
194// cxx2html.
195// </synopsis>
196
197template <class T>
198class WrapperData_TV<T,T,Vector<T>,True,True> : public WrapperBase<T>
199{
200 typedef WrapperData_TV<T,T,Vector<T>,True,True> myData;
201
202public:
203 explicit WrapperData_TV(T(*f)(const T&, const Vector<T>&), uInt dim=1) :
204 WrapperBase<T>(dim), pf_p(f) {}
205 virtual ~WrapperData_TV() {}
206 virtual T eval(typename Function<T>::FunctionArg x,
207 const Vector<T> &par) const {
208 if (pf_p) {
209 return pf_p((*static_cast<const typename Function<T>::FunctionArg>(x)),
210 par);
211 }
212 return T(0); }
213
214protected:
215 T (*pf_p)(const T&, const Vector<T>&);
216
217private:
218 WrapperData_TV(const myData &other);
219 myData &operator=(const myData &other);
220
221protected:
222 //# Make members of parent classes known.
223 using WrapperBase<T>::ndim_p;
224 using WrapperBase<T>::arg_p;
225};
226
227#undef WrapperData_TV
228
229
230#define WrapperData_VV WrapperData
231
232// <summary> Specialization for calls with argument and parameters
233// </summary>
234// <synopsis> Note that the actual name of the class is
235// <src>WrapperData</src>. The special name is only for the use of
236// cxx2html.
237// </synopsis>
238
239template <class T>
241public WrapperBase<T>
242{
243 typedef WrapperData_VV<T,Vector<T>,Vector<T>,True,True> myData;
244
245public:
246 explicit WrapperData_VV(T(*f)(const Vector<T>&, const Vector<T>&),
247 uInt dim=1) :
248 WrapperBase<T>(dim), pf_p(f) {}
249 virtual ~WrapperData_VV() {}
250 virtual T eval(typename Function<T>::FunctionArg x,
251 const Vector<T> &par) const {
252 if (pf_p) {
253 for (uInt i=0; i<ndim_p; ++i) arg_p[i] = x[i];
254 return pf_p(arg_p, par); }
255 return T(0); }
256
257protected:
258 T (*pf_p)(const Vector<T>&, const Vector<T>&);
259
260private:
261 WrapperData_VV(const myData &other);
262 myData &operator=(const myData &other);
263
264protected:
265 //# Make members of parent classes known.
266 using WrapperBase<T>::ndim_p;
267 using WrapperBase<T>::arg_p;
268};
269
270#undef WrapperData_VV
271
272
273#define WrapperData_FT WrapperData
274
275// <summary> Specialization for calls with no arguments and parameter
276// </summary>
277// <synopsis> Note that the actual name of the class is
278// <src>WrapperData</src>. The special name is only for the use of
279// cxx2html.
280// </synopsis>
281
282template <class T>
283class WrapperData_FT<T,T,T,False,True> : public WrapperBase<T>
284{
285 typedef WrapperData_FT<T,T,T,False,True> myData;
286
287public:
288 explicit WrapperData_FT(T(*f)(const T&)) :
289 WrapperBase<T>(0), pf_p(f) {}
290 virtual ~WrapperData_FT() {}
291 virtual T eval(typename Function<T>::FunctionArg,
292 const Vector<T> &par) const {
293 if (pf_p) return pf_p(par[0]);
294 return T(0); }
295
296protected:
297 T (*pf_p)(const T&);
298
299private:
300 WrapperData_FT(const myData &other);
301 myData &operator=(const myData &other);
302
303protected:
304 //# Make members of parent classes known.
305 using WrapperBase<T>::ndim_p;
306 using WrapperBase<T>::arg_p;
307};
308
309#undef WrapperData_FT
310
311
312#define WrapperData_FV WrapperData
313
314// <summary> Specialization for calls with no arguments and parameters
315// </summary>
316// <synopsis> Note that the actual name of the class is
317// <src>WrapperData</src>. The special name is only for the use of
318// cxx2html.
319// </synopsis>
320
321template <class T>
322class WrapperData_FV<T,T,Vector<T>,False,True> : public WrapperBase<T>
323{
324 typedef WrapperData_FV<T,T,Vector<T>,False,True> myData;
325
326public:
327 explicit WrapperData_FV(T(*f)(const Vector<T>&)) :
328 WrapperBase<T>(0), pf_p(f) {}
329 virtual ~WrapperData_FV() {}
330 virtual T eval(typename Function<T>::FunctionArg,
331 const Vector<T> &par) const {
332 if (pf_p) return pf_p(par);
333 return T(0); }
334
335protected:
336 T (*pf_p)(const Vector<T>&);
337
338private:
339 WrapperData_FV(const myData &other);
340 myData &operator=(const myData &other);
341
342protected:
343 //# Make members of parent classes known.
344 using WrapperBase<T>::ndim_p;
345 using WrapperBase<T>::arg_p;
346};
347
348#undef WrapperData_FV
349
350
351#define WrapperData_TF WrapperData
352
353// <summary> Specialization for calls with argument and no parameters
354// </summary>
355// <synopsis> Note that the actual name of the class is
356// <src>WrapperData</src>. The special name is only for the use of
357// cxx2html.
358// </synopsis>
359
360template <class T>
361class WrapperData_TF<T,T,T,True,False> : public WrapperBase<T>
362{
363 typedef WrapperData_TF<T,T,T,True,False> myData;
364
365public:
366 explicit WrapperData_TF(T(*f)(const T&), uInt dim=1) :
367 WrapperBase<T>(dim), pf_p(f) {}
368 virtual ~WrapperData_TF() {}
369 virtual T eval(typename Function<T>::FunctionArg x,
370 const Vector<T>&) const {
371 if (pf_p) {
372 return pf_p((*static_cast<const typename Function<T>::FunctionArg>(x)));
373 }
374 return T(0); }
375
376protected:
377 T (*pf_p)(const T&);
378
379private:
380 WrapperData_TF(const myData &other);
381 myData &operator=(const myData &other);
382
383protected:
384 //# Make members of parent classes known.
385 using WrapperBase<T>::ndim_p;
386 using WrapperBase<T>::arg_p;
387};
388
389#undef WrapperData_TF
390
391
392#define WrapperData_VF WrapperData
393
394// <summary> Specialization for calls with argument and no parameters
395// </summary>
396// <synopsis> Note that the actual name of the class is
397// <src>WrapperData</src>. The special name is only for the use of
398// cxx2html.
399// </synopsis>
400
401template <class T>
402class WrapperData_VF<T,Vector<T>,T,True,False> : public WrapperBase<T>
403{
404 typedef WrapperData_VF<T,Vector<T>,T,True,False> myData;
405
406public:
407 explicit WrapperData_VF(T(*f)(const Vector<T>&), uInt dim=1) :
408 WrapperBase<T>(dim), pf_p(f) {}
409 virtual ~WrapperData_VF() {}
410 virtual T eval(typename Function<T>::FunctionArg x,
411 const Vector<T> &) const {
412 if (pf_p) {
413 for (uInt i=0; i<ndim_p; ++i) arg_p[i] = x[i];
414 return pf_p(arg_p); }
415 return T(0); }
416
417protected:
418 T (*pf_p)(const Vector<T>&);
419
420private:
421 WrapperData_VF(const myData &other);
422 myData &operator=(const myData &other);
423
424protected:
425 //# Make members of parent classes known.
426 using WrapperBase<T>::ndim_p;
427 using WrapperBase<T>::arg_p;
428};
429
430#undef WrapperData_VF
431
432
433#define WrapperData_FF WrapperData
434
435// <summary> Specialization for calls with no arguments and no parameters
436// </summary>
437// <synopsis> Note that the actual name of the class is
438// <src>WrapperData</src>. The special name is only for the use of
439// cxx2html.
440// </synopsis>
441
442template <class T>
443class WrapperData_FF<T,T,T,False,False> : public WrapperBase<T>
444{
445 typedef WrapperData_FF<T,T,T,True,False> myData;
446
447public:
448 explicit WrapperData_FF(T(*f)()) :
449 WrapperBase<T>(0), pf_p(f) {}
450 virtual ~WrapperData_FF() {}
451 virtual T eval(typename Function<T>::FunctionArg,
452 const Vector<T>&) const {
453 if (pf_p) return pf_p();
454 return T(0); }
455
456protected:
457 T (*pf_p)();
458
459private:
460 WrapperData_FF(const myData &other);
461 myData &operator=(const myData &other);
462
463protected:
464 //# Make members of parent classes known.
465 using WrapperBase<T>::ndim_p;
466 using WrapperBase<T>::arg_p;
467};
468
469#undef WrapperData_FF
470
471} //# NAMESPACE CASACORE - END
472
473#endif
#define WrapperData_VT
#define WrapperData_FF
#define WrapperData_TF
#define WrapperData_VV
#define WrapperData_VF
#define WrapperData_TV
#define WrapperData_FV
#define WrapperData_TT
Definition WrapperData.h:90
#define WrapperData_FT
Vector< T > arg_p
Vector argument interface.
Definition WrapperBase.h:91
uInt ndim_p
Dimensionality.
Definition WrapperBase.h:89
WrapperData_FF< T, T, T, True, False > myData
virtual T eval(typename Function< T >::FunctionArg, const Vector< T > &) const
Evaluate the function at x.
Specialization for calls with no arguments and parameter.
virtual T eval(typename Function< T >::FunctionArg, const Vector< T > &par) const
Evaluate the function at x.
WrapperData_FT< T, T, T, False, True > myData
Specialization for calls with no arguments and parameters.
WrapperData_FV< T, T, Vector< T >, False, True > myData
virtual T eval(typename Function< T >::FunctionArg, const Vector< T > &par) const
Evaluate the function at x.
Specialization for calls with argument and no parameters.
WrapperData_TF< T, T, T, True, False > myData
WrapperData_TF(T(*f)(const T &), uInt dim=1)
virtual T eval(typename Function< T >::FunctionArg x, const Vector< T > &) const
Evaluate the function at x.
Specialization for calls with argument and parameter.
WrapperData_TT< T, T, T, True, True > myData
myData & operator=(const myData &other)
WrapperData_TT(T(*f)(const T &, const T &), uInt dim=1)
Standard constructor.
virtual T eval(typename Function< T >::FunctionArg x, const Vector< T > &par) const
Evaluate the function at x.
WrapperData_TT(const myData &other)
Copy constructor and assignment (not implemented)
Specialization for calls with argument and parameters.
WrapperData_TV< T, T, Vector< T >, True, True > myData
virtual T eval(typename Function< T >::FunctionArg x, const Vector< T > &par) const
Evaluate the function at x.
WrapperData_TV(T(*f)(const T &, const Vector< T > &), uInt dim=1)
Specialization for calls with argument and no parameters.
virtual T eval(typename Function< T >::FunctionArg x, const Vector< T > &) const
Evaluate the function at x.
WrapperData_VF(T(*f)(const Vector< T > &), uInt dim=1)
WrapperData_VF< T, Vector< T >, T, True, False > myData
Specialization for calls with argument and parameter.
virtual T eval(typename Function< T >::FunctionArg x, const Vector< T > &par) const
Evaluate the function at x.
WrapperData_VT(T(*f)(const Vector< T > &, const T &), uInt dim=1)
WrapperData_VT< T, Vector< T >, T, True, True > myData
Specialization for calls with argument and parameters.
WrapperData_VV< T, Vector< T >, Vector< T >, True, True > myData
virtual T eval(typename Function< T >::FunctionArg x, const Vector< T > &par) const
Evaluate the function at x.
WrapperData_VV(T(*f)(const Vector< T > &, const Vector< T > &), uInt dim=1)
virtual T eval(typename Function< T >::FunctionArg, const V &) const
Evaluate the function at x.
Definition WrapperData.h:78
WrapperData()
Default constructor: to allow arrays of functions.
virtual ~WrapperData()
Destructor.
Definition WrapperData.h:73
this file contains all the compiler specific defines
Definition mainpage.dox:28
const Bool False
Definition aipstype.h:42
unsigned int uInt
Definition aipstype.h:49
const Bool True
Definition aipstype.h:41