FunctionWrapper.h

Go to the documentation of this file.
00001 //# FunctionWrapper.h: Construct function objects from C++ functions 
00002 //# Copyright (C) 2001,2002,2005
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$
00027 
00028 #ifndef SCIMATH_FUNCTIONWRAPPER_H
00029 #define SCIMATH_FUNCTIONWRAPPER_H
00030 
00031 //# Includes
00032 #include <casacore/casa/aips.h>
00033 #include <casacore/scimath/Functionals/WrapperParam.h>
00034 #include <casacore/casa/Utilities/CountedPtr.h>
00035 
00036 namespace casacore { //# NAMESPACE CASACORE - BEGIN
00037 
00038 //# Forward declarations
00039 template <class T> class Vector;
00040 template <class T> class WrapperBase;
00041 
00042 // <summary> Construct nD function objects from C++ functions 
00043 // </summary>
00044 //
00045 // <use visibility=export>
00046 //
00047 // <reviewed reviewer="" date="1996/02/22" tests="" demos="">
00048 // </reviewed>
00049 //
00050 // <prerequisite>
00051 //   <li> <linkto class="Function">Function</linkto> class
00052 //   <li> <linkto class="FunctionParam">FunctionParam</linkto>
00053 // </prerequisite>
00054 //
00055 // <synopsis>
00056 // This class is provided so that user can quickly construct a function
00057 // object from a C++ function pointer without having to write a function
00058 // class. The constructor constructs a function object from a function 
00059 // pointer, and an optional parameter list.
00060 // Parameters are necessary if
00061 // the function has to be used in a functional fitting process (see
00062 // <linkto class=GenericL2Fit>GenericL2Fit</linkto>).
00063 //
00064 // The general function signature is <src>f(x;p)</src>, where <src>x</src>
00065 // represents the <em>arguments</em>, and <src>p</src> the parameters.
00066 // The allowed signatures of the function include all combinations of
00067 // arguments and parameters, and are:
00068 // <ul>
00069 //  <li> <src>f()</src>  no arguments e.g. random number or constant
00070 //  <li> <src>f(x)</src>  1-dimensional, e.g. <src>sin(x)</src>
00071 //  <li> <src>f(Vectorx)</src>  n-dimensional, e.g. <src>sin(x+2y)</src>
00072 // </ul>
00073 //
00074 // </synopsis>
00075 //
00076 // <example>
00077 // <srcblock>
00078 // Float func(const Vector<Float>& x) {return x(0)*x(1);}        // x*y
00079 // // Convert C++ functions to Functionals
00080 // FunctionWrapper<Float> Func(func,2);
00081 // </srcblock>
00082 //
00083 
00084 template <class T>
00085 class FunctionWrapper : public WrapperParam<T>
00086 {
00087 public:
00088   //# Constructors
00089   // Default constructor, to enable arrays
00090   FunctionWrapper();
00091   // A function with no parameters and no arguments.
00092   FunctionWrapper(T(*f)());
00093   // A function with parameter and no arguments
00094   // (Note value of isPar irrelevant)
00095   FunctionWrapper(T(*f)( const T&), const Bool isPar);
00096   // A function with parameters and no arguments.
00097   // (Note value of isPar irrelevant)
00098   FunctionWrapper(T(*f)(const Vector<T>&), const Bool isPar);
00099   // Construct a  1-dimensional function with no parameters.
00100   FunctionWrapper(T(*f)(const T&));
00101   // Construct a  1-dimensional function with parameter.
00102   FunctionWrapper(T(*f)(const T&, const T&), const T &par);
00103   // Construct a  1-dimensional function with parameters.
00104   FunctionWrapper(T(*f)(const T&, const Vector<T>&),
00105                     const Vector<T> &par);
00106   // Construct an n-dimensional  function with no parameters.
00107   FunctionWrapper(T(*f)(const Vector<T>&), const Int dim=1);
00108   // Construct an n-dimensional  function with parameter.
00109   FunctionWrapper(T(*f)(const Vector<T>&, const T&),
00110                     const T &par, const uInt dim=1);
00111   // Construct an n-dimensional  function with parameters.
00112   FunctionWrapper(T(*f)(const Vector<T>&, const Vector<T>&),
00113                     const Vector<T> &par, const uInt dim=1);
00114   // Copy constructor (reference semantics)
00115   // <group>
00116   FunctionWrapper(const FunctionWrapper<T> &other);
00117   // </group>
00118   // Copy assignment (reference semantics)
00119   FunctionWrapper<T> &operator=(const FunctionWrapper<T> &other);
00120 
00121   // Destructor
00122   virtual ~FunctionWrapper() {}
00123 
00124   //# Operators    
00125   // Evaluate the function at <src>x</src>.
00126   // <group>
00127   virtual T eval(typename Function<T>::FunctionArg x) const;
00128   // </group>
00129 
00130   //# Member functions
00131   // Get the dimensionality
00132   virtual uInt ndim() const;
00133   // Return a copy of this object from the heap. The caller is responsible 
00134   // for deleting this pointer.
00135   // <group>
00136   virtual Function<T> *clone() const {
00137     return new FunctionWrapper<T>(*this); }
00138   // </group>
00139 
00140 protected:
00141   //# Data
00142   // The function aid object
00143   CountedPtr<WrapperBase<T> > doit_p;
00144 
00145   //# Make members of parent classes known.
00146 protected:
00147   using WrapperParam<T>::param_p;
00148 };
00149 
00150 
00151 } //# NAMESPACE CASACORE - END
00152 
00153 #ifndef CASACORE_NO_AUTO_TEMPLATES
00154 #include <casacore/scimath/Functionals/FunctionWrapper.tcc>
00155 #endif //# CASACORE_NO_AUTO_TEMPLATES
00156 #endif
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines

Generated on 31 Aug 2016 for casa by  doxygen 1.6.1