ODIN
tjarray.h
1  /***************************************************************************
2  tjvector.h - description
3  -------------------
4  begin : Thu Feb 22 2001
5  copyright : (C) 2000-2021 by Thies Jochimsen
6  email : thies@jochimsen.de
7  ***************************************************************************/
8 
9 /***************************************************************************
10  * *
11  * This program is free software; you can redistribute it and/or modify *
12  * it under the terms of the GNU General Public License as published by *
13  * the Free Software Foundation; either version 2 of the License, or *
14  * (at your option) any later version. *
15  * *
16  ***************************************************************************/
17 
18 
19 #ifndef TJARRAY_H
20 #define TJARRAY_H
21 
22 
23 
24 #include <tjutils/tjvector.h>
25 #include <tjutils/tjlog.h>
26 
27 
41 class ndim : public STD_vector<unsigned long> {
42 
43 public:
44 
49  ndim (unsigned long d=0);
50 
55  ndim (const ndim& mm) : STD_vector<unsigned long>(mm) {}
56 
62  ndim (const STD_string& s);
63 
68  unsigned long dim() const {return size();}
69 
74  operator STD_string () const;
75 
79  friend STD_ostream& operator << (STD_ostream& s,const ndim& nn) { return s << STD_string(nn);}
80 
86 
92 
98  ndim& add_dim ( unsigned long e, bool first=false );
99 
104  unsigned long total() const;
105 
110  unsigned long extent2index(const ndim& mm) const;
111 
116  ndim index2extent(unsigned long index) const;
117 
122  bool operator == (const ndim& nn) const;
123 
128  bool operator != (const ndim& nn) const;
129 
134  ndim& reduce ( unsigned long dim );
135 
141 };
142 
143 
144 
146 
147 
155 template<class V, class T> class tjarray : public V {
156 
157 public:
158 
159 
165 
166 
171  tjarray (unsigned long n1);
172  tjarray (unsigned long n1, unsigned long n2);
173  tjarray (unsigned long n1, unsigned long n2, unsigned long n3);
174  tjarray (unsigned long n1, unsigned long n2, unsigned long n3, unsigned long n4);
175  tjarray (unsigned long n1, unsigned long n2, unsigned long n3, unsigned long n4, unsigned long n5);
176 
177 
182  tjarray (const tjarray<V,T> &ta);
183 
184 
189  tjarray (const V& sv);
190 
191 
196  tjarray (const ndim &nn);
197 
198 
203 
208  tjarray<V,T>& operator = (const T& value);
209 
210 
215  V& resize(unsigned int newsize);
216 
217 
224  tjarray<V,T>& redim (const ndim &nn);
225 
226 
233  tjarray<V,T>& redim (unsigned long n1);
234  tjarray<V,T>& redim (unsigned long n1, unsigned long n2);
235  tjarray<V,T>& redim (unsigned long n1, unsigned long n2, unsigned long n3);
236  tjarray<V,T>& redim (unsigned long n1, unsigned long n2, unsigned long n3, unsigned long n4);
237  tjarray<V,T>& redim (unsigned long n1, unsigned long n2, unsigned long n3, unsigned long n4, unsigned long n5);
238 
239 
244  tjarray<V,T>& autosize () {extent.autosize(); return *this;}
245 
246 
251  const ndim& get_extent () const;
252 
253 
258  T& operator () (const ndim& ii);
259 
260 
265  const T& operator () (const ndim& ii) const;
266 
267 
272  T& operator () (unsigned long n1);
273  T& operator () (unsigned long n1, unsigned long n2);
274  T& operator () (unsigned long n1, unsigned long n2, unsigned long n3);
275  T& operator () (unsigned long n1, unsigned long n2, unsigned long n3, unsigned long n4);
276  T& operator () (unsigned long n1, unsigned long n2, unsigned long n3, unsigned long n4, unsigned long n5);
277 
278 
283  const T& operator () (unsigned long n1) const;
284  const T& operator () (unsigned long n1, unsigned long n2) const;
285  const T& operator () (unsigned long n1, unsigned long n2, unsigned long n3) const;
286  const T& operator () (unsigned long n1, unsigned long n2, unsigned long n3, unsigned long n4) const;
287  const T& operator () (unsigned long n1, unsigned long n2, unsigned long n3, unsigned long n4, unsigned long n5) const;
288 
289 
294  unsigned long dim() const;
295 
296 
301  unsigned long size(unsigned long i) const;
302 
303 
308  unsigned long total() const;
309 
310 
315  unsigned long length() const;
316 
321  unsigned int elementsize() const;
322 
328 
329 
335 
336 
341  friend STD_ostream& operator << (STD_ostream& s, const tjarray<V,T> &ta) {
342  return s << ta.get_extent() << "=" << ta.printbody();
343  }
344 
345 
350  ndim create_index(unsigned long index) const;
351 
352 
353 
354  private:
355 
356  static ndim create_extent(unsigned long n1);
357  static ndim create_extent(unsigned long n1,unsigned long n2);
358  static ndim create_extent(unsigned long n1,unsigned long n2,unsigned long n3);
359  static ndim create_extent(unsigned long n1,unsigned long n2,unsigned long n3,unsigned long n4);
360  static ndim create_extent(unsigned long n1,unsigned long n2,unsigned long n3,unsigned long n4,unsigned long n5);
361 
362  ndim extent;
363 
364  T element_dummy;
365 };
366 
367 
369 // Aliases:
370 
375 
380 
385 
386 
391 
392 
397 
398 
399 
401 // Helper functions:
402 
408  STD_string print_table(const sarray& table);
409 
410 
415  sarray parse_table(const STD_string& str);
416 
417 
420 #endif
Definition: tjarray.h:41
unsigned long total() const
ndim(const ndim &mm)
Definition: tjarray.h:55
unsigned long extent2index(const ndim &mm) const
bool operator!=(const ndim &nn) const
unsigned long dim() const
Definition: tjarray.h:68
ndim(const STD_string &s)
ndim & add_dim(unsigned long e, bool first=false)
friend STD_ostream & operator<<(STD_ostream &s, const ndim &nn)
Definition: tjarray.h:79
ndim index2extent(unsigned long index) const
bool operator==(const ndim &nn) const
ndim(unsigned long d=0)
ndim & operator--()
ndim & autosize()
ndim & reduce(unsigned long dim)
unsigned long dim() const
tjarray(const tjarray< V, T > &ta)
unsigned long length() const
unsigned int elementsize() const
T & operator()(const ndim &ii)
ndim create_index(unsigned long index) const
tjarray(unsigned long n1)
tjarray< V, T > & operator=(const tjarray< V, T > &ta)
tjarray< V, T > & assignValues(const tjarray< V, T > &ta)
tjarray(const ndim &nn)
unsigned long total() const
tjarray< V, T > & redim(const ndim &nn)
tjarray(const V &sv)
friend STD_ostream & operator<<(STD_ostream &s, const tjarray< V, T > &ta)
Definition: tjarray.h:341
tjarray< V, T > & copy(const tjarray< V, T > &ta)
V & resize(unsigned int newsize)
unsigned long size(unsigned long i) const
tjarray< V, T > & autosize()
Definition: tjarray.h:244
tjarray< V, T > & redim(unsigned long n1)
const ndim & get_extent() const
tjarray< ivector, int > iarray
Definition: tjarray.h:384
tjarray< svector, STD_string > sarray
Definition: tjarray.h:396
STD_string print_table(const sarray &table)
sarray parse_table(const STD_string &str)
tjarray< cvector, STD_complex > carray
Definition: tjarray.h:390
tjarray< dvector, double > darray
Definition: tjarray.h:379
tjarray< fvector, float > farray
Definition: tjarray.h:374