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