casa
$Rev:20696$
|
00001 //# Functional.h: Map a domain object into a range object via operator(). 00002 //# Copyright (C) 1995,1996,1999-2001 00003 //# Associated Universities, Inc. Washington DC, USA. 00004 //# 00005 //# This library is free software; you can redistribute it and/or modify it 00006 //# under the terms of the GNU Library General Public License as published by 00007 //# the Free Software Foundation; either version 2 of the License, or (at your 00008 //# option) any later version. 00009 //# 00010 //# This library is distributed in the hope that it will be useful, but WITHOUT 00011 //# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 00012 //# FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public 00013 //# License for more details. 00014 //# 00015 //# You should have received a copy of the GNU Library General Public License 00016 //# along with this library; if not, write to the Free Software Foundation, 00017 //# Inc., 675 Massachusetts Ave, Cambridge, MA 02139, USA. 00018 //# 00019 //# Correspondence concerning AIPS++ should be addressed as follows: 00020 //# Internet email: aips2-request@nrao.edu. 00021 //# Postal address: AIPS++ Project Office 00022 //# National Radio Astronomy Observatory 00023 //# 520 Edgemont Road 00024 //# Charlottesville, VA 22903-2475 USA 00025 //# 00026 //# $Id: Functional.h 20551 2009-03-25 00:11:33Z Malte.Marquarding $ 00027 00028 #ifndef CASA_FUNCTIONAL_H 00029 #define CASA_FUNCTIONAL_H 00030 00031 //# Includes 00032 #include <casa/aips.h> 00033 00034 namespace casa { //# NAMESPACE CASA - BEGIN 00035 00036 //# Forward declaration 00037 template<class T> class Lattice; 00038 00039 // <summary> Map a domain object into a range object via operator(). 00040 // </summary> 00041 00042 // <use visibility=export> 00043 00044 // <reviewed reviewer="UNKNOWN" date="before2004/08/25" tests="" demos=""> 00045 // </reviewed> 00046 00047 // <etymology> The term ``Functional'' was chosen to follow the usage 00048 // in Barton and Nackman's ``Scientific and Engineering C++.'' 00049 // </etymology> 00050 // 00051 // <synopsis> 00052 // A <src>Functional<Domain,Range></src> is an abstract base class which 00053 // encapsulates the mapping of an object of type <src>Domain</src> into an 00054 // object of type <src>Range</src>. 00055 // This operation is invoked via operator() to make it look like 00056 // a function call. 00057 // 00058 // While these functions are <src>function-like</src>, there is no guarantee 00059 // that evaluations of the same parameter will yield the same result 00060 // (the implementor of a particular class could, for example, merely choose 00061 // to emit a random number). 00062 // However implementors of <src>Functional</src> classes are strongly 00063 // encouraged to implement (visible) side-effect free semantics in their 00064 // classes. 00065 // 00066 // A <src>Functional</src> object is used in circumstances similar to those 00067 // in which a function pointer could be used. An advantage of the 00068 // <src>Functional</src> objects is that it is possible to have more than 00069 // one of them at the same time. 00070 // Another potential advantage (not yet 00071 // implemented) is that it will be possible to perform functional 00072 // composition at run time, e.g. a=b+c where a,b, and c are 00073 // <src>Functionals</src>. 00074 // Another advantage is that since the Functional implementations 00075 // will in general be templated, the same source code would yield 00076 // instantiations for all the numeric types and for specializations like 00077 // automatic derivatives. 00078 // 00079 // To be of greatest utility, a library of functions that do mathematics, 00080 // plotting, etc. on Functional objects needs to be developed. 00081 // </synopsis> 00082 // 00083 // <example> 00084 // The following simple example shows how you can write a function that uses a 00085 // Functional object. 00086 // <srcblock> 00087 // Double integrate1D(const Functional<Float,Float> &f, 00088 // Double x1, Double x2, Double dx) { 00089 // uInt n = (xend - xstart) / dx; 00090 // Double sum = 0.0; 00091 // for (uInt i=0; i < n; i++) sum += f(x1 + i*dx) * dx; 00092 // return sum; 00093 // } 00094 // </srcblock> 00095 // Obviously this isn't a very serious algorithm! 00096 // </example> 00097 // 00098 // <motivation> 00099 // The specific application that caused the implementation of these 00100 // <src>Functional</src> 00101 // classes was the creation of the <linkto module="Fitting">Fitting 00102 // </linkto> module, which needed classes to represent the fitting functions. 00103 // </motivation> 00104 // 00105 // <templating arg=Domain> 00106 // <li> Accessible default and copy constructors, assignment operators, 00107 // and destructors will almost always also be required. 00108 // </templating> 00109 // 00110 // <templating arg=Range> 00111 // <li> A copy constructor is absolutely required for Range objects because 00112 // operator() returns Range objects by value. 00113 // <li> Accessible default constructors, assignment operators, 00114 // and destructors will almost always also be required. 00115 // </templating> 00116 // 00117 // <todo asof="2001/08/29"> 00118 // <li> For polymorphic access it could be that a <src>clone()</src> function 00119 // is needed at this level. 00120 // </todo> 00121 00122 template<class Domain, class Range> class Functional { 00123 public: 00124 //# Constructors 00125 // Destructor 00126 virtual ~Functional(); 00127 00128 //# Operators 00129 // Map a Domain <src>x</src> into a Range <src>y</src> value. 00130 virtual Range operator()(const Domain &x) const = 0; 00131 }; 00132 00133 00134 } //# NAMESPACE CASA - END 00135 00136 #ifndef CASACORE_NO_AUTO_TEMPLATES 00137 #include <casa/BasicMath/Functional.tcc> 00138 #endif //# CASACORE_NO_AUTO_TEMPLATES 00139 #endif