casa  5.7.0-16
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
FunctionWrapper.h
Go to the documentation of this file.
1 //# FunctionWrapper.h: Construct function objects from C++ functions
2 //# Copyright (C) 2001,2002,2005
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_FUNCTIONWRAPPER_H
29 #define SCIMATH_FUNCTIONWRAPPER_H
30 
31 //# Includes
32 #include <casacore/casa/aips.h>
35 
36 namespace casacore { //# NAMESPACE CASACORE - BEGIN
37 
38 //# Forward declarations
39 template <class T> class Vector;
40 template <class T> class WrapperBase;
41 
42 // <summary> Construct nD function objects from C++ functions
43 // </summary>
44 //
45 // <use visibility=export>
46 //
47 // <reviewed reviewer="" date="1996/02/22" tests="" demos="">
48 // </reviewed>
49 //
50 // <prerequisite>
51 // <li> <linkto class="Function">Function</linkto> class
52 // <li> <linkto class="FunctionParam">FunctionParam</linkto>
53 // </prerequisite>
54 //
55 // <synopsis>
56 // This class is provided so that user can quickly construct a function
57 // object from a C++ function pointer without having to write a function
58 // class. The constructor constructs a function object from a function
59 // pointer, and an optional parameter list.
60 // Parameters are necessary if
61 // the function has to be used in a functional fitting process (see
62 // <linkto class=GenericL2Fit>GenericL2Fit</linkto>).
63 //
64 // The general function signature is <src>f(x;p)</src>, where <src>x</src>
65 // represents the <em>arguments</em>, and <src>p</src> the parameters.
66 // The allowed signatures of the function include all combinations of
67 // arguments and parameters, and are:
68 // <ul>
69 // <li> <src>f()</src> no arguments e.g. random number or constant
70 // <li> <src>f(x)</src> 1-dimensional, e.g. <src>sin(x)</src>
71 // <li> <src>f(Vectorx)</src> n-dimensional, e.g. <src>sin(x+2y)</src>
72 // </ul>
73 //
74 // </synopsis>
75 //
76 // <example>
77 // <srcblock>
78 // Float func(const Vector<Float>& x) {return x(0)*x(1);} // x*y
79 // // Convert C++ functions to Functionals
80 // FunctionWrapper<Float> Func(func,2);
81 // </srcblock>
82 //
83 
84 template <class T>
85 class FunctionWrapper : public WrapperParam<T>
86 {
87 public:
88  //# Constructors
89  // Default constructor, to enable arrays
91  // A function with no parameters and no arguments.
92  FunctionWrapper(T(*f)());
93  // A function with parameter and no arguments
94  // (Note value of isPar irrelevant)
95  FunctionWrapper(T(*f)( const T&), const Bool isPar);
96  // A function with parameters and no arguments.
97  // (Note value of isPar irrelevant)
98  FunctionWrapper(T(*f)(const Vector<T>&), const Bool isPar);
99  // Construct a 1-dimensional function with no parameters.
100  FunctionWrapper(T(*f)(const T&));
101  // Construct a 1-dimensional function with parameter.
102  FunctionWrapper(T(*f)(const T&, const T&), const T &par);
103  // Construct a 1-dimensional function with parameters.
104  FunctionWrapper(T(*f)(const T&, const Vector<T>&),
105  const Vector<T> &par);
106  // Construct an n-dimensional function with no parameters.
107  FunctionWrapper(T(*f)(const Vector<T>&), const Int dim=1);
108  // Construct an n-dimensional function with parameter.
109  FunctionWrapper(T(*f)(const Vector<T>&, const T&),
110  const T &par, const uInt dim=1);
111  // Construct an n-dimensional function with parameters.
112  FunctionWrapper(T(*f)(const Vector<T>&, const Vector<T>&),
113  const Vector<T> &par, const uInt dim=1);
114  // Copy constructor (reference semantics)
115  // <group>
116  FunctionWrapper(const FunctionWrapper<T> &other);
117  // </group>
118  // Copy assignment (reference semantics)
120 
121  // Destructor
122  virtual ~FunctionWrapper() {}
123 
124  //# Operators
125  // Evaluate the function at <src>x</src>.
126  // <group>
127  virtual T eval(typename Function<T>::FunctionArg x) const;
128  // </group>
129 
130  //# Member functions
131  // Get the dimensionality
132  virtual uInt ndim() const;
133  // Return a copy of this object from the heap. The caller is responsible
134  // for deleting this pointer.
135  // <group>
136  virtual Function<T> *clone() const {
137  return new FunctionWrapper<T>(*this); }
138  // </group>
139 
140 protected:
141  //# Data
142  // The function aid object
144 
145  //# Make members of parent classes known.
146 protected:
148 };
149 
150 
151 } //# NAMESPACE CASACORE - END
152 
153 #ifndef CASACORE_NO_AUTO_TEMPLATES
154 #include <casacore/scimath/Functionals/FunctionWrapper.tcc>
155 #endif //# CASACORE_NO_AUTO_TEMPLATES
156 #endif
A 1-D Specialization of the Array class.
int Int
Definition: aipstype.h:50
std::vector< double > Vector
Definition: ds9context.h:24
Parameter handling for wrapped function objects.
Definition: WrapperParam.h:81
FunctionWrapper< T > & operator=(const FunctionWrapper< T > &other)
Copy assignment (reference semantics)
Construct nD function objects from C++ functions.
virtual Function< T > * clone() const
Return a copy of this object from the heap.
Referenced counted pointer for constant data.
Definition: VisModelData.h:42
Numerical functional interface class.
bool Bool
Define the standard types used by Casacore.
Definition: aipstype.h:42
virtual T eval(typename Function< T >::FunctionArg x) const
Evaluate the function at x.
CountedPtr< WrapperBase< T > > doit_p
The function aid object.
FunctionWrapper()
Default constructor, to enable arrays.
virtual ~FunctionWrapper()
Destructor.
virtual uInt ndim() const
Get the dimensionality.
unsigned int uInt
Definition: aipstype.h:51
#define casacore
&lt;X11/Intrinsic.h&gt; #defines true, false, casacore::Bool, and String.
Definition: X11Intrinsic.h:42