Grid.hxx

00001 // Copyright (C) 2003-2007, Vivien Mallet
00002 //
00003 // This file is part of SeldonData library, used for data processing.
00004 //
00005 // SeldonData is free software; you can redistribute it and/or modify it under
00006 // the terms of the GNU General Public License as published by the Free
00007 // Software Foundation; either version 2 of the License, or (at your option)
00008 // any later version.
00009 //
00010 // SeldonData 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 General Public License for
00013 // more details.
00014 //
00015 // For more information, visit the SeldonData home page:
00016 //      http://vivienmallet.net/lib/seldondata/
00017 
00018 #ifndef FILE_SELDONDATA_GRID_HXX
00019 
00020 namespace SeldonData
00021 {
00022 
00023 
00024   /********/
00025   /* Grid */
00026   /********/
00027 
00029   template <class T>
00030   class Grid
00031   {
00032 
00033     // typedef declarations.
00034   public:
00035     typedef T value_type;
00036     typedef T* pointer;
00037     typedef const T* const_pointer;
00038     typedef T& reference;
00039     typedef const T& const_reference;
00040     
00041   protected:
00043     int length_;
00045     int variable_;
00046 
00049     bool duplicate_;
00051     // are there?
00052     int pointers_;
00053 
00055     value_type zero_;
00056     
00057   public:
00058 
00059     // Constructors.
00060 
00061     Grid()  throw();
00062     Grid(int length, int variable = 0)  throw();
00063     Grid(const Grid& G)  throw();
00064 
00065     // Destructor.
00066 
00067     virtual ~Grid()  throw();
00068 
00069     // Methods.
00070 
00071     virtual Grid<T>& operator= (const Grid<T>&);
00072 
00073     virtual int GetLength() const;
00074     virtual int GetLength(int i) const;
00075     int GetVariable() const;
00076     virtual bool IsDependent(int i) const;
00077 
00078     virtual int GetNbElements() const;
00079 
00080     void SetVariable(int variable);
00081 
00082     void SetPointers(int pointers);
00083     int GetPointers() const;
00084 
00085     void SetDuplicate(bool duplicate);
00086     bool GetDuplicate() const;
00087     virtual Grid<T>* Duplicate() const;
00088     virtual Grid<T>* Copy();
00089 
00090     virtual reference operator () (int i);
00091     virtual value_type operator () (int i) const;
00092 
00093     virtual reference Value(int i0, int i1 = -1,
00094                             int i2 = -1, int i3 = -1,
00095                             int i4 = -1, int i5 = -1,
00096                             int i6 = -1, int i7 = -1,
00097                             int i8 = -1, int i9 = -1);
00098 
00099     virtual value_type Value(int i0, int i1 = -1,
00100                              int i2 = -1, int i3 = -1,
00101                              int i4 = -1, int i5 = -1,
00102                              int i6 = -1, int i7 = -1,
00103                              int i8 = -1, int i9 = -1) const;
00104 
00105     virtual void ChangeCoordsInPlace(Function_Base<T>& f,
00106                                      Array<Grid<T>*, 1> grids);
00107 
00108     virtual void Print() const;
00109 
00110   };
00111 
00112 
00113   /***************/
00114   /* RegularGrid */
00115   /***************/
00116 
00118   template<class T>
00119   class RegularGrid: public Grid<T>
00120   {
00121     
00122     // typedef declarations.
00123   public:
00124     typedef T value_type;
00125     typedef T* pointer;
00126     typedef const T* const_pointer;
00127     typedef T& reference;
00128     typedef const T& const_reference;
00129     
00130   protected:
00132     Array<value_type, 1> values_;
00133 
00134   public:
00135 
00136     // Constructors.
00137 
00138     RegularGrid()  throw();
00139     RegularGrid(int length, int variable = 0)  throw();
00140     RegularGrid(value_type start, value_type inc, int length, int variable = 0)  throw();
00141     RegularGrid(const Array<value_type, 1>& values, int variable = 0)  throw();
00142     RegularGrid(const Grid<T>& G)  throw();
00143     RegularGrid(const RegularGrid<T>& G)  throw();
00144 
00145     // Destructor.
00146 
00147     ~RegularGrid()  throw();
00148 
00149     // Methods.
00150 
00151     RegularGrid<T>& operator= (const Grid<T>&);
00152     RegularGrid<T>& operator= (const RegularGrid<T>&);
00153 
00154     int GetLength() const;
00155     int GetLength(int i) const;
00156 
00157     int GetNbElements() const;
00158     Array<value_type, 1>& GetArray();
00159     const Array<value_type, 1>& GetArray() const;
00160 
00161     Grid<T>* Duplicate() const;
00162     Grid<T>* Copy();
00163 
00164     reference operator () (int i);
00165     value_type operator () (int i) const;
00166 
00167     reference Value(int i0, int i1 = -1,
00168                     int i2 = -1, int i3 = -1,
00169                     int i4 = -1, int i5 = -1,
00170                     int i6 = -1, int i7 = -1,
00171                     int i8 = -1, int i9 = -1);
00172 
00173     value_type Value(int i0, int i1 = -1,
00174                      int i2 = -1, int i3 = -1,
00175                      int i4 = -1, int i5 = -1,
00176                      int i6 = -1, int i7 = -1,
00177                      int i8 = -1, int i9 = -1) const;
00178 
00179     template <class F>
00180     void Apply(F& function);
00181     template <class T0, class F>
00182     void Apply(RegularGrid<T0>&, F& function);
00183 
00184     void Print() const;
00185 
00186   };
00187   
00188 
00189   /***************/
00190   /* GeneralGrid */
00191   /***************/
00192 
00194   template<class T, int n>
00195   class GeneralGrid: public Grid<T>
00196   {
00197     
00198     // typedef declarations.
00199   public:
00200     typedef T value_type;
00201     typedef T* pointer;
00202     typedef const T* const_pointer;
00203     typedef T& reference;
00204     typedef const T& const_reference;
00205 
00206   protected:
00208     Array<value_type, n> values_;
00210     Array<int, 1> dependencies_;
00211 
00212   public:
00213 
00214     // Constructors.
00215 
00216     GeneralGrid()  throw();
00217     GeneralGrid(Array<value_type, n>& values,
00218                 int variable,
00219                 const TinyVector<int, n>& dependencies)  throw();
00220     GeneralGrid(const TinyVector<int, n>& values_shape,
00221                 int variable,
00222                 const TinyVector<int, n>& dependencies)  throw();
00223     GeneralGrid(const GeneralGrid<T, n>& G)  throw();
00224     GeneralGrid(const Grid<T>& G)  throw();
00225 
00226     // Destructors.
00227 
00228     ~GeneralGrid()  throw();
00229 
00230     // Methods.
00231 
00232     GeneralGrid<T, n>& operator= (const Grid<T>&);
00233     GeneralGrid<T, n>& operator= (const GeneralGrid<T, n>&);
00234 
00235     int GetLength() const;
00236     int GetLength(int i) const;
00237 
00238     int GetNbElements() const;
00239     Array<value_type, n>& GetArray();
00240     const Array<value_type, n>& GetArray() const;
00241     Array<int, 1>& GetDependencies();
00242     const Array<int, 1>& GetDependencies() const;
00243     int GetMainVariable() const;
00244     bool IsDependent(int i) const;
00245     
00246     Grid<T>* Duplicate() const;
00247     Grid<T>* Copy();
00248 
00249     reference operator () (int i);
00250     value_type operator () (int i) const;
00251 
00252     reference Value(int i0, int i1 = -1,
00253                     int i2 = -1, int i3 = -1,
00254                     int i4 = -1, int i5 = -1,
00255                     int i6 = -1, int i7 = -1,
00256                     int i8 = -1, int i9 = -1);
00257     
00258     value_type Value(int i0, int i1 = -1,
00259                      int i2 = -1, int i3 = -1,
00260                      int i4 = -1, int i5 = -1,
00261                      int i6 = -1, int i7 = -1,
00262                      int i8 = -1, int i9 = -1) const;
00263 
00264     void ChangeCoordsInPlace(Function_Base<T>& f, Array<Grid<T>*, 1> grids);
00265 
00266     template <class F>
00267     void Apply(F& function);
00268     template <class T0, class F>
00269     void Apply(GeneralGrid<T0, n>&, F& function);
00270 
00271     void Print() const;
00272 
00273   private:
00276     int main_variable_;
00277 
00278   };
00279 
00280 
00281 }  // namespace Data.
00282 
00283 
00284 #define FILE_SELDONDATA_GRID_HXX
00285 #endif
00286 

Generated on Tue Nov 17 11:20:52 2009 for SeldonData by  doxygen 1.5.1