casa  $Rev:20696$
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
UnaryFunction.h
Go to the documentation of this file.
00001 //# UnaryFunction.h: A one dimensional unary function
00002 //# Copyright (C) 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: UnaryFunction.h 21024 2011-03-01 11:46:18Z gervandiepen $
00027 
00028 #ifndef SCIMATH_UNARYFUNCTION_H
00029 #define SCIMATH_UNARYFUNCTION_H
00030 
00031 //# Includes
00032 #include <casa/aips.h>
00033 #include <scimath/Functionals/UnaryParam.h>
00034 #include <scimath/Functionals/Function.h>
00035 
00036 namespace casa { //# NAMESPACE CASA - BEGIN
00037 
00038 //# Forward declarations
00039 
00040 // <summary> A one dimensional unary function
00041 // </summary>
00042 
00043 // <use visibility=export>
00044 
00045 // <reviewed reviewer="" date="" tests="tFunctionHolder" 
00046 // demos="">
00047 // </reviewed>
00048 
00049 // <prerequisite>
00050 //   <li> <linkto class="UnaryParam">UnaryParam</linkto>
00051 //   <li> <linkto class="Function">Function</linkto>
00052 // </prerequisite>
00053 
00054 // <etymology> 
00055 // A 1-dimensional unary hat.
00056 // </etymology>
00057 
00058 // <synopsis> 
00059 // A <src>Unary</src> is described by a height, a center and a width
00060 // (halfwidth). The value is:
00061 // <srcblock>
00062 //      height          (|x-center| <  width)
00063 //   0.5height          (|x-center| == width)
00064 //      0               (|x-center| >  width)
00065 // </srcblock>
00066 // The parameters are enumerated by HEIGHT, CENTER and WIDTH. They have
00067 // default values of (1, 0, 1).
00068 // </synopsis> 
00069 //
00070 // <example>
00071 // <srcblock>
00072 //    UnaryFunction<Double> sf(5.0, 25.0, 7);
00073 //    sf(25);            // = 5.0
00074 // </srcblock>
00075 // </example>
00076 
00077 // <templating arg=T>
00078 //  <li> T should have standard numerical operators
00079 // </templating>
00080 
00081 // <thrown>
00082 //    <li> AipsError if incorrect parameter number specified.
00083 // </thrown>
00084 //
00085 
00086 template<class T> class UnaryFunction : public UnaryParam<T>
00087 {
00088 public:
00089   //# Constructors
00090   // Constructs the UnaryFunction, Defaults:
00091   // height=1, center=0, width=1.
00092   // <note role=warning> Could not use default arguments
00093   // that worked both with gcc and IRIX </note>
00094   // <group>
00095   UnaryFunction() : UnaryParam<T>() {}
00096   explicit UnaryFunction(const T &height) :
00097     UnaryParam<T>(height) {}
00098   UnaryFunction(const T &height, const T &center) :
00099     UnaryParam<T>(height, center) {}
00100   UnaryFunction(const T &height, const T &center, const T &width) :
00101     UnaryParam<T>(height, center, width) {}
00102   // </group>
00103 
00104   // Copy constructor (deep copy)
00105   // <group>
00106   UnaryFunction(const UnaryFunction<T> &other) : UnaryParam<T>(other) {}
00107   template <class W>
00108   UnaryFunction(const UnaryFunction<W> &other) : UnaryParam<T>(other) {}
00109   // </group>
00110   // Copy assignment (deep copy)
00111   UnaryFunction<T> &operator=(const UnaryFunction<T> &other) {
00112     UnaryParam<T>::operator=(other); return *this; }
00113     
00114   // Destructor
00115   virtual ~UnaryFunction() {}
00116 
00117   //# Operators    
00118   // Evaluate the Unary at <src>x</src>.
00119   // If a vector is used as the argument only its first element is used.
00120   // <group>
00121   virtual T eval(typename Function<T>::FunctionArg x) const;
00122   // </group>
00123     
00124   //# Member functions
00125   // Return a copy of this object from the heap. The caller is responsible 
00126   // for deleting this pointer. 
00127   // <group>
00128   virtual Function<T> *clone() const { return new UnaryFunction<T>(*this); }
00129   virtual Function<typename FunctionTraits<T>::DiffType> *cloneAD() const {
00130     return new UnaryFunction<typename FunctionTraits<T>::DiffType>(*this); }
00131   virtual Function<typename FunctionTraits<T>::BaseType> *cloneNonAD() const {
00132     return new UnaryFunction<typename FunctionTraits<T>::BaseType>(*this); }
00133   // </group>
00134 
00135   //# Make members of parent classes known.
00136 protected:
00137   using UnaryParam<T>::param_p;
00138 public:
00139   using UnaryParam<T>::nparameters;
00140   using UnaryParam<T>::CENTER;
00141   using UnaryParam<T>::WIDTH;
00142   using UnaryParam<T>::HEIGHT;
00143 };
00144 
00145 
00146 } //# NAMESPACE CASA - END
00147 
00148 #ifndef CASACORE_NO_AUTO_TEMPLATES
00149 #include <scimath/Functionals/UnaryFunction.tcc>
00150 #endif //# CASACORE_NO_AUTO_TEMPLATES
00151 #endif