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