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