casacore
Loading...
Searching...
No Matches
Functional.h
Go to the documentation of this file.
1// # Functional.h: Map a domain object into a range object via operator().
2// # Copyright (C) 1995,1996,1999-2001
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 CASA_FUNCTIONAL_H
27#define CASA_FUNCTIONAL_H
28
29// # Includes
30#include <casacore/casa/aips.h>
31
32namespace casacore { // # NAMESPACE CASACORE - BEGIN
33
34// # Forward declaration
35template <class T>
36class Lattice;
37
38// <summary> Map a domain object into a range object via operator().
39// </summary>
40
41// <use visibility=export>
42
43// <reviewed reviewer="UNKNOWN" date="before2004/08/25" tests="" demos="">
44// </reviewed>
45
46// <etymology> The term ``Functional'' was chosen to follow the usage
47// in Barton and Nackman's ``Scientific and Engineering C++.''
48// </etymology>
49//
50// <synopsis>
51// A <src>Functional<Domain,Range></src> is an abstract base class which
52// encapsulates the mapping of an object of type <src>Domain</src> into an
53// object of type <src>Range</src>.
54// This operation is invoked via operator() to make it look like
55// a function call.
56//
57// While these functions are <src>function-like</src>, there is no guarantee
58// that evaluations of the same parameter will yield the same result
59// (the implementor of a particular class could, for example, merely choose
60// to emit a random number).
61// However implementors of <src>Functional</src> classes are strongly
62// encouraged to implement (visible) side-effect free semantics in their
63// classes.
64//
65// A <src>Functional</src> object is used in circumstances similar to those
66// in which a function pointer could be used. An advantage of the
67// <src>Functional</src> objects is that it is possible to have more than
68// one of them at the same time.
69// Another potential advantage (not yet
70// implemented) is that it will be possible to perform functional
71// composition at run time, e.g. a=b+c where a,b, and c are
72// <src>Functionals</src>.
73// Another advantage is that since the Functional implementations
74// will in general be templated, the same source code would yield
75// instantiations for all the numeric types and for specializations like
76// automatic derivatives.
77//
78// To be of greatest utility, a library of functions that do mathematics,
79// plotting, etc. on Functional objects needs to be developed.
80// </synopsis>
81//
82// <example>
83// The following simple example shows how you can write a function that uses a
84// Functional object.
85// <srcblock>
86// Double integrate1D(const Functional<Float,Float> &f,
87// Double x1, Double x2, Double dx) {
88// uInt n = (xend - xstart) / dx;
89// Double sum = 0.0;
90// for (uInt i=0; i < n; i++) sum += f(x1 + i*dx) * dx;
91// return sum;
92// }
93// </srcblock>
94// Obviously this isn't a very serious algorithm!
95// </example>
96//
97// <motivation>
98// The specific application that caused the implementation of these
99// <src>Functional</src>
100// classes was the creation of the <linkto module="Fitting">Fitting
101// </linkto> module, which needed classes to represent the fitting functions.
102// </motivation>
103//
104// <templating arg=Domain>
105// <li> Accessible default and copy constructors, assignment operators,
106// and destructors will almost always also be required.
107// </templating>
108//
109// <templating arg=Range>
110// <li> A copy constructor is absolutely required for Range objects because
111// operator() returns Range objects by value.
112// <li> Accessible default constructors, assignment operators,
113// and destructors will almost always also be required.
114// </templating>
115//
116// <todo asof="2001/08/29">
117// <li> For polymorphic access it could be that a <src>clone()</src> function
118// is needed at this level.
119// </todo>
120
121template <class Domain, class Range>
123 public:
124 // # Constructors
125 // Destructor
126 virtual ~Functional();
127
128 // # Operators
129 // Map a Domain <src>x</src> into a Range <src>y</src> value.
130 virtual Range operator()(const Domain &x) const = 0;
131};
132
133} // namespace casacore
134
135#ifndef CASACORE_NO_AUTO_TEMPLATES
136#include <casacore/casa/BasicMath/Functional.tcc>
137#endif // # CASACORE_NO_AUTO_TEMPLATES
138#endif
virtual ~Functional()
Destructor.
virtual Range operator()(const Domain &x) const =0
Map a Domain x into a Range y value.
For temporary backward namespace compatibility, use casa as alias for casacore.
Definition mainpage.dox:28