maptype.h

Go to the documentation of this file.
00001 /////////////////////////////////////////////////////////////////////////////
00002 ///
00003 /// @file maptype.h
00004 ///
00005 /// An abstract map type.
00006 /// This file contains the definition of an abstract class
00007 /// of a multi-parameter map for the program "cmgraphs.cpp".
00008 /// Each class which defines a particular map should be derived
00009 /// from the class "MapType" defined in this file,
00010 /// or at least should have the same interface.
00011 ///
00012 /// @author Pawel Pilarczyk
00013 ///
00014 /////////////////////////////////////////////////////////////////////////////
00015 
00016 // Copyright (C) 1997-2008 by Pawel Pilarczyk.
00017 //
00018 // This file is part of my research software package.  This is free software;
00019 // you can redistribute it and/or modify it under the terms of the GNU
00020 // General Public License as published by the Free Software Foundation;
00021 // either version 2 of the License, or (at your option) any later version.
00022 //
00023 // This software is distributed in the hope that it will be useful,
00024 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00025 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00026 // GNU General Public License for more details.
00027 //
00028 // You should have received a copy of the GNU General Public License along
00029 // with this software; see the file "license.txt".  If not, write to the
00030 // Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
00031 // MA 02111-1307, USA.
00032 
00033 // Started on February 9, 2008. Last revision: February 9, 2008.
00034 
00035 
00036 #ifndef _CMGRAPHS_MAPTYPE_H_
00037 #define _CMGRAPHS_MAPTYPE_H_
00038 
00039 
00040 // --------------------------------------------------
00041 // ------------- the abstract map class -------------
00042 // --------------------------------------------------
00043 
00044 /// This is an abstract class which defines the interface to other classes
00045 /// that describe maps for the use for the program "cmgraphs.cpp".
00046 class MapType
00047 {
00048 public:
00049         /// The default constructor of an object which describes a map.
00050         MapType ();
00051 
00052         /// The destructor of an object which describe a map.
00053         virtual ~MapType ();
00054 
00055         /// Sets the parameters to the given intervals defined by their
00056         /// left and right coordinates.
00057         void setParam (const double *left, const double *right, int n);
00058 
00059         /// Returns the left value of the given parameter.
00060         const double &getLeftParam (int n) const;
00061 
00062         /// Returns the right value of the given parameter.
00063         const double &getRightParam (int n) const;
00064 
00065         /// Computes the image of a box whose left and right coordinates
00066         /// are given. Fills in the images with the left and right
00067         /// coordinates of the image box.
00068         virtual void compute (const double *xleft, const double *xright,
00069                 double *yleft, double *yright, int dim) const = 0;
00070 
00071         /// An interface to the function 'compute' based on intervals.
00072         template <class IntervalType>
00073         void operator () (const IntervalType *x, IntervalType *y,
00074                 int dim) const;
00075 
00076 private:
00077         /// The left ends of the parameter intervals of the map.
00078         double *leftParam;
00079 
00080         /// The right ends of the parameter intervals of the map.
00081         double *rightParam;
00082 
00083         /// The number of parameters defined.
00084         int nParam;
00085 
00086         /// The copy constructor should not be used.
00087         MapType (const MapType &);
00088 
00089         /// The assignment operator should not be used.
00090         MapType &operator = (const MapType &);
00091 
00092 }; /* class MapType */
00093 
00094 // --------------------------------------------------
00095 
00096 inline MapType::MapType (): leftParam (0), rightParam (0), nParam (0)
00097 {
00098         return;
00099 } /* MapType::MapType */
00100 
00101 inline MapType::~MapType ()
00102 {
00103         if (leftParam)
00104                 delete [] leftParam;
00105         if (rightParam)
00106                 delete [] rightParam;
00107         return;
00108 } /* MapType::~MapType */
00109 
00110 inline MapType::MapType (const MapType &)
00111 {
00112         return;
00113 } /* MapType::MapType */
00114 
00115 inline MapType &MapType::operator = (const MapType &)
00116 {
00117         return *this;
00118 } /* MapType::operator = */
00119 
00120 inline void MapType::setParam (const double *left, const double *right,
00121         int n)
00122 {
00123         if (n <= 0)
00124                 return;
00125         if (n != nParam)
00126         {
00127                 if (nParam)
00128                 {
00129                         delete [] leftParam;
00130                         delete [] rightParam;
00131                 }
00132                 leftParam = new double [n];
00133                 rightParam = new double [n];
00134                 nParam = n;
00135         }
00136         for (int i = 0; i < nParam; ++ i)
00137         {
00138                 leftParam [i] = left [i];
00139                 rightParam [i] = right [i];
00140         }
00141         return;
00142 } /* MapType::setParam */
00143 
00144 inline const double &MapType::getLeftParam (int n) const
00145 {
00146         if (!leftParam || (n >= nParam))
00147                 throw "Requested left parameter not defined.";
00148         return leftParam [n];
00149 } /* MapType::getLeftParam */
00150 
00151 inline const double &MapType::getRightParam (int n) const
00152 {
00153         if (!rightParam || (n >= nParam))
00154                 throw "Requested right parameter not defined.";
00155         return rightParam [n];
00156 } /* MapType::getRightParam */
00157 
00158 template <class IntervalType>
00159 inline void MapType::operator () (const IntervalType *x, IntervalType *y,
00160         int dim) const
00161 {
00162         double *buffer = new double [4 * dim];
00163         double *xLeft = buffer;
00164         double *xRight = buffer + dim;
00165         for (int i = 0; i < dim; ++ i)
00166         {
00167                 xLeft [i] = x [i]. leftBound ();
00168                 xRight [i] = x [i]. rightBound ();
00169         }
00170         double *yLeft = buffer + 2 * dim;
00171         double *yRight = buffer + 3 * dim;
00172         this -> compute (xLeft, xRight, yLeft, yRight, dim);
00173         for (int i = 0; i < dim; ++ i)
00174                 y [i] = IntervalType (yLeft [i], yRight [i]);
00175         delete [] buffer;
00176         return;
00177 } /* MapType::compute */
00178 
00179 
00180 #endif // _CMGRAPHS_MAPTYPE_H_
00181 

Generated on Sun Mar 28 17:47:57 2010 for The Conley-Morse Graphs Software by  doxygen 1.5.3