00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #ifndef FILE_SELDONDATA_GRID_HXX
00020
00021 namespace SeldonData
00022 {
00023
00024
00025
00026
00027
00028
00030 template <class T>
00031 class Grid
00032 {
00033
00034
00035 public:
00036 typedef T value_type;
00037 typedef T* pointer;
00038 typedef const T* const_pointer;
00039 typedef T& reference;
00040 typedef const T& const_reference;
00041
00042 protected:
00044 int length_;
00046 int variable_;
00047
00050 bool duplicate_;
00052
00053 int pointers_;
00054
00056 value_type zero_;
00057
00058 public:
00059
00060
00061
00062 Grid() throw();
00063 Grid(int length, int variable = 0) throw();
00064 Grid(const Grid& G) throw();
00065
00066
00067
00068 virtual ~Grid() throw();
00069
00070
00071
00072 virtual Grid<T>& operator= (const Grid<T>&);
00073
00074 virtual int GetLength() const;
00075 virtual int GetLength(int i) const;
00076 int GetVariable() const;
00077 virtual bool IsDependent(int i) const;
00078
00079 virtual int GetNbElements() const;
00080
00081 void SetVariable(int variable);
00082
00083 void SetPointers(int pointers);
00084 int GetPointers() const;
00085
00086 void SetDuplicate(bool duplicate);
00087 bool GetDuplicate() const;
00088 virtual Grid<T>* Duplicate() const;
00089 virtual Grid<T>* Copy();
00090
00091 virtual reference operator () (int i);
00092 virtual value_type operator () (int i) const;
00093
00094 virtual reference Value(int i0, int i1 = -1,
00095 int i2 = -1, int i3 = -1,
00096 int i4 = -1, int i5 = -1,
00097 int i6 = -1, int i7 = -1,
00098 int i8 = -1, int i9 = -1);
00099
00100 virtual value_type Value(int i0, int i1 = -1,
00101 int i2 = -1, int i3 = -1,
00102 int i4 = -1, int i5 = -1,
00103 int i6 = -1, int i7 = -1,
00104 int i8 = -1, int i9 = -1) const;
00105
00106 virtual void ChangeCoordsInPlace(Function_Base<T>& f,
00107 Array<Grid<T>*, 1> grids);
00108
00109 virtual void Print() const;
00110
00111 };
00112
00113
00114
00115
00116
00117
00119 template<class T>
00120 class RegularGrid: public Grid<T>
00121 {
00122
00123
00124 public:
00125 typedef T value_type;
00126 typedef T* pointer;
00127 typedef const T* const_pointer;
00128 typedef T& reference;
00129 typedef const T& const_reference;
00130
00131 protected:
00133 Array<value_type, 1> values_;
00134
00135 public:
00136
00137
00138
00139 RegularGrid() throw();
00140 RegularGrid(int length, int variable = 0) throw();
00141 RegularGrid(value_type start, value_type inc, int length, int variable = 0) throw();
00142 RegularGrid(const Array<value_type, 1>& values, int variable = 0) throw();
00143 RegularGrid(const Grid<T>& G) throw();
00144 RegularGrid(const RegularGrid<T>& G) throw();
00145
00146
00147
00148 ~RegularGrid() throw();
00149
00150
00151
00152 RegularGrid<T>& operator= (const Grid<T>&);
00153 RegularGrid<T>& operator= (const RegularGrid<T>&);
00154
00155 int GetLength() const;
00156 int GetLength(int i) const;
00157
00158 int GetNbElements() const;
00159 Array<value_type, 1>& GetArray();
00160 const Array<value_type, 1>& GetArray() const;
00161
00162 Grid<T>* Duplicate() const;
00163 Grid<T>* Copy();
00164
00165 reference operator () (int i);
00166 value_type operator () (int i) const;
00167
00168 reference Value(int i0, int i1 = -1,
00169 int i2 = -1, int i3 = -1,
00170 int i4 = -1, int i5 = -1,
00171 int i6 = -1, int i7 = -1,
00172 int i8 = -1, int i9 = -1);
00173
00174 value_type Value(int i0, int i1 = -1,
00175 int i2 = -1, int i3 = -1,
00176 int i4 = -1, int i5 = -1,
00177 int i6 = -1, int i7 = -1,
00178 int i8 = -1, int i9 = -1) const;
00179
00180 template <class F>
00181 void Apply(F& function);
00182 template <class T0, class F>
00183 void Apply(RegularGrid<T0>&, F& function);
00184
00185 void Print() const;
00186
00187 };
00188
00189
00190
00191
00192
00193
00195 template<class T, int n>
00196 class GeneralGrid: public Grid<T>
00197 {
00198
00199
00200 public:
00201 typedef T value_type;
00202 typedef T* pointer;
00203 typedef const T* const_pointer;
00204 typedef T& reference;
00205 typedef const T& const_reference;
00206
00207 protected:
00209 Array<value_type, n> values_;
00211 Array<int, 1> dependencies_;
00212
00213 public:
00214
00215
00216
00217 GeneralGrid() throw();
00218 GeneralGrid(Array<value_type, n>& values,
00219 int variable,
00220 const TinyVector<int, n>& dependencies) throw();
00221 GeneralGrid(const TinyVector<int, n>& values_shape,
00222 int variable,
00223 const TinyVector<int, n>& dependencies) throw();
00224 GeneralGrid(const GeneralGrid<T, n>& G) throw();
00225 GeneralGrid(const Grid<T>& G) throw();
00226
00227
00228
00229 ~GeneralGrid() throw();
00230
00231
00232
00233 GeneralGrid<T, n>& operator= (const Grid<T>&);
00234 GeneralGrid<T, n>& operator= (const GeneralGrid<T, n>&);
00235
00236 int GetLength() const;
00237 int GetLength(int i) const;
00238
00239 int GetNbElements() const;
00240 Array<value_type, n>& GetArray();
00241 const Array<value_type, n>& GetArray() const;
00242 Array<int, 1>& GetDependencies();
00243 const Array<int, 1>& GetDependencies() const;
00244 int GetMainVariable() const;
00245 bool IsDependent(int i) const;
00246
00247 Grid<T>* Duplicate() const;
00248 Grid<T>* Copy();
00249
00250 reference operator () (int i);
00251 value_type operator () (int i) const;
00252
00253 reference Value(int i0, int i1 = -1,
00254 int i2 = -1, int i3 = -1,
00255 int i4 = -1, int i5 = -1,
00256 int i6 = -1, int i7 = -1,
00257 int i8 = -1, int i9 = -1);
00258
00259 value_type Value(int i0, int i1 = -1,
00260 int i2 = -1, int i3 = -1,
00261 int i4 = -1, int i5 = -1,
00262 int i6 = -1, int i7 = -1,
00263 int i8 = -1, int i9 = -1) const;
00264
00265 void ChangeCoordsInPlace(Function_Base<T>& f, Array<Grid<T>*, 1> grids);
00266
00267 template <class F>
00268 void Apply(F& function);
00269 template <class T0, class F>
00270 void Apply(GeneralGrid<T0, n>&, F& function);
00271
00272 void Print() const;
00273
00274 private:
00277 int main_variable_;
00278
00279 };
00280
00281
00282 }
00283
00284
00285 #define FILE_SELDONDATA_GRID_HXX
00286 #endif
00287