casa  $Rev:20696$
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
MarshallableChebyshev.h
Go to the documentation of this file.
00001 //# MarshalableChebyshev.h: a Marshallable Chebyshev polynomial
00002 //# Copyright (C) 2002
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 //#! ========================================================================
00027 //# $Id: MarshallableChebyshev.h 21024 2011-03-01 11:46:18Z gervandiepen $
00028 
00029 #ifndef SCIMATH_MARSHALLABLECHEBYSHEV_H
00030 #define SCIMATH_MARSHALLABLECHEBYSHEV_H
00031 
00032 #include <casa/aips.h>
00033 #include <scimath/Functionals/Chebyshev.h>
00034 #include <scimath/Functionals/FunctionMarshallable.h>
00035 
00036 namespace casa { //# NAMESPACE CASA - BEGIN
00037 
00038 //# Forward Declarations
00039 
00040 // <summary> A Chebyshev function class that supports serialization
00041 // </summary>
00042 
00043 // <use visibility=export>
00044 
00045 // <reviewed reviewer="wbrouw" date="2001/11/12" tests="tChebyshev" demos="">
00046 // </reviewed>
00047 
00048 // <prerequisite>
00049 //   <li> <linkto class=Function>Function</linkto>
00050 // </prerequisite>
00051 //
00052 // <etymology>
00053 // This class is named after Chebyshev Type I polynomials.  "Marshallable" 
00054 // means that the class can be serialized into a form that can be transmitted 
00055 // to another execution context.  
00056 // </etymology>
00057 //
00058 // <synopsis>
00059 // This class is a specialization of the Chebyshev class that supports 
00060 // serialization.  That is, it allows one to write the state of the Chebyshev 
00061 // polynomial object into a Record.  This record can then be transmitted 
00062 // to another execution context (e.g.  or another AIPS++ DO) where it 
00063 // can be "reconstituted" as a new object with identical state as this one.  
00064 // This documentation focusses on this serialization functionality (also known 
00065 // as "marshalling"); for details about the general features of the Chebyshev 
00066 // polynomial series, see the <linkto class="Chebyshev">Chebyshev</linkto> 
00067 // class.
00068 // </synopsis>
00069 //
00070 // <example>
00071 // </example>
00072 //
00073 // <motivation>
00074 // Making Chebyshev Marshallable provides a convenient way of configuring
00075 // the simulator tool from .
00076 // </motivation>
00077 //
00078 // <thrown>
00079 //    <li> Assertion in debug mode if attempt is made to address incorrect
00080 //              coefficients
00081 // </thrown>
00082 //
00083 
00084 template<class T>
00085 class MarshallableChebyshev : public Chebyshev<T>, 
00086                                 public FunctionMarshallable 
00087 {
00088 private:
00089     static const String modenames[];
00090 
00091 public:
00092     static const String FUNCTYPE;
00093     static const String FUNCFIELDS[];
00094 
00095     // definitions of the fields stored in a serialized Record.  The 
00096     // actual string names are stored in FUNCFIELDS
00097     enum FieldNames {
00098         // the array of coefficients
00099         COEFFS,
00100         // the default mode
00101         MODE,
00102         // the default value to use when mode=CONSTANT
00103         DEF,
00104         // the 2-element double array
00105         INTERVAL,
00106         // the number of supported fields
00107         NFieldNames
00108     };
00109 
00110     //# Constructors
00111     // create a zero-th order Chebyshev polynomial with the first coefficient
00112     // equal to zero.  The bounded domain is [T(-1), T(1)].  The 
00113     // OutOfDomainMode is CONSTANT, and the default value is T(0).
00114     MarshallableChebyshev() : 
00115         Chebyshev<T>(), FunctionMarshallable(FUNCTYPE) {}
00116 
00117     // create an n-th order Chebyshev polynomial with the coefficients
00118     // equal to zero.  The bounded domain is [T(-1), T(1)].  The 
00119     // OutOfDomainMode is CONSTANT, and the default value is T(0).
00120     explicit MarshallableChebyshev(const uInt n) : 
00121         Chebyshev<T>(n), FunctionMarshallable(FUNCTYPE)  {}
00122 
00123     // create a zero-th order Chebyshev polynomical with the first coefficient
00124     // equal to one.  
00125     //   min is the minimum value of its Chebyshev interval, and 
00126     //   max is the maximum value.  
00127     //   mode sets the behavior of the function outside the Chebyshev interval
00128     //      (see setOutOfIntervalMode() and OutOfIntervalMode enumeration 
00129     //      definition for details).  
00130     //   defval is the value returned when the function is evaluated outside
00131     //      the Chebyshev interval and mode=CONSTANT.
00132     MarshallableChebyshev(const T &min, const T &max,
00133                             const typename ChebyshevEnums::
00134                             OutOfIntervalMode mode=ChebyshevEnums::CONSTANT,
00135                             const T &defval=T(0)) :
00136         Chebyshev<T>(min, max, mode, defval), FunctionMarshallable(FUNCTYPE) 
00137     {}
00138   
00139     // create a fully specified Chebyshev polynomial.  
00140     //   coeffs holds the coefficients of the Chebyshev polynomial (see 
00141     //      setCoefficients() for details).
00142     //   min is the minimum value of its canonical range, and 
00143     //   max is the maximum value.  
00144     //   mode sets the behavior of the function outside the Chebyshev interval
00145     //      (see setOutOfIntervalMode() and OutOfIntervalMode enumeration 
00146     //      definition for details).  
00147     //   defval is the value returned when the function is evaluated outside
00148     //      the canonical range and mode=CONSTANT.
00149     MarshallableChebyshev(const Vector<T> &coeffs, 
00150                             const T &min, const T &max, 
00151                             const typename ChebyshevEnums::
00152                             OutOfIntervalMode mode=ChebyshevEnums::CONSTANT, 
00153                             const T &defval=T(0)) :
00154         Chebyshev<T>(coeffs, min, max, mode, defval), 
00155         FunctionMarshallable(FUNCTYPE)  
00156     {}
00157   
00158     // create a fully specified Chebyshev polynomial from parameters 
00159     // stored in a Record.  
00160     explicit MarshallableChebyshev(const Record& gr) 
00161         throw(InvalidSerializationError);
00162 
00163     // create a deep copy of another Chebyshev polynomial
00164     // <group>
00165     MarshallableChebyshev(const Chebyshev<T> &other) : 
00166         Chebyshev<T>(other), FunctionMarshallable(FUNCTYPE) {}
00167     MarshallableChebyshev(const MarshallableChebyshev<T> &other) : 
00168         Chebyshev<T>(other), FunctionMarshallable(other) {}
00169     // </group>
00170   
00171     // make a (deep) copy of another Chebyshev polynomial
00172     // <group>
00173     MarshallableChebyshev<T> &operator=(
00174         const MarshallableChebyshev<T> &other) 
00175     {
00176         FunctionMarshallable::operator=(other);
00177         Chebyshev<T>::operator=(other); 
00178         return *this; 
00179     }
00180     MarshallableChebyshev<T> &operator=(
00181         const Chebyshev<T> &other) 
00182     {
00183         Chebyshev<T>::operator=(other); 
00184         return *this; 
00185     }
00186     // </group>
00187   
00188     // Destructor
00189     virtual ~MarshallableChebyshev() {}
00190   
00191     // store the state of this Function into a Record
00192     virtual void store(Record& gr) const;
00193 
00194     // Create a copy of this object.  The caller is responsible for
00195     // deleting the pointer. 
00196     virtual Function<T> *clone() const { 
00197         return new MarshallableChebyshev<T>(*this); 
00198     }
00199 };
00200 
00201 
00202 } //# NAMESPACE CASA - END
00203 
00204 #ifndef CASACORE_NO_AUTO_TEMPLATES
00205 #include <scimath/Functionals/MarshallableChebyshev.tcc>
00206 #endif //# CASACORE_NO_AUTO_TEMPLATES
00207 #endif