Garfield++ v1r0
A toolkit for the detailed simulation of particle detectors based on ionisation measurement in gases and semiconductors
Loading...
Searching...
No Matches
AbsArr.h
Go to the documentation of this file.
1#ifndef ABSARR_H
2#define ABSARR_H
3/*
4Simple arrays with variable length.
5DynLinArr - "Dynamic Linear Array" - it is what it is.
6The name is choosen to distinguish this template class from every known
7other libraries.
8The information is kept in one block of memory and accessible with
9indexes. The array is characterized by the only parameter - its physical
10size. If you need a logicl size different from physical, keep the
11logical size in a separated place.
12Increasing of the array size leads to allocation of
13another block of memory and copying all elements to it by
14operator= (which can be correctly defined in the class definitions).
15This is difference with STL, in which vector have logical size
16which can be smaller than the volume of allocated memory.
17Currently the array boundaries are checked at each access, this is
18also difference with STL.
19These checks can be switched out by undefining macro ALR_CHECK_BOUND.
20The copying of array leads to copying all elements, descruction - to
21desctruction of elements.
22The array DynLinArr can keep other array DynLinArr as elements
23and constitute multy-dimensional array of not "parallelogram" shape,
24that is for each first index, the dimension corresponding to
25the second index can be different from that of the other first indexes.
26This is very powerfull feature, but it is not always desirable.
27If you need box-like array or "parallelogram" shape, use DynArr -
28"Dynamic Array".
29
30In DynArr the number of dimensions is arbitrary, but size of this
31array along each dimension is fixed and independent on
32the indexes of other dimensions. So this is rectangular array.
33The access is performed by indexes,
34but not through operators []. Since it is not trivial to provide
35such access for this array, I preferred the simplest solutions
36and arranged this access through little functions "ac":
37 T& DynArr::ac(long i) // for 1-dimensional array
38 T& DynArr::ac(long i1, long i2) // for 2-dimensional array
39 T& DynArr::ac(const DynLinArr<long>& ind)
40 // for arbitrary number of dimensions
41 // but the number of them in array should be equal to size of ind.
42 // ind is array of indexes. Its first element if the first index,
43 // second is second, etc.
44class DynArr is constructed with the help of DynLinArr.
45DynArr can keep as elements another DynArr's or DynLinArr's.
46DynLinArr can also keep DynArr as elements.
47
48There are many various auxiliary utilites assosiated with these arrays.
49Some of them look little bit antiquated, since they was created in
50stone age and were not revised after innovation of electricity.:)
51This happened because the author needed to port his programs on
52very various computers, not all of them had very advanced C++-related
53software. Today the situation with C++ is being changed rapidly
54and some of these pearls may be arranged by more modern way.
55But the main components of this file are actual and very convenient.
56
57Copyright (c) 1999-2005 I. B. Smirnov
58
59The file can be used, copied, modified, and distributed
60according to the terms of GNU Lesser General Public License version 2.1
61as published by the Free Software Foundation,
62and provided that the above copyright notice, this permission notice,
63and notices about any modifications of the original text
64appear in all copies and in supporting documentation.
65The file is provided "as is" without express or implied warranty.
66*/
67#include <iostream>
68#include <iomanip>
72#include "wcpplib/util/String.h"
73
74// Here there is a good place to switch on the bound check in all programs
75#ifndef ALR_CHECK_BOUND
76#define ALR_CHECK_BOUND
77#endif
78#ifndef ALR_CHECK_EACH_BOUND
79#define ALR_CHECK_EACH_BOUND
80#endif
81
82#ifdef USE_REPLACE_ALLOC
84#endif
85
86//#define DEBUG_DYNLINARR // make some print
87//#define DEBUG_DYNARR // make some print and in addition
88// functions from DynArr make some formally unnecessary checks, which are
89// hiwever useful for debug.
90
91// Here there is a good place to switch off the bound check in all programs
92//#ifdef ALR_CHECK_BOUND
93//#undef ALR_CHECK_BOUND
94//#endif
95//#ifdef ALR_CHECK_BOUND
96//error in program
97//#endif
98//#define FUNCTINH
99
100//#define DONT_USE_ABSPTR
101#ifndef DONT_USE_ABSPTR // in oder to supply some programs without
102 // smart pointers
104
105// Note: at current setup, if DONT_USE_ABSPTR is not activated,
106// DynLinArr and DynArr are both addressable from ActivePtr,
107// since they are derived from RegPassivePtr, which is itself addressable,
108// and since they have virtual copy functions and constructors themselves.
109
110#else
111// Some necessary repetitions from AbsPtr.h:
112enum Pilfer {
113 steal
114};
115
116// See AnsPtr.h for details regarding the following:
117#define PILF_CONST const
118#define PILF_MUTABLE mutable
119//#define PILF_CONST
120//#define PILF_MUTABLE
121
122#endif
123#include "wcpplib/math/minmax.h"
124
125extern long max_qel_DynLinArr; // increase it if need
126// Helps to detect access to not inited DynLinArr,
127// what may happen at initializetion of class members
128// and use of not inited member for initialization of the other.
129
130template <class T> class DynArr;
131
132//enum ArgInterp { interp_as_arr }; // these "enums" are replaced to
133// class types because it was noticed that unexpected conversions
134// from and to int may spoil everything, also see comment just below.
136};
137//enum PutArgInterp { interp_as_adr };
138class ArgInterp_SingleAdr // for put_qel()
139 {
140};
141//class PutArgInterp_Arr
142//{ };
143//enum ArgInterpVal { interp_as_val }; // No, it can be converted
144// to int and leads to call of incorrect contructors.
145// Trying to use empty classes.
147};
148
149#ifndef DONT_USE_ABSPTR
150template <class T>
151class DynLinArr : public RegPassivePtr
152#else
153 template <class T>
154 class DynLinArr
155#endif
156 {
157 public:
158 // Constructors
159 DynLinArr(void) : qel(0), el(NULL) { ; }
160 explicit DynLinArr(long fqel) : qel(fqel), el(NULL) {
161 if (qel > max_qel_DynLinArr) {
162 mcerr << "ERROR in DynLinArr(long fqel):\n";
163 mcerr << "qel > max_qel_DynLinArr:\n";
165 mcerr << "Type of T is (in internal notations) " << typeid(T).name()
166 << '\n';
167 spexit(mcerr);
168 }
169 if (qel < 0) {
170 mcerr << "ERROR in DynLinArr(long fqel):\n";
171 mcerr << "qel < 0:\n";
172 Iprintn(mcout, qel);
173 mcerr << "Type of T is (in internal notations) " << typeid(T).name()
174 << '\n';
175 spexit(mcerr);
176 }
177#ifdef USE_REPLACE_ALLOC
178 if (fqel > 0) {
179 el = (T*)malloc(sizeof(T) * fqel);
180 long n;
181 for (n = 0; n < fqel; n++)
182 new (&(el[n])) T;
183 }
184#else
185 el = (fqel > 0) ? (new T[fqel]) : (T*)NULL;
186#endif
187 }
188
189 DynLinArr(long fqel, const T& val) : qel(fqel), el(NULL) {
190 if (qel > max_qel_DynLinArr) {
191 mcerr << "ERROR in DynLinArr(long fqel, const T& val):\n";
192 mcerr << "qel > max_qel_DynLinArr:\n";
194 mcerr << "Type of T is (in internal notations) " << typeid(T).name()
195 << '\n';
196 spexit(mcerr);
197 }
198 if (qel < 0) {
199 mcerr << "ERROR in DynLinArr(long fqel, const T& val):\n";
200 mcerr << "qel < 0:\n";
201 Iprintn(mcout, qel);
202 mcerr << "Type of T is (in internal notations) " << typeid(T).name()
203 << '\n';
204 spexit(mcerr);
205 }
206#ifdef USE_REPLACE_ALLOC
207 if (fqel > 0) {
208 el = (T*)malloc(sizeof(T) * fqel);
209 long n;
210 for (n = 0; n < fqel; n++)
211 new (&(el[n])) T;
212 }
213#else
214 el = (fqel > 0) ? (new T[fqel]) : (T*)NULL;
215#endif
216 assignAll(val);
217 }
218 DynLinArr(long fqel, const T* ar, ArgInterp_Arr /*t*/) : qel(fqel), el(NULL) {
219 if (qel > max_qel_DynLinArr) {
220 mcerr << "ERROR in DynLinArr(long fqel, const T* ar, ArgInterp_Arr):\n";
221 mcerr << "qel > max_qel_DynLinArr:\n";
223 mcerr << "Type of T is (in internal notations) " << typeid(T).name()
224 << '\n';
225 spexit(mcerr);
226 }
227 if (qel < 0) {
228 mcerr << "ERROR in DynLinArr(long fqel, const T* ar, ArgInterp_Arr):\n";
229 mcerr << "qel < 0:\n";
230 Iprintn(mcout, qel);
231 mcerr << "Type of T is (in internal notations) " << typeid(T).name()
232 << '\n';
233 spexit(mcerr);
234 }
235#ifdef USE_REPLACE_ALLOC
236 if (fqel > 0) {
237 el = (T*)malloc(sizeof(T) * fqel);
238 long n;
239 for (n = 0; n < fqel; n++)
240 new (&(el[n])) T;
241 }
242#else
243 el = (fqel > 0) ? (new T[fqel]) : (T*)NULL;
244#endif
245 long n;
246 for (n = 0; n < qel; n++)
247 el[n] = ar[n];
248 }
249 // const T* ar is array here (of course).
250 // ArgInterp_Arr serves to distinguish this
251 // from previous constructor when second argument
252 // does not coincide with T but can be converted to it.
253 // Typical example is when T is double and second argument is 0.
254 // It is assumed that 0 should be converted to 0.0 and previous
255 // constructor should be called. But in practice (Red Hat Linux 6.0)
256 // the compiler says
257 // call of overloaded `DynLinArr(int &, int)' is ambiguous.
258 // I don't know whether this is error of particular compiler or
259 // general problem. But the third dummy argument is anyway convenient
260 // to distringuish these cases.
261
263 template <class D> DynLinArr<T>& operator=(const DynLinArr<D>& f);
264
265 void pass(long fqel, T* fel) {
266 // Do not call directly! Is to be used only
267 // from assignment operator above
268 clear();
269 qel = fqel;
270 el = fel;
271 }
272
273 inline DynLinArr(const DynLinArr<T>& f);
274 DynLinArr(PILF_CONST DynLinArr<T>& f, Pilfer) : qel(f.qel), el(f.el) {
275#ifdef DEBUG_DYNLINARR
276 mcout << "DynLinArr( DynLinArr<T>& f, Pilfer) is working\n";
277#endif
278 f.qel = 0;
279 f.el = 0;
280 }
281 DynLinArr(const DynArr<T>& f); // works only if f has one dimension
282 // otherwise calls spexit.
283
284 DynLinArr(const DynArr<T>& f, int n_of_dim,
285 // 0 - first dim) 1 - second dim)
286 long roc_number);
287 // takes only mentioned raw or column.
288
289 DynLinArr& assignAll(const T& f) {
290 check();
291 long n;
292 for (n = 0; n < qel; n++)
293 el[n] = f;
294 return *this;
295 }
296 template <class X>
297 DynLinArr<T>& assignAll1(const X& f) // assumes that
298 // element is object
299 // which also accepts assignAll, which is called for it.
300 {
301 check();
302 long n;
303 for (n = 0; n < qel; n++)
304 el[n].assignAll(f);
305 return *this;
306 }
307 //DynLinArr& operator=(const T& f) { int n; for( n=0; n<qel; n++) el[n]=f; }
308 inline T& operator[](long n) {
309#ifdef ALR_CHECK_BOUND
310 if (n >= 0 && n < qel) {
311 return el[n];
312 } else {
313 mcerr << "ERROR in const T& DynLinArr::operator[](long n) const: "
314 << "n is out of bounds, n=" << n << " qel=" << qel << '\n';
315 mcerr << "Type of T is (in internal notations) " << typeid(T).name()
316 << '\n';
317 spexit(mcerr);
318#ifdef INS_CRETURN
319 return el[0]; // to quiet Microsoft Visial Studio compiler against
320 // "not all control paths return a value"
321#endif
322 }
323#else
324 return el[n];
325#endif
326 /*
327#ifdef ALR_CHECK_BOUND
328 if(n<0 || n>=qel)
329 {
330 mcerr<<"ERROR in T& DynLinArr::operator[](long n): "
331 <<"n is out of bounds, n="<<n
332 <<" qel="<<qel<<'\n';
333 mcerr<<"Type of T is (in internal notations) "<<typeid(T).name()<<'\n';
334 spexit(mcerr);
335 }
336#endif
337 return el[n];
338 */
339 }
340 inline const T& operator[](long n) const {
341#ifdef ALR_CHECK_BOUND
342 if (n >= 0 && n < qel) {
343 return el[n];
344 } else {
345 mcerr << "ERROR in const T& DynLinArr::operator[](long n) const: "
346 << "n is out of bounds, n=" << n << " qel=" << qel << '\n';
347 mcerr << "Type of T is (in internal notations) " << typeid(T).name()
348 << '\n';
349 spexit(mcerr);
350#ifdef INS_CRETURN // Insert calming return
351 return el[0]; // to quiet Microsoft Visial Studio compiler against
352 // "not all control paths return a value"
353#endif
354 }
355#else
356 return el[n];
357#endif
358 /* // it is more simple to read but might be slower to execute
359#ifdef ALR_CHECK_BOUND
360 if(n<0 || n>=qel)
361 {
362 mcerr<<"ERROR in const T& DynLinArr::operator[](long n) const: "
363 <<"n is out of bounds, n="<<n
364 <<" qel="<<qel<<'\n';
365 mcerr<<"Type of T is (in internal notations) "<<typeid(T).name()<<'\n';
366 spexit(mcerr);
367 }
368#endif
369 return el[n];
370 */
371 }
372 inline T& acu(long n) // unchecked access
373 {
374 return el[n];
375 }
376 inline const T& acu(long n) const // unchecked access
377 {
378 return el[n];
379 }
380 inline T& last_el(void) {
381#ifdef ALR_CHECK_BOUND
382 if (qel > 0) {
383 return el[qel - 1];
384 } else {
385 mcerr << "ERROR in const T& DynLinArr::last_el(void) const: qel <=0:"
386 << " qel" << qel << '\n';
387 mcerr << "Type of T is (in internal notations) " << typeid(T).name()
388 << '\n';
389 spexit(mcerr);
390#ifdef INS_CRETURN // Insert calming return
391 return el[0]; // to quiet Microsoft Visial Studio compiler against
392 // "not all control paths return a value"
393#endif
394 }
395#else
396 return el[qel];
397#endif
398 }
399
400 inline const T& last_el(void) const {
401#ifdef ALR_CHECK_BOUND
402 if (qel > 0) {
403 return el[qel - 1];
404 } else {
405 mcerr << "ERROR in const T& DynLinArr::last_el(void) const: qel <=0:"
406 << " qel" << qel << '\n';
407 mcerr << "Type of T is (in internal notations) " << typeid(T).name()
408 << '\n';
409 spexit(mcerr);
410#ifdef INS_CRETURN // Insert calming return
411 return el[0]; // to quiet Microsoft Visial Studio compiler against
412 // "not all control paths return a value"
413#endif
414 }
415#else
416 return el[qel];
417#endif
418 }
419
420 long get_qel(void) const { return qel; }
421 void put_qel(long fqel);
422 void put_qel(long fqel, const T* val, ArgInterp_SingleAdr t);
423 // creates array with size fqel
424 // If old array existed, then
425 // If it was less than fqel, it all is copied to new array
426 // and the other elements either assigned *val or
427 // remains not inited.
428 // else its fqel part is copyed to new array.
429 // ArgInterp_SingleAdr serves to distinguish this
430 // from next function when second argument
431 // does not coincide with T but can be converted to it
432 // (for example NULL to int and it is not clear which function
433 // should be called.
434 // Attention!, val is an element, this is assimetry with contructor,
435 // in which ar is an array.
436
437 void put_qel(long fqel, const T& val) {
438 put_qel(fqel, &val, ArgInterp_SingleAdr());
439 }
440 void increment(const T* val = NULL) {
441 check();
442 long q = qel + 1;
443 put_qel(q, *val);
444 }
445 void increment(const T& val) {
446 check();
447 long q = qel + 1;
448 put_qel(q, val);
449 }
450 void clear(void) {
451 put_qel(0);
452 } // Not only clears the content,
453 // but makes zero dimension.
455#ifdef DEBUG_DYNLINARR
456 mcout << "DynLinArr::pilfer is called\n";
457#endif
458 if (this != &f) {
459 if (qel != 0) {
460 if (f.qel != 0) {
461 mcerr << "ERROR in DynLinArr::pilfer(...):\n";
462 mcerr << "Both the destination and source arrays are not empty\n";
463 // For explanations why it is dengerous, see similar function
464 // of ActivePtr.
465 spexit(mcerr);
466 } else {
467#ifdef USE_REPLACE_ALLOC
468 {
469 long n;
470 for (n = 0; n < qel; n++)
471 el[n].~T();
472 free(el);
473 }
474#else
475 delete[] el;
476#endif
477 qel = 0;
478 }
479 }
480 el = f.el;
481 qel = f.qel;
482 f.el = NULL;
483 f.qel = 0;
484 }
485 }
486
487 void check(void) const;
488
489 /*
490 void print(std::ostream& file, long qpr) const
491 {
492 Ifile<<"DynLinArr<T>: qel="<<get_qel()<<" qpr="<<qpr<<'\n';
493 long n;
494 indn.n+=2;
495 for( n=0; n<qpr; n++)
496 {
497 Ifile<<"n="<<n<<" el[n]="<<this->DynLinArr<T>::operator[](n)<<'\n';
498 }
499 indn.n-=2;
500 }
501 */
502 DynArr<T> top(void); // transpose the vector, rotate it
503 // from vertical colunm to horisontal line for the purpose
504 // of linear algebra calculations.
505
506 //friend void DLA_sort<T>(DynLinArr<T>& f);
507 // Apply any function of one argument (of type T) to each element.
508 template <class P> friend void apply1(DynLinArr<P>& ar, void (*fun)(P& f));
509 //template<class P> friend void apply1m(DynLinArr<P>& ar,
510 // void (*P::fun)(void));
511 // Apply any function of two arguments
512 // (first of which is of type T and the second is of type of address
513 // of another function (possibly apply1) to each element.
514 template <class P, class X>
515 friend void apply2(DynLinArr<P>& ar, void (*fun1)(P& f, void (*fun21)(X& f)),
516 void (*fun2)(X& f));
517
518 //template<class P, class X> friend void apply2m(DynLinArr<P>& ar,
519 // void (*fun1)(P& f, void (*fun21)(X& f) ),
520 // void (*X::fun2)(void) );
521 //void apply(void (*fun)(T& f))
522 //{ long n; for(n=0; n<qel; n++) (*fun)(el[n]); }
523
524 // Attention: the both sorts below at large N are much less efficient
525 // then sort for standard vectors.
526 // At N of the order of 50000 thay take several seconds,
527 // whereas sort for vectors takes several tenths of second.
528
529 void sort(long q_to_sort = 0); // sorts first q_to_sort to increasing order.
530 // If q_to_sort = 0, it sorts all get_qel() elements.
531
532 void sort(DynLinArr<long>& sort_ind, long q_to_sort = 0) const;
533 // to increasing order
534 // Does not change array, but creates index array which gives access
535 // in sorted order. For example:
536 // DynLinArr< long > sort_ind;
537 // collection.sort(sort_ind);
538 // for(n=0; n<q; n++)
539 // {
540 // collection_ordered[n] = collection[sort_ind[n]];
541 // }
542 // Thus content of each n-th element of sort_ind gives
543 // position of n-th (by size) element of array.
544
545 // finds and sorts minimal q_to_sort elements from all.
547 long q_to_sort = 0) const;
549 long q_to_sort = 0) const;
550
551//void sort(DynLinArr< long >& sort_ind, long q_to_sort = 0) const;
552
553/*
554 The following does not work.
555 It will attempt to instantiate it even for non-class types like long etc.
556 virtual void print(std::ostream& file, int l) const;
557*/
558#ifndef DONT_USE_ABSPTR
560#endif
561
562 virtual ~DynLinArr() {
563 check();
564 if (el != NULL)
565#ifdef USE_REPLACE_ALLOC
566 {
567 long n;
568 for (n = 0; n < qel; n++) {
569 (&(el[n]))->~T();
570 }
571 free(el);
572 }
573#else
574 delete[] el;
575#endif
576 }
577
578 private:
579 PILF_MUTABLE long qel; // number of elements, mutable only for pilfer
580 PILF_MUTABLE T* el; // array of qel elements, mutable only for pilfer
581//(regarding mutable and pilfer see ActivePtr for more comments).
582#ifdef USE_REPLACE_ALLOC
584#endif
585};
586#ifndef DONT_USE_ABSPTR
587template <class T>
589#endif
590 template <class T>
591void apply1(DynLinArr<T>& ar, void (*fun)(T& f)) {
592 long n;
593 for (n = 0; n < ar.qel; n++)
594 (*fun)(ar.el[n]);
595}
596
597//template<class T>
598//void apply1m(DynLinArr<T>& ar, void (*T::fun)(void))
599//{ long n; for(n=0; n<ar.qel; n++) ar.el[n].(*fun)(); }
600
601template <class T, class X>
602void apply2(DynLinArr<T>& ar, void (*fun1)(T& f, void (*fun21)(X& f)),
603 void (*fun2)(X& f)) {
604 long n;
605 for (n = 0; n < ar.qel; n++)
606 (*fun1)(ar.el[n], fun2);
607}
608
609//template<class T, class X>
610//void apply2m(DynLinArr<T>& ar,
611// void (*fun1)(T& f, void (*fun21)(X& f) ),
612// void (*X::fun2)(void) )
613//{ long n; for(n=0; n<ar.qel; n++) (*fun1)(ar.el[n], fun2); }
614
615template <class T> void DynLinArr<T>::check(void) const {
616 if (qel < 0) {
617 mcerr << "ERROR in template<class T> void DynLinArr<T>::check(void):\n";
618 mcerr << "qel < 0, qel=" << qel << '\n';
619 mcerr << "Type of T is (in internal notations) " << typeid(T).name()
620 << '\n';
621 spexit(mcerr);
622 }
623 if (qel == 0 && el != NULL) {
624 mcerr << "ERROR in template<class T> void DynLinArr<T>::check(void):\n";
625 //mcerr<<"qel == 0 && el != NULL: long(el)="<<long(el)<<'\n';
626 mcerr << "qel == 0 && el != NULL: el=" << el << '\n';
627 mcerr << "Type of T is (in internal notations) " << typeid(T).name()
628 << '\n';
629 spexit(mcerr);
630 }
631 if (qel > 0) {
632 if (el == NULL) {
633 mcerr << "ERROR in template<class T> void DynLinArr<T>::check(void):\n";
634 mcerr << "qel > 0 && el == NULL: qel=" << qel << '\n';
635 mcerr << "Type of T is (in internal notations) " << typeid(T).name()
636 << '\n';
637 spexit(mcerr);
638 }
639 if (qel > max_qel_DynLinArr) {
640 mcerr << "ERROR in template<class T> void DynLinArr<T>::check(void):\n";
641 mcerr << "qel > max_qel_DynLinArr: \n";
643 mcerr << "Type of T is (in internal notations) " << typeid(T).name()
644 << '\n';
645 spexit(mcerr);
646 }
647 }
648}
649
650template <class T>
652#ifdef DEBUG_DYNLINARR
653 mcout << "DynLinArr<T>& DynLinArr<T>::operator=(const DynLinArr<T>& f) is "
654 "working\n";
655#endif
656 if (this != &f) {
657 //mcout<<"DynLinArr<T>& operator=(const DynLinArr<T>& f): long(el)="
658 //<<long(el)<<'\n';
659 check();
660 f.check();
661 // First of all we allocate memory and copy to there
662 // all elements from f, because f can be part of this array,
663 // for example, one of its elements.
664 long q = f.get_qel();
665#ifdef USE_REPLACE_ALLOC
666 T* temp_el;
667 if (q > 0) {
668 temp_el = (T*)malloc(sizeof(T) * q);
669 //long n; for(n=0; n<q; n++) new(&(temp_el[n])) T;
670 long n;
671 for (n = 0; n < q; n++)
672 new (&(temp_el[n])) T(f.el[n]); // here
673 // we call copy constructor instead of creating default as for above
674 // and then to copy to it.
675 } else
676 temp_el = NULL;
677#else
678 //mcout<<"operator=: sizeof(T)="<<std::setw(10)<<sizeof(T)<<" q="<<q<<'\n';
679 //T* temp_el = (q > 0) ? (new T[q]) : (T*)NULL;
680 T* temp_el = (T*)NULL;
681 if (q > 0) {
682 //mcout<<"operator=: sizeof(T)="<<std::setw(10)<<sizeof(T)<<"
683 //q="<<q<<'\n';
684 temp_el = new T[q];
685 long n;
686 for (n = 0; n < q; n++)
687 temp_el[n] = f.el[n];
688 }
689#endif
690 //long n; for( n=0; n<q; n++) temp_el[n]=f.el[n];
691 /*
692#ifdef USE_REPLACE_ALLOC
693 for(n=0; n<q; n++) el[n].~T();
694 free(el);
695#else
696 delete[] el;
697#endif
698 qel = q;
699 el = temp_el;
700 */
701 pass(q, temp_el);
702 //el = (qel > 0) ? (new T[qel]) : (T*)NULL;
703 //long n; for( n=0; n<qel; n++) el[n]=f.el[n];
704 }
705 return *this;
706}
707
708template <class T>
709template <class D>
711#ifdef DEBUG_DYNLINARR
712 mcout << "DynLinArr<T>& DynLinArr<T>::operator=(const DynLinArr<D>& f) is "
713 "working\n";
714#endif
715 //if(this != &f)
716 //{
717 //mcout<<"DynLinArr<T>& operator=(const DynLinArr<T>& f): long(el)="
718 //<<long(el)<<'\n';
719 check();
720 f.check();
721 // First of all we allocate memory and copy to there
722 // all elements from f, because f can be part of this array,
723 // for example, one of its elements.
724 long q = f.get_qel();
725#ifdef USE_REPLACE_ALLOC
726 T* temp_el;
727 if (q > 0) {
728 temp_el = (T*)malloc(sizeof(T) * q);
729 //long n; for(n=0; n<q; n++) T* t = new(&(temp_el[n])) T;
730 // What is this (above)? Perhaps I did not debug this.
731
732 long n;
733 for (n = 0; n < q; n++)
734 new (&(temp_el[n])) T(f.el[n]); // here
735 // we call copy constructor instead of creating default as for above
736 // and then to copy to it.
737 } else
738 temp_el = NULL;
739#else
740 //T* temp_el = (q > 0) ? (new T[q]) : (T*)NULL;
741 T* temp_el = (T*)NULL;
742 if (q > 0) {
743 //mcout<<"operator=: sizeof(T)="<<std::setw(10)<<sizeof(T)<<" q="<<q<<'\n';
744 temp_el = new T[q];
745 //long n; for( n=0; n<q; n++) temp_el[n]=f.el[n];
746 long n;
747 for (n = 0; n < q; n++)
748 temp_el[n] = f[n];
749 }
750
751#endif
752 //long n; for( n=0; n<q; n++) temp_el[n] = f.acu(n);
753 pass(q, temp_el);
754 //el = (qel > 0) ? (new T[qel]) : (T*)NULL;
755 //long n; for( n=0; n<qel; n++) el[n]=f.el[n];
756 //}
757 return *this;
758}
759
760template <class T>
762 :
763#ifndef DONT_USE_ABSPTR
764 RegPassivePtr(),
765#endif
766 qel(0),
767 el(NULL) {
768#ifdef DEBUG_DYNLINARR
769 mcout << "DynLinArr(const DynLinArr<T>& f) is working\n";
770#endif
771 *this = f;
772}
773
774template <class T> void DynLinArr<T>::put_qel(long fqel) {
775 //
776 // creates array with size fqel
777 // If old array existed, then
778 // If it was less than fqel, it all is copied to new array
779 // and the other elements either assigned *val or
780 // remains not inited.
781 // else its fqel part is copyed to new array.
782 //mcout<<"put_qel: *this="<<(*this);
783 if (fqel < 0) {
784 mcerr << "ERROR in template<class T> void DynLinArr<T>::put_qel(long "
785 "fqel):\n";
786 mcerr << "fqel < 0, fqel=" << fqel << '\n';
787 mcerr << "Type of T is (in internal notations) " << typeid(T).name()
788 << '\n';
789 spexit(mcerr);
790 }
791 check();
792 if (el == NULL) {
793 qel = fqel;
794 if (qel > 0) {
795#ifdef USE_REPLACE_ALLOC
796 el = (T*)malloc(sizeof(T) * fqel);
797 for (long n = 0; n < fqel; ++n)
798 new (&(el[n])) T;
799#else
800 el = new T[fqel];
801#endif
802 }
803 } else {
804 if (qel != fqel) {
805 if (fqel <= 0) {
806 qel = 0;
807#ifdef USE_REPLACE_ALLOC
808 for (long n = 0; n < qel; ++n)
809 el[n].~T();
810 free(el);
811#else
812 delete[] el;
813#endif
814 el = NULL;
815 } else {
816 T* elh;
817#ifdef USE_REPLACE_ALLOC
818 elh = (T*)malloc(sizeof(T) * fqel);
819 for (n = 0; n < fqel; ++n)
820 new (&(elh[n])) T;
821#else
822 elh = new T[fqel]; // long q = find_min(qel,fqel);
823#endif
824 for (long n = 0; n < fqel; ++n) {
825 if (n < qel) elh[n] = el[n];
826 }
827#ifdef USE_REPLACE_ALLOC
828 for (long n = 0; n < qel; ++n)
829 el[n].~T();
830 free(el);
831#else
832 delete[] el;
833#endif
834 el = elh;
835 qel = fqel;
836 }
837 }
838 }
839}
840
841template <class T>
842void DynLinArr<T>::put_qel(long fqel, const T* val, ArgInterp_SingleAdr t) {
843 // By default val == NULL
844 // creates array with size fqel
845 // If old array existed, then
846 // If it was less than fqel, it all is copied to new array
847 // and the other elements either assigned *val or
848 // remains not inited.
849 // else its fqel part is copyed to new array.
850 //mcout<<"put_qel: *this="<<(*this);
851 if (fqel < 0) {
852 mcerr << "ERROR in template<class T> void DynLinArr<T>::put_qel(long fqel, "
853 "const T* val, ArgInterp_SingleAdr):\n";
854 mcerr << "fqel < 0, fqel=" << fqel << '\n';
855 mcerr << "Type of T is (in internal notations) " << typeid(T).name()
856 << '\n';
857 spexit(mcerr);
858 // Avoid compiler warning because of unused variable t (HS).
859 mcerr << sizeof(t) << "\n";
860 }
861 check();
862 if (el == NULL) {
863 qel = fqel;
864 if (qel > 0) {
865#ifdef USE_REPLACE_ALLOC
866 el = (T*)malloc(sizeof(T) * fqel);
867 for (long n = 0; n < fqel; ++n)
868 new (&(el[n])) T;
869#else
870 el = new T[fqel];
871#endif
872 }
873 if (val != NULL) for (long n = 0; n < qel; ++n)
874 el[n] = *val;
875 } else {
876 if (qel != fqel) {
877 if (fqel <= 0) {
878 qel = 0;
879#ifdef USE_REPLACE_ALLOC
880 for (long n = 0; n < qel; ++n)
881 el[n].~T();
882 free(el);
883#else
884 delete[] el;
885#endif
886 el = NULL;
887 } else {
888 T* elh;
889#ifdef USE_REPLACE_ALLOC
890 elh = (T*)malloc(sizeof(T) * fqel);
891 for (long n = 0; n < fqel; ++n)
892 new (&(elh[n])) T;
893#else
894 elh = new T[fqel]; // long q = find_min(qel,fqel);
895#endif
896 for (long n = 0; n < fqel; ++n) {
897 if (n < qel)
898 elh[n] = el[n];
899 else if (val != NULL)
900 elh[n] = *val;
901 }
902#ifdef USE_REPLACE_ALLOC
903 for (long n = 0; n < qel; ++n)
904 el[n].~T();
905 free(el);
906#else
907 delete[] el;
908#endif
909 el = elh;
910 qel = fqel;
911 }
912 }
913 }
914}
915
916// Simple sorting routine optimized for DynLiArr. )ptimized means
917//not doing checks at each indexing, but it is not the best for the large
918//number of N.
919// Note that it can be made better if at choosing n_possible_next
920// to arrange going backward. But this is much more complicated so currently
921// I am not going to do this.
922
923template <class T> void DynLinArr<T>::sort(long q_to_sort) {
924 mfunnamep("void DynLinArr<T>::sort(long q_to_sort = 0)");
925
926 check_econd12(q_to_sort, >, qel, mcerr);
927 if (q_to_sort <= 0) q_to_sort = qel;
928 if (q_to_sort <= 1) return;
929
930 long n_possible_next = 1;
931 long q_comp = 0;
932 long n, m;
933 for (n = 0; n < q_to_sort - 1; n++) {
934 //Iprint2n(mcout, n, n_possible_next);
935 // first it finds the minimum along the rest and replaces if it is less
936 //long nmin = n+1;
937 long nmin = n_possible_next;
938 T el_min = el[nmin];
939 int s_change_possible_next = 0;
940
941 //for(m=n+2; m<q_to_sort; m++)
942 for (m = n_possible_next + 1; m < q_to_sort; m++) {
943 q_comp++;
944 //if(el[nmin] > el[m])
945 if (el_min > el[m]) {
946 n_possible_next = nmin;
947 s_change_possible_next = 1;
948 nmin = m;
949 el_min = el[nmin];
950 }
951 }
952 //Iprint4n(mcout, n_possible_next, s_change_possible_next, nmin, el_min);
953 if (s_change_possible_next == 0 || n_possible_next < n + 2) {
954 n_possible_next = n + 2;
955 }
956 //if(el[n] > el[nmin])
957 //{
958 // T t = el[nmin];
959 // el[nmin] = el[n];
960 // el[n] = t;
961 //}
962 //Iprintn(mcout, n_possible_next);
963 //Iprint2n(mcout, el[n], el_min);
964 if (el[n] > el_min) {
965 if (s_change_possible_next == 1) {
966 //if(n_possible_next < q_to_sort)
967 if (n_possible_next < q_to_sort && el[n] < el[n_possible_next]) {
968 n_possible_next = nmin;
969 }
970 }
971 //mcout<<"replacing el[n] and el_min\n";
972 T t = el_min;
973 el[nmin] = el[n];
974 el[n] = t;
975 }
976 //Iprintn(mcout, (*this));
977
978 }
979 //Iprintn(mcout, q_comp);
980}
981
982// New variant, should be faster, the old is below.
983
984template <class T>
985void DynLinArr<T>::sort(DynLinArr<long>& sort_ind, long q_to_sort) const {
986 mfunnamep("void DynLinArr<T>::sort(DynLinArr< long >& sort_ind, long "
987 "q_to_sort = 0) const");
988
989 check_econd12(q_to_sort, >, qel, mcerr);
990 if (q_to_sort <= 0) q_to_sort = qel;
991 //if(q_to_sort <= 1) return;
992
993 sort_ind.clear();
994 sort_ind.pilfer(DynLinArr<long>(q_to_sort));
995 long n, m;
996 for (n = 0; n < q_to_sort; n++) {
997 sort_ind.acu(n) = n;
998 }
999 if (q_to_sort <= 1) return;
1000
1001 long n_possible_next = 1;
1002
1003 for (n = 0; n < q_to_sort - 1; n++) {
1004 // first it finds the minimum along the rest and replaces if it is less
1005 long nmin = n_possible_next;
1006 long ind_nmin = sort_ind.acu(nmin);
1007 int s_change_possible_next = 0;
1008
1009 //for(m=n+2; m<q_to_sort; m++)
1010 for (m = n_possible_next + 1; m < q_to_sort; m++) {
1011 if (el[ind_nmin] > el[sort_ind.acu(m)])
1012 //if(el[sort_ind.acu(nmin)] > el[sort_ind.acu(m)])
1013 {
1014 n_possible_next = nmin;
1015 s_change_possible_next = 1;
1016 nmin = m;
1017 ind_nmin = sort_ind.acu(nmin);
1018 }
1019 }
1020 if (s_change_possible_next == 0 || n_possible_next < n + 2) {
1021 n_possible_next = n + 2;
1022 }
1023 if (el[sort_ind.acu(n)] > el[ind_nmin])
1024 //if(el[sort_ind.acu(n)] > el[sort_ind.acu(nmin)])
1025 {
1026 if (s_change_possible_next == 1) {
1027 if (n_possible_next < q_to_sort &&
1028 el[sort_ind.acu(n)] < el[sort_ind.acu(n_possible_next)]) {
1029 n_possible_next = nmin;
1030 }
1031 }
1032 //long t = sort_ind.acu(nmin);
1033 sort_ind.acu(nmin) = sort_ind.acu(n);
1034 sort_ind.acu(n) = ind_nmin;
1035 }
1036 }
1037}
1038
1039template <class T>
1041 long q_to_sort) const {
1042 mfunnamep("void DynLinArr<T>::sort_select_increasing(DynLinArr< long >& "
1043 "sort_ind, long q_to_sort = 0) const");
1044
1045 check_econd12(q_to_sort, >, qel, mcerr);
1046 long s_last_noninc = 0;
1047 if (q_to_sort <= 0) {
1048 q_to_sort = qel;
1049 s_last_noninc = 1;
1050 } else if (q_to_sort == qel) {
1051 s_last_noninc = 1;
1052 }
1053
1054 //if(qel <= 1) return;
1055 sort_ind.clear();
1056 sort_ind.pilfer(DynLinArr<long>(qel));
1057 long n, m;
1058 for (n = 0; n < qel; n++) {
1059 sort_ind[n] = n;
1060 }
1061 if (q_to_sort <= 1) return;
1062
1063 long n_possible_next = 1;
1064
1065 for (n = 0; n < q_to_sort - s_last_noninc; n++) {
1066 // first it finds the minimum along the rest and replaces if it is less
1067 long nmin = n_possible_next;
1068 long ind_nmin = sort_ind[nmin];
1069 int s_change_possible_next = 0;
1070
1071 //for(m=n+2; m<q_to_sort; m++)
1072 for (m = n_possible_next + 1; m < qel; m++) {
1073 if (el[ind_nmin] > el[sort_ind[m]])
1074 //if(el[sort_ind.acu(nmin)] > el[sort_ind.acu(m)])
1075 {
1076 n_possible_next = nmin;
1077 s_change_possible_next = 1;
1078 nmin = m;
1079 ind_nmin = sort_ind[nmin];
1080 }
1081 }
1082 if (s_change_possible_next == 0 || n_possible_next < n + 2) {
1083 n_possible_next = n + 2;
1084 }
1085 if (el[sort_ind[n]] > el[ind_nmin])
1086 //if(el[sort_ind.acu(n)] > el[sort_ind.acu(nmin)])
1087 {
1088 if (s_change_possible_next == 1) {
1089 if (n_possible_next < q_to_sort &&
1090 el[sort_ind[n]] < el[sort_ind[n_possible_next]]) {
1091 n_possible_next = nmin;
1092 }
1093 }
1094 //long t = sort_ind.acu(nmin);
1095 sort_ind[nmin] = sort_ind[n];
1096 sort_ind[n] = ind_nmin;
1097 }
1098 }
1099 sort_ind.put_qel(qel);
1100}
1101
1102template <class T>
1104 long q_to_sort) const {
1105 mfunnamep("void DynLinArr<T>::sort_select_decreasing(DynLinArr< long >& "
1106 "sort_ind, long q_to_sort = 0) const");
1107
1108 check_econd12(q_to_sort, >, qel, mcerr);
1109 long s_last_noninc = 0;
1110 if (q_to_sort <= 0) {
1111 q_to_sort = qel;
1112 s_last_noninc = 1;
1113 } else if (q_to_sort == qel) {
1114 s_last_noninc = 1;
1115 }
1116 //Iprintn(mcout, q_to_sort);
1117
1118 //if(qel <= 1) return;
1119 sort_ind.clear();
1120 sort_ind.pilfer(DynLinArr<long>(qel));
1121 long n, m;
1122 for (n = 0; n < qel; n++) {
1123 sort_ind[n] = n;
1124 }
1125 if (q_to_sort <= 1) return;
1126
1127 long n_possible_next = 1;
1128
1129 for (n = 0; n < q_to_sort - s_last_noninc; n++) {
1130 //Iprintn(mcout, n);
1131 // first it finds the minimum along the rest and replaces if it is less
1132 long nmax = n_possible_next;
1133 //Iprintn(mcout, nmax);
1134 long ind_nmax = sort_ind[nmax];
1135 int s_change_possible_next = 0;
1136
1137 //for(m=n+2; m<q_to_sort; m++)
1138 for (m = n_possible_next + 1; m < qel; m++) {
1139 //Iprint3n(mcout, ind_nmax, m, sort_ind[m]);
1140 if (el[ind_nmax] < el[sort_ind[m]]) {
1141 n_possible_next = nmax;
1142 s_change_possible_next = 1;
1143 nmax = m;
1144 //Iprintn(mcout, nmax);
1145 ind_nmax = sort_ind[nmax];
1146 }
1147 }
1148 if (s_change_possible_next == 0 || n_possible_next < n + 2) {
1149 n_possible_next = n + 2;
1150 }
1151 //Iprint4n(mcout, n, sort_ind[n], ind_nmax, el[ind_nmax]);
1152 if (el[sort_ind[n]] < el[ind_nmax]) {
1153 if (s_change_possible_next == 1) {
1154 if (n_possible_next < q_to_sort &&
1155 el[sort_ind[n]] > el[sort_ind[n_possible_next]]) {
1156 n_possible_next = nmax;
1157 }
1158 }
1159 //long t = sort_ind.acu(nmin);
1160 sort_ind[nmax] = sort_ind[n];
1161 sort_ind[n] = ind_nmax;
1162 }
1163 }
1164 sort_ind.put_qel(qel);
1165}
1166
1167/*
1168template<class T>
1169void DynLinArr<T>::sort(DynLinArr< long >& sort_ind, long q_to_sort) const
1170{
1171 mfunnamep("void DynLinArr<T>::sort(DynLinArr< long >& sort_ind, long q_to_sort
1172= 0) const");
1173
1174 check_econd12(q_to_sort , > , qel , mcerr);
1175 if(q_to_sort <= 0) q_to_sort = qel;
1176 if(q_to_sort <= 1) return;
1177
1178 //if(qel <= 1) return;
1179 sort_ind.clear();
1180 sort_ind.pilfer(DynLinArr< long >(q_to_sort));
1181 long n,m;
1182 for(n=0; n<q_to_sort; n++)
1183 {
1184 sort_ind.acu(n) = n;
1185 }
1186
1187 for(n=0; n<q_to_sort-1; n++)
1188 {
1189 // first it finds the minimum along the rest and replaces if it is less
1190 long nmin = n+1;
1191 long ind_nmin = sort_ind.acu(nmin);
1192 for(m=n+2; m<q_to_sort; m++)
1193 {
1194 if(el[ind_nmin] > el[sort_ind.acu(m)])
1195 //if(el[sort_ind.acu(nmin)] > el[sort_ind.acu(m)])
1196 {
1197 nmin = m;
1198 ind_nmin = sort_ind.acu(nmin);
1199 }
1200 }
1201 if(el[sort_ind.acu(n)] > el[ind_nmin])
1202 //if(el[sort_ind.acu(n)] > el[sort_ind.acu(nmin)])
1203 {
1204 //long t = sort_ind.acu(nmin);
1205 sort_ind.acu(nmin) = sort_ind.acu(n);
1206 sort_ind.acu(n) = ind_nmin;
1207 }
1208 }
1209}
1210*/
1211
1212/*
1213template<T> void DLA_sort(DynLinArr<T>& f)
1214{
1215 mfunnamep("template<T> void DLA_sort(DynLinArr<T>& f)");
1216
1217 long q = f.get_qel();
1218 if(q <= 1) return;
1219 long n,m;
1220 T* a = &(f[0]);
1221 for(n=0; n<q-1; n++)
1222 {
1223 for(m=n+1; m<q; m++)
1224 {
1225 if(a[n] > a[m])
1226 {
1227 T t = a[m];
1228 a[m] = a[n];
1229 a[n] = t;
1230 }
1231 }
1232 }
1233}
1234*/
1235/*
1236//Somewhy this doen not work prolerly if T is template class itself
1237//AbsCont_ts.c:167: type unification failed for function template
1238//`template <class T> long int append_TreeNode(TreeNode<...> &,
1239//TreeNode<...> &, long int &, T * = 0, long int = 0)'
1240*/
1241/*
1242This is not compiled in Solaris:
1243Error: Function templates may not have default parameters.
1244*/
1245#ifndef BAN_DEFAULT_PAR_FUN_TEMPL
1246template <class T>
1247long append(const T& t, // value to assign
1248 DynLinArr<T>& dla, // array to whose elements this value is to be
1249 // assigned
1250 long& qael, //input: index of element to which it will be assigned
1251 // if qael == get_qel(), the qel will be increased
1252 // to either new_qel or by 3 times.
1253 // But if qael > get_qel(), it is considered as error.
1254 //output: the next index
1255 T* tempt = NULL, // data filled to extra elements
1256 long new_qel = 0 // recommended new size
1257 ) {
1258 if (dla.get_qel() < qael) {
1259 mcerr << "ERROR in long append(class DynLinArr& dla, ...): dla.get_qel() < "
1260 "qael\n"
1261 << "dla.get_qel()=" << dla.get_qel() << " qael=" << qael << '\n';
1262 mcerr << "Type of T is (in internal notations) " << typeid(T).name()
1263 << '\n';
1264 spexit(mcerr);
1265 }
1266 if (dla.get_qel() == qael) {
1267 if (new_qel <= qael) new_qel = find_max(3 * qael, long(3));
1268 dla.put_qel(new_qel, tempt, ArgInterp_SingleAdr());
1269 }
1270 dla[qael++] = t;
1271 return qael;
1272}
1273
1274#else
1275
1276//long append(const T& t, DynLinArr<T>& dla, long& qael,
1277// T* tempt=NULL, long new_qel=0 )
1278#define append_to_DynLinArr(t, dla, qael, tempt, new_qel) \
1279 { \
1280 if (dla.get_qel() < qael) { \
1281 mcerr << "append(class DynLinArr& dla, ...): dla.get_qel() < qael, " \
1282 << "dla.get_qel()=" << dla.get_qel() << " qael=" << qael << '\n'; \
1283 spexit(mcerr); \
1284 } \
1285 int nn = new_qel; \
1286 if (dla.get_qel() == qael) { \
1287 if (new_qel <= qael) nn = find_max(3 * qael, long(3)); \
1288 dla.put_qel(nn, tempt); \
1289 } \
1290 dla[qael++] = t; \
1291 }
1292#define append_to_DynLinArr_short(t, dla, qael) \
1293 { \
1294 if (dla.get_qel() < qael) { \
1295 mcerr << "append(class DynLinArr& dla, ...): dla.get_qel() < qael, " \
1296 << "dla.get_qel()=" << dla.get_qel() << " qael=" << qael << '\n'; \
1297 spexit(mcerr); \
1298 } \
1299 int nn = 0; \
1300 if (dla.get_qel() == qael) { \
1301 nn = find_max(3 * qael, long(3)); \
1302 dla.put_qel(nn, NULL); \
1303 } \
1304 dla[qael++] = t; \
1305 }
1306#endif
1307
1308/*
1309template<class T, int >
1310DynLinArr<T>& convert_Stat_to_Dyn(const StatLinArr<T,fqel>& fs,
1311 DynLinArr<T>& fd)
1312{
1313 fd.put_qel(fqel);
1314 long n; for( n=0; n<fqel; n++) el[n] = f[n];
1315 return fd;
1316}
1317*/
1318
1319template <class T>
1320 std::ostream& operator<<(std::ostream& file, const DynLinArr<T>& f) {
1321 //mfunnamep("template<class T> std::ostream& operator<<(std::ostream& file,
1322 //const DynLinArr<T>& f)");
1323 //mcout<<"operator<<(std::ostream& file, const DynLinArr<T>& f) is started\n";
1324 Ifile << "DynLinArr<T>: qel=" << f.get_qel() << '\n';
1325 f.check();
1326 long n;
1327 indn.n += 2;
1328 for (n = 0; n < f.get_qel(); n++) {
1329 //Ifile<<"n="<<n<<" el[n]="<<noindent<<f[n]<<yesindent<<'\n';
1330 if (s_short_output == 0) {
1331 Ifile << "n=" << n << " el[n]=";
1332 }
1333 std::ostringstream ost;
1334 ost << indn << noindent << f[n] << yesindent;
1335 put_one_n(ost);
1336 file << ost.str();
1337 }
1338 //file<<yesindent;
1339 indn.n -= 2;
1340 return file;
1341}
1342
1343#include "wcpplib/stream/definp.h"
1344
1345template <class T>
1346 std::istream& operator>>(std::istream& file, DynLinArr<T>& f) {
1347 mfunnamep(
1348 "template<class T> istream& operator>>(istream& file, DynLinArr<T>& f)");
1349 //mcout<<"operator<<(std::ostream& file, const DynLinArr<T>& f) is started\n";
1350 definp_endpar dep(&file, 0, 1, 0, s_short_output);
1351 long qel = 0;
1352 dep.s_short = 0;
1353 DEFINPAP(qel);
1354 dep.s_short = s_short_output;
1355 check_econd11(qel, < 0, mcerr);
1356 f.clear();
1357 f.put_qel(qel);
1358 long fn;
1359 for (fn = 0; fn < qel; fn++) {
1360 if (s_short_output == 0) {
1361 long n = 0;
1362 DEFINPAP(n);
1363 check_econd12(fn, !=, n, mcerr);
1364 }
1365 //set_position("el[n]=", *dep.istrm, dep.s_rewind, dep.s_req_sep);
1366 //file >> f[n];
1367 definp_any_par(f[fn], "el[n]=", dep);
1368 }
1369 return file;
1370}
1371
1372// Commented out unused function (hschindl)
1373/*
1374template<class T>
1375void output_DynLinArr(std::ostream& file, const DynLinArr<T>& f, int l, long q)
1376{
1377 //mfunnamep("template<class T> void output_DynLinArr(std::ostream& file, const
1378DynLinArr<T>& f, int l, long q)");
1379 Ifile<<"DynLinArr<T>: qel="<<f.get_qel()<<" q to print is "<<q<<'\n';
1380 f.check();
1381 if(q>f.get_qel())
1382 {
1383 mcerr<<"output_DynLinArr(...): q>f.get_qel(), q="<<q
1384 <<" f.get_qel()="<<f.get_qel()<<'\n';
1385 mcerr<<"Type of T is (in internal notations) "<<typeid(T).name()<<'\n';
1386 spexit(mcerr);
1387 }
1388 long n;
1389 indn.n+=2;
1390 for( n=0; n<q; n++)
1391 {
1392 //Ifile<<"n="<<n<<" el[n]="<<noindent<<f[n]<<yesindent<<'\n';
1393 Ifile<<"n="<<n<<" el[n]="<<noindent;
1394 std::ostringstream ost;
1395 ost<<f[n]<<yesindent;
1396 put_one_n(ost);
1397 file<<ost.str();
1398 }
1399 //file<<yesindent;
1400 indn.n-=2;
1401}
1402*/
1403
1404template <class T>
1405void print_DynLinArr(std::ostream& file, const DynLinArr<T>& f, int l) {
1406 //mfunnamep("template<class T> void print_DynLinArr(std::ostream& file, const
1407 //DynLinArr<T>& f, int l)");
1408 Ifile << "DynLinArr<T>: qel=" << f.get_qel() << '\n';
1409 f.check();
1410 long n;
1411 indn.n += 2;
1412 for (n = 0; n < f.get_qel(); n++) {
1413 //Ifile<<"n="<<n<<" el[n]="<<noindent; f[n].print(file, l);
1414 //file<<yesindent;
1415 Ifile << "n=" << n << " el[n]=" << noindent;
1416 std::ostringstream ost;
1417 f[n].print(ost, l);
1418 ost << yesindent;
1419 put_one_n(ost);
1420 file << ost.str();
1421 }
1422 indn.n -= 2;
1423}
1424/*
1425Does not work.
1426It will attempt to instantiate it even for non-class types like long etc.
1427template<class T>
1428void DynLinArr<T>::print(std::ostream& file, int l) const
1429{
1430 mfunnamep("template<class T> void DynLinArr::print(std::ostream& file, int
1431l)");
1432 Ifile<<"DynLinArr<T>: qel="<<get_qel()<<'\n';
1433 check();
1434 long n;
1435 indn.n+=2;
1436 for( n=0; n<get_qel(); n++)
1437 {
1438 Ifile<<"n="<<n<<" el[n]="<<noindent; this->operator[](n).print(file, l);
1439 file<<yesindent;
1440 }
1441 indn.n-=2;
1442}
1443*/
1444template <class T>
1445void print_DynLinArr(std::ostream& file, const DynLinArr<T>& f, int l, long q) {
1446 //mfunnamep("template<class T> void print_DynLinArr(std::ostream& file, const
1447 //DynLinArr<T>& f, int l, long q)");
1448 Ifile << "DynLinArr<T>: qel=" << f.get_qel() << " q to print is " << q
1449 << '\n';
1450 f.check();
1451 if (q > f.get_qel()) {
1452 mcerr << "print_DynLinArr(...): q>f.get_qel(), q=" << q
1453 << " f.get_qel()=" << f.get_qel() << '\n';
1454 mcerr << "Type of T is (in internal notations) " << typeid(T).name()
1455 << '\n';
1456 spexit(mcerr);
1457 }
1458 long n;
1459 indn.n += 2;
1460 for (n = 0; n < q; n++) {
1461 //Ifile<<"n="<<n<<" el[n]="<<noindent; f[n].print(file, l);
1462 //file<<yesindent;
1463 Ifile << "n=" << n << " el[n]=" << noindent;
1464 std::ostringstream ost;
1465 f[n].print(ost, l);
1466 ost << yesindent;
1467 put_one_n(ost);
1468 file << ost.str();
1469 }
1470 indn.n -= 2;
1471}
1472
1473template <class T>
1474void print_adr_DynLinArr(std::ostream& file, const DynLinArr<T>& f, int l,
1475 long q) {
1476 //mfunnamep("template<class T> void print_adr_DynLinArr(std::ostream& file,
1477 //const DynLinArr<T>& f, int l, long q)");
1478 Ifile << "DynLinArr<T>: qel=" << f.get_qel() << " q to print is " << q
1479 << '\n';
1480 f.check();
1481 if (q > f.get_qel()) {
1482 mcerr << "print_adr_DynLinArr(...): q>f.get_qel(), q=" << q
1483 << " f.get_qel()=" << f.get_qel() << '\n';
1484 mcerr << "Type of T is (in internal notations) " << typeid(T).name()
1485 << '\n';
1486 spexit(mcerr);
1487 }
1488 long n;
1489 indn.n += 2;
1490 for (n = 0; n < q; n++) {
1491 //Ifile<<"n="<<n<<" el[n]="<<noindent; f[n]->print(file, l);
1492 //file<<yesindent;
1493 Ifile << "n=" << n << " el[n]=" << noindent;
1494 std::ostringstream ost;
1495 f[n]->print(ost, l);
1496 ost << yesindent;
1497 put_one_n(ost);
1498 file << ost.str();
1499 }
1500 indn.n -= 2;
1501}
1502
1504
1505void print_DynLinArr_int(std::ostream& file, const DynLinArr<int>& f);
1506void print_DynLinArr_long(std::ostream& file, const DynLinArr<long>& f);
1507void print_DynLinArr_float(std::ostream& file, const DynLinArr<float>& f);
1508void print_DynLinArr_double(std::ostream& file, const DynLinArr<double>& f);
1509// See AbsArrD for similar function with DoubleAc
1510
1511void print_DynLinArr_double2(std::ostream& file, const DynLinArr<double>& f1,
1512 const DynLinArr<double>& f2);
1513// Print two arrays in two colums side-by-side.
1514// Good for arrays of equal dimensions.
1515
1516void print_DynLinArr_int_double(std::ostream& file, const DynLinArr<int>& iar,
1517 const DynLinArr<double>& dar);
1518
1519void print_DynLinArr_int_double3(std::ostream& file, const DynLinArr<int>& iar,
1520 const DynLinArr<double>& dar1,
1521 const DynLinArr<double>& dar2,
1522 const DynLinArr<double>& dar3);
1523// Print 4 arrays in two colums side-by-side.
1524// Good for arrays of equal dimensions.
1525
1526#define Iprintdla_int(file, name) \
1527 file << indn << #name << "=" << noindent; \
1528 print_DynLinArr_int(file, name);
1529#define Iprintdla_long(file, name) \
1530 file << indn << #name << "=" << noindent; \
1531 print_DynLinArr_long(file, name);
1532#define Iprintdla_float(file, name) \
1533 file << indn << #name << "=" << noindent; \
1534 print_DynLinArr_float(file, name);
1535#define Iprintdla_double(file, name) \
1536 file << indn << #name << "=" << noindent; \
1537 print_DynLinArr_double(file, name);
1538// See AbsArrD for similar function with DoubleAc
1539
1540template <class T, class X> void copy_DynLinArr(const T& s, X& d) {
1541 mfunnamep("template<class T, class X> void copy_DynLinArr(const T& s, X& d)");
1542 s.check();
1543 d.check();
1544 long q = s.get_qel();
1545 d.put_qel(q);
1546 long n;
1547 for (n = 0; n < q; n++) {
1548 d[n] = s[n];
1549 }
1550}
1551
1552// Covert to another compatible type
1553template <class T, class X> void convert_DynLinArr(const T& s, X& d) {
1554 long q = s.get_qel();
1555 d.put_qel(q);
1556 long n;
1557 for (n = 0; n < q; n++) {
1558 d[n] = X(s[n]);
1559 }
1560}
1561
1562template <class T>
1563void put_qel_1(DynLinArr<T>& f, long fq) // change dimensions of arrays
1564 // which are elements of the main one
1565 {
1566 long q = f.get_qel();
1567 long n;
1568 for (n = 0; n < q; n++)
1569 f[n].put_qel(fq);
1570}
1571
1572template <class T, class T1>
1573void assignAll_1(DynLinArr<T>& f, const T1& ft) // assign ft to all elements
1574 // of arrays which are elements of the main one
1575 {
1576 long q = f.get_qel();
1577 long n;
1578 for (n = 0; n < q; n++)
1579 f[n].assignAll(ft);
1580}
1581
1582template <class T> class IterDynLinArr {
1583 public:
1584 IterDynLinArr(DynLinArr<T>* fdar) : dar(fdar), ncur(-1) { ; }
1585 T* more(void) {
1586 if (ncur < dar->get_qel() - 1)
1587 return &((*dar)[++ncur]);
1588 else
1589 ncur = dar->get_qel();
1590 return NULL;
1591 }
1592 T* current(void) {
1593 if (ncur >= 0 || ncur < dar->get_qel())
1594 return &((*dar)[ncur]);
1595 else
1596 return NULL;
1597 }
1598 T* less(void) // switch current to previous
1599 {
1600 if (ncur >= 1)
1601 return &((*dar)[--ncur]);
1602 else
1603 ncur = -1;
1604 return NULL;
1605 }
1606 long get_ncur(void) { return ncur; }
1607
1608 private:
1609 long ncur;
1610 DynLinArr<T>* dar;
1611};
1612
1613int gconfirm_ind(const DynLinArr<long>& qel, const DynLinArr<long>& ind);
1614int gconfirm_ind_ext(const DynLinArr<long>& qel, const DynLinArr<long>& ind);
1615
1616// The following function checks whether the arrays or their first qfirst
1617// elements are equal.
1618// In the first case this means that their dimensions and all elements
1619// should be equal to each other.
1620// In the second case if either of the dimensions is less than qfirst,
1621// the result is negative (0), so the arrays are considered different.
1622// If the dimensions are equal or more than qfirst,
1623// the function compares that number of first elements.
1624// If to put here just equal, the program may not be compiled since
1625// instead of this function the program will insert
1626//template <class InputIterator1, class InputIterator2>
1627//inline bool equal(InputIterator1 first1, InputIterator1 last1,
1628// InputIterator2 first2) {
1629// Therefore I substituted it to ifequal.
1630template <class T>
1631int ifequal(const DynLinArr<T>& fd1, const DynLinArr<T>& fd2,
1632 long qfirst = -1) {
1633 long n;
1634 if (qfirst == -1) {
1635 if ((qfirst = fd1.get_qel()) != fd2.get_qel()) return 0;
1636 //qfirst=fd1.get_qel();
1637 } else {
1638 if (qfirst > fd1.get_qel() || qfirst > fd2.get_qel()) return 0;
1639 }
1640 //Iprintn(mcout, qfirst);
1641 for (n = 0; n < qfirst; n++) {
1642 //Iprint3n(mcout, n, fd1[n], fd2[n]);
1643 if (!(fd1[n] == fd2[n])) return 0;
1644 }
1645 return 1;
1646}
1647
1648// The same as above, but compares DynLinArr with ordinary array.
1649template <class T>
1650int ifequal(const DynLinArr<T>& fd1, const T* fd2, long qfirst = -1) {
1651 long n;
1652 if (qfirst == -1) {
1653 qfirst = fd1.get_qel();
1654 } else {
1655 if (qfirst > fd1.get_qel()) return 0;
1656 }
1657 for (n = 0; n < qfirst; n++)
1658 if (!(fd1[n] == fd2[n])) return 0;
1659 return 1;
1660}
1661
1662template <class T> int ifequal(T* fd1, T* fd2, long qfirst) {
1663 long n;
1664 for (n = 0; n < qfirst; n++)
1665 if (!(fd1[n] == fd2[n])) return 0;
1666 return 1;
1667}
1668
1669template <class T>
1670DynLinArr<T> merge(const DynLinArr<T>& fd1, long qfd1, const DynLinArr<T>& fd2,
1671 long qfd2) {
1672 long n;
1673 if (qfd1 < 0) {
1674 qfd1 = fd1.get_qel();
1675 }
1676 if (qfd2 < 0) {
1677 qfd2 = fd2.get_qel();
1678 }
1679 DynLinArr<T> ret(qfd1 + qfd2);
1680 if (qfd1 + qfd2 == 0) return ret;
1681 for (n = 0; n < qfd1; n++) {
1682 ret[n] = fd1[n];
1683 }
1684 for (n = 0; n < qfd2; n++) {
1685 ret[qfd1 + n] = fd2[n];
1686 }
1687 return ret;
1688}
1689
1690// The following might be in String.h, but String.h is included into this
1691// file, and the whole system cannot work.
1693
1694//template<class T> class IndexingProvider;
1695
1696#ifndef DONT_USE_ABSPTR
1697template <class T>
1698class DynArr : public RegPassivePtr
1699#else
1700 template <class T>
1701 class DynArr
1702#endif
1703 {
1704 public:
1705 // Constructors
1706 DynArr(void) { ; }
1707 // For one-dimensional array:
1708 explicit DynArr(long fqel, T* val = NULL)
1709 : qel(DynLinArr<long>(1)),
1710 cum_qel(DynLinArr<long>(1)),
1711 el(DynLinArr<T>(fqel)) {
1712#ifdef DEBUG_DYNARR
1713 mcout << "explicit DynArr(long fqel, T* val=NULL) is called\n";
1714#endif
1715 qel[0] = fqel;
1716 cum_qel[0] = 1;
1717 if (val != NULL) assignAll(*val);
1718 }
1719 DynArr(long fqel, T val, ArgInterp_Val /*t*/)
1720 : qel(DynLinArr<long>(1)),
1721 cum_qel(DynLinArr<long>(1)),
1722 el(DynLinArr<T>(fqel)) {
1723#ifdef DEBUG_DYNARR
1724 mcout << "explicit DynArr(long fqel, T* val=NULL) is called\n";
1725#endif
1726 qel[0] = fqel;
1727 cum_qel[0] = 1;
1728 assignAll(val);
1729 }
1730 DynArr(long fqel, const T* ar, ArgInterp_Arr /*t*/)
1731 : qel(DynLinArr<long>(1)), cum_qel(DynLinArr<long>(1)), el(fqel) {
1732 qel[0] = fqel;
1733 cum_qel[0] = 1;
1734 long n;
1735 for (n = 0; n < fqel; n++)
1736 el.acu(n) = ar[n];
1737 }
1738 // Another variant for one-dimensional array
1739 // Attention: if the T is long, this might be mixed with array of dimensions.
1740 // To avoid this the latter should be accompanied by address, see below.
1742 : qel(DynLinArr<long>(1)), cum_qel(DynLinArr<long>(1)), el(f.get_qel()) {
1743 qel[0] = f.get_qel();
1744 cum_qel[0] = 1;
1745 for (long n = 0; n < qel[0]; n++)
1746 ac(n) = f[n];
1747 }
1748
1749 // For two-dimensional array:
1750 DynArr(long fqel1, long fqel2, T* val = NULL)
1751 : qel(DynLinArr<long>(2)),
1752 cum_qel(DynLinArr<long>(2)),
1753 el(fqel1 * fqel2) {
1754#ifdef DEBUG_DYNARR
1755 mcout << "DynArr(long fqel1, long fqel2, T* val=NULL) is called\n";
1756#endif
1757 qel[0] = fqel1;
1758 qel[1] = fqel2;
1759 cum_qel[0] = fqel2;
1760 cum_qel[1] = 1;
1761 if (val != NULL) assignAll(*val);
1762 }
1763
1764 DynArr(long fqel1, long fqel2, T val, ArgInterp_Val /*t*/)
1765 : qel(DynLinArr<long>(2)),
1766 cum_qel(DynLinArr<long>(2)),
1767 el(fqel1 * fqel2) {
1768#ifdef DEBUG_DYNARR
1769 mcout
1770 << "DynArr(long fqel1, long fqel2, T val, ArgInterp_Val t) is called\n";
1771#endif
1772 qel[0] = fqel1;
1773 qel[1] = fqel2;
1774 cum_qel[0] = fqel2;
1775 cum_qel[1] = 1;
1776 assignAll(val);
1777 }
1778
1779 // For three-dimensional array:
1780 DynArr(long fqel1, long fqel2, long fqel3, T* val = NULL)
1781 : qel(DynLinArr<long>(3)),
1782 cum_qel(DynLinArr<long>(3)),
1783 el(fqel1 * fqel2 * fqel3) {
1784 qel[0] = fqel1;
1785 qel[1] = fqel2;
1786 qel[2] = fqel3;
1787 cum_qel[0] = fqel2 * fqel3;
1788 cum_qel[1] = fqel3;
1789 cum_qel[2] = 1;
1790 if (val != NULL) assignAll(*val);
1791 }
1792
1793 // For four-dimensional array:
1794 DynArr(long fqel1, long fqel2, long fqel3, long fqel4, T* val = NULL)
1795 : qel(DynLinArr<long>(4)),
1796 cum_qel(DynLinArr<long>(4)),
1797 el(fqel1 * fqel2 * fqel3 * fqel4) {
1798 qel[0] = fqel1;
1799 qel[1] = fqel2;
1800 qel[2] = fqel3;
1801 qel[3] = fqel4;
1802 cum_qel[0] = fqel2 * fqel3 * fqel4;
1803 cum_qel[1] = fqel3 * fqel4;
1804 cum_qel[2] = fqel4;
1805 cum_qel[3] = 1;
1806 if (val != NULL) assignAll(*val);
1807 }
1808
1809 // Default value is removed in order to avoid confusions with copy
1810 // constructor from DynLinArr at T = long.
1811 // If initialization of values is not necessary, just put NULL as argument.
1812 // It creates array with structure determined by fqel.
1813
1814 DynArr(const DynLinArr<long>& fqel, T val, ArgInterp_Val /*t*/) : qel(fqel) {
1815 long qdim = qel.get_qel();
1816 if (qdim <= 0) return;
1817 cum_qel.put_qel(qdim);
1818 long ndim;
1819 long size = qel[0];
1820 for (ndim = 1; ndim < qdim; ndim++)
1821 size *= qel[ndim];
1822 el.put_qel(size);
1823 cum_qel[qdim - 1] = 1;
1824 for (ndim = qdim - 2; ndim >= 0; ndim--)
1825 cum_qel[ndim] = qel[ndim + 1] * cum_qel[ndim + 1];
1826 assignAll(val);
1827 }
1828
1829 explicit DynArr(const DynLinArr<long>& fqel, T* val) : qel(fqel) {
1830 // fqel: array of dimensions
1831 // val: address of value to fill, may be NULL
1832 long qdim = qel.get_qel();
1833 if (qdim <= 0) return;
1834 cum_qel.put_qel(qdim);
1835 long ndim;
1836 long size = qel[0];
1837 for (ndim = 1; ndim < qdim; ndim++)
1838 size *= qel[ndim];
1839 el.put_qel(size);
1840 cum_qel[qdim - 1] = 1;
1841 for (ndim = qdim - 2; ndim >= 0; ndim--)
1842 cum_qel[ndim] = qel[ndim + 1] * cum_qel[ndim + 1];
1843 if (val != NULL) assignAll(*val);
1844 }
1845
1847#ifndef DONT_USE_ABSPTR
1848 : RegPassivePtr()
1849#endif
1850 {
1851#ifdef DEBUG_DYNARR
1852 mcout << "DynArr(const DynArr<T>& f) is working\n";
1853#endif
1854 *this = f;
1855 }
1857 : qel(f.qel, steal), cum_qel(f.cum_qel, steal), el(f.el, steal) {
1858#ifdef DEBUG_DYNARR
1859 mcout << "DynArr( DynArr<T>& f, Pilfer) is working\n";
1860#endif
1861 }
1862
1864#ifdef DEBUG_DYNARR
1865 mcout << "DynArr::pilfer is called\n";
1866#endif
1867 if (this != &f) {
1868 if (qel.get_qel() != 0) {
1869 if (f.qel.get_qel() != 0) {
1870 mcerr << "ERROR in DynArr::pilfer(...):\n";
1871 mcerr << "Both the destination and source arrays are not empty\n";
1872 // For explanations why it is dangerous, see similar function
1873 // of ActivePtr.
1874 spexit(mcerr);
1875 } else {
1876 qel.clear();
1877 cum_qel.clear();
1878 el.clear();
1879 }
1880 }
1881 qel.pilfer(f.qel);
1882 cum_qel.pilfer(f.cum_qel);
1883 el.pilfer(f.el);
1884 f.qel.clear();
1885 f.cum_qel.clear();
1886 f.el.clear();
1887 }
1888 }
1889
1891 template <class D> DynArr<T>& operator=(const DynArr<D>& f);
1892
1893 void pass(long q, DynLinArr<long> fqel, DynLinArr<long> fcum_qel, T* fel)
1894 // Do not call directly! Is to be used only
1895 // from assignment operator above
1896 {
1897 clear();
1898 qel = fqel;
1899 cum_qel = fcum_qel;
1900 el.pass(q, fel);
1901 }
1902
1903 // Auxiliary class that provides indexing through ordinary way
1904 // It is perhaps quite slow.
1905 template <class D> class IndexingProvider {
1906 public:
1908 mutable long q_deref_ind;
1909 mutable long current_pos;
1910 IndexingProvider(DynArr<D>& farr, long fq_deref_ind, long fcurrent_pos)
1911 : arr(farr), q_deref_ind(fq_deref_ind), current_pos(fcurrent_pos) {}
1912 operator D&() const {
1913 if (q_deref_ind != arr.qel.get_qel()) {
1914 mcerr << "ERROR in IndexingProvider::operator D& (): q_deref_ind != "
1915 "qel.get_qel()\n";
1917 mcerr << "Type of T is (in internal notations) " << typeid(D).name()
1918 << '\n';
1919 spexit(mcerr);
1920 }
1921#ifdef ALR_CHECK_BOUND
1922 return arr.el[current_pos];
1923#else
1924 return arr.el.acu(current_pos);
1925#endif
1926 }
1927 D& operator=(const D& f) {
1928 if (q_deref_ind != arr.get_qel().get_qel()) {
1929 mcerr << "ERROR in T& IndexingProvider::operator=(T& f): q_deref_ind "
1930 "!= arr.get_qel().get_qel()\n";
1932 mcerr << "Type of T is (in internal notations) " << typeid(D).name()
1933 << '\n';
1934 spexit(mcerr);
1935 }
1936#ifdef ALR_CHECK_BOUND
1937 arr.ac_lin(current_pos) = f;
1938#else
1939 arr.acu_lin(current_pos) = f;
1940#endif
1941 //return arr.el[current_pos];
1942 }
1943
1945 if (q_deref_ind >= arr.get_qel().get_qel()) {
1946 mcerr << "ERROR in DynArr::IndexingProvider& DynArr::operator[](long "
1947 "n): q_deref_ind >= arr.get_qel().get_qel()\n";
1949 mcerr << "Type of T is (in internal notations) " << typeid(D).name()
1950 << '\n';
1951 spexit(mcerr);
1952 }
1953#ifdef ALR_CHECK_EACH_BOUND
1954 if (n >= 0 && n < arr.qel.acu(q_deref_ind)) {
1955#endif
1957 q_deref_ind++;
1958 return *this;
1959#ifdef ALR_CHECK_EACH_BOUND
1960 } else {
1961 mcerr << "Error in IndexingProvider<D>& "
1962 "IndexingProvider::operator[](long n): n < 0 || n >= "
1963 "qel.acu(q_deref_ind)\n";
1964 Iprint2n(mcout, n, arr.qel.acu(q_deref_ind));
1965 mcerr << "Type of T is (in internal notations) " << typeid(T).name()
1966 << '\n';
1967 spexit(mcerr);
1968 }
1969#endif
1970 }
1971
1972 inline const IndexingProvider<D>& operator[](long n) const {
1973 if (q_deref_ind >= arr.get_qel().get_qel()) {
1974 mcerr << "ERROR in DynArr::IndexingProvider& DynArr::operator[](long "
1975 "n): q_deref_ind >= arr.get_qel().get_qel()\n";
1977 mcerr << "Type of T is (in internal notations) " << typeid(D).name()
1978 << '\n';
1979 spexit(mcerr);
1980 }
1981#ifdef ALR_CHECK_EACH_BOUND
1982 if (n >= 0 && n < arr.qel.acu(q_deref_ind)) {
1983#endif
1985 q_deref_ind++;
1986 return *this;
1987#ifdef ALR_CHECK_EACH_BOUND
1988 } else {
1989 mcerr << "Error in IndexingProvider<D>& "
1990 "IndexingProvider::operator[](long n): n < 0 || n >= "
1991 "qel.acu(q_deref_ind)\n";
1992 Iprint2n(mcout, n, arr.qel.acu(q_deref_ind));
1993 mcerr << "Type of T is (in internal notations) " << typeid(T).name()
1994 << '\n';
1995 spexit(mcerr);
1996 }
1997#endif
1998 }
1999
2000 };
2001
2002 // This operator can be used to provide ordinary indexing [][][]... .
2003 // It is perhaps quite slow compared with ac() functions.
2004 // It is provided only for the use in contexts in which [][][]...
2005 // is needed.
2007 if (qel.get_qel() < 1) {
2008 mcerr << "ERROR in DynArr::IndexingProvider DynArr::operator[](long n): "
2009 "qel.get_qel()< 1, qel.get_qel()=" << qel.get_qel() << '\n';
2010 mcerr << "Type of T is (in internal notations) " << typeid(T).name()
2011 << '\n';
2012 spexit(mcerr);
2013 }
2014#ifdef ALR_CHECK_EACH_BOUND
2015 if (n >= 0 && n < qel.acu(0)) {
2016#endif
2017 return IndexingProvider<T>(*this, 1, n * cum_qel.acu(0));
2018#ifdef ALR_CHECK_EACH_BOUND
2019 } else {
2020 mcerr << "Error in IndexingProvider<T> DynArr::operator[](long n): n < 0 "
2021 "|| n >= qel.acu(0)\n";
2022 Iprint2n(mcout, n, qel.acu(0));
2023 mcerr << "Type of T is (in internal notations) " << typeid(T).name()
2024 << '\n';
2025 spexit(mcerr);
2026 }
2027#endif
2028 }
2029
2030 inline const IndexingProvider<T> operator[](long n) const {
2031 if (qel.get_qel() < 1) {
2032 mcerr << "ERROR in DynArr::IndexingProvider DynArr::operator[](long n): "
2033 "qel.get_qel()< 1, qel.get_qel()=" << qel.get_qel() << '\n';
2034 mcerr << "Type of T is (in internal notations) " << typeid(T).name()
2035 << '\n';
2036 spexit(mcerr);
2037 }
2038#ifdef ALR_CHECK_EACH_BOUND
2039 if (n >= 0 && n < qel.acu(0)) {
2040#endif
2041 //DynArr<T>* temp = static_cast<DynArr<T>* >(this);
2042 DynArr<T>* temp = const_cast<DynArr<T>*>(this);
2043 // static_cast<const IndexingProvider<T> >(*this);
2044 return IndexingProvider<T>(*temp, 1, n * cum_qel.acu(0));
2045#ifdef ALR_CHECK_EACH_BOUND
2046 } else {
2047 mcerr << "Error in IndexingProvider<T> DynArr::operator[](long n): n < 0 "
2048 "|| n >= qel.acu(0)\n";
2049 Iprint2n(mcout, n, qel.acu(0));
2050 mcerr << "Type of T is (in internal notations) " << typeid(T).name()
2051 << '\n';
2052 spexit(mcerr);
2053 }
2054#endif
2055 }
2056
2057 T& ac(long i) // for 1-dimensional array
2058 {
2059 if (qel.get_qel() == 1)
2060 return el[i];
2061 else {
2062 mcerr << "ERROR in DynArr::ac(long i): qel.get_qel()!= 1, qel.get_qel()="
2063 << qel.get_qel() << '\n';
2064 mcerr << "Type of T is (in internal notations) " << typeid(T).name()
2065 << '\n';
2066 spexit(mcerr);
2067#ifdef INS_CRETURN // Insert calming return
2068 return el[0]; // to quiet Microsoft Visual Studio compiler against
2069 // "not all control paths return a value"
2070#endif
2071 }
2072 //return el[i];
2073 }
2074 const T& ac(long i) const // for 1-dimensional array
2075 {
2076 if (qel.get_qel() == 1)
2077 return el[i];
2078 else {
2079 mcerr << "ERROR in DynArr::ac(long i): qel.get_qel()!= 1, qel.get_qel()="
2080 << qel.get_qel() << '\n';
2081 mcerr << "Type of T is (in internal notations) " << typeid(T).name()
2082 << '\n';
2083 spexit(mcerr);
2084#ifdef INS_CRETURN // Insert calming return
2085 return el[0]; // to quiet Microsoft Visual Studio compiler against
2086 // "not all control paths return a value"
2087#endif
2088 }
2089 /*
2090 if(qel.get_qel() != 1)
2091 { mcerr<<"ERROR in DynArr::ac(long i): qel.get_qel()!= 1, qel.get_qel()="
2092 <<qel.get_qel()<<'\n';
2093 mcerr<<"Type of T is (in internal notations) "<<typeid(T).name()<<'\n';
2094 spexit(mcerr); }
2095 return el[i];
2096 */
2097 }
2098 inline T& acu(long i1) // for 1-dimensional array, completely unchecked
2099 {
2100 return el.acu(i1);
2101 }
2102 inline const T& acu(
2103 long i1) const // for 1-dimensional array, completely unchecked
2104 {
2105 return el.acu(i1);
2106 }
2107
2108 T& ac(const DynLinArr<long>& ind) // for arbitrary number of dimensions
2109 // but the number of them in array should be equal to size of ind.
2110 // ind is array of indexes. Its first element if the first index,
2111 // second is second, etc.
2112 {
2113 long q;
2114 if ((q = qel.get_qel()) != ind.get_qel()) {
2115 mcerr << "ERROR in DynArr::ac(const DynLinArr<long>& ind): "
2116 << "qel.get_qel()!= ind.get_qel()\n"
2117 << "qel.get_qel()=" << qel.get_qel()
2118 << " ind.get_qel()=" << ind.get_qel() << '\n';
2119 mcerr << "Type of T is (in internal notations) " << typeid(T).name()
2120 << '\n';
2121 spexit(mcerr);
2122 }
2123#ifdef ALR_CHECK_EACH_BOUND
2124#ifdef DEBUG_DYNARR
2125 if (q == 1) // faster for this case
2126 return el[ind.acu(0)];
2127 else
2128 return el[calc_lin_ind(ind)];
2129#else
2130 if (q == 1)
2131 return el[ind.acu(0)];
2132 else
2133 return el.acu(calc_lin_ind(ind));
2134#endif
2135#else
2136 if (q == 1)
2137 return el[ind.acu(0)];
2138 else
2139 return el[calc_lin_ind(ind)];
2140#endif
2141 }
2142 const T& ac(const DynLinArr<long>& ind) const // the same as above
2143 {
2144 long q;
2145 if ((q = qel.get_qel()) != ind.get_qel()) {
2146 mcerr << "ERROR in DynArr::ac(const DynLinArr<long>& ind): "
2147 << "qel.get_qel()!= ind.get_qel()\n"
2148 << "qel.get_qel()=" << qel.get_qel()
2149 << " ind.get_qel()=" << ind.get_qel() << '\n';
2150 mcerr << "Type of T is (in internal notations) " << typeid(T).name()
2151 << '\n';
2152 spexit(mcerr);
2153 }
2154/*
2155#ifdef ALR_CHECK_EACH_BOUND
2156#ifdef DEBUG_DYNARR
2157 return el[calc_lin_ind(ind)];
2158#else
2159 return el.acu(calc_lin_ind(ind));
2160#endif
2161#else
2162 return el[calc_lin_ind(ind)];
2163#endif
2164 //return el[calc_lin_ind(ind)];
2165 */
2166
2167#ifdef ALR_CHECK_EACH_BOUND
2168#ifdef DEBUG_DYNARR
2169 if (q == 1) // faster for this case
2170 return el[ind.acu(0)];
2171 else
2172 return el[calc_lin_ind(ind)];
2173#else
2174 if (q == 1)
2175 return el[ind.acu(0)];
2176 else
2177 return el.acu(calc_lin_ind(ind));
2178#endif
2179#else
2180 if (q == 1)
2181 return el[ind.acu(0)];
2182 else
2183 return el[calc_lin_ind(ind)];
2184#endif
2185 }
2186
2187 T& acp(const DynLinArr<long>& ind) // the same as above, but
2188 // the size of ind can be more than the number of indexes
2189 // (the rest is unused)
2190 {
2191 long q;
2192 if ((q = qel.get_qel()) > ind.get_qel()) {
2193 mcerr << "ERROR in DynArr::acp(const DynLinArr<long>& ind): "
2194 << "qel.get_qel()!= ind.get_qel()\n"
2195 << "qel.get_qel()=" << qel.get_qel()
2196 << " ind.get_qel()=" << ind.get_qel() << '\n';
2197 mcerr << "Type of T is (in internal notations) " << typeid(T).name()
2198 << '\n';
2199 spexit(mcerr);
2200 }
2201
2202#ifdef ALR_CHECK_EACH_BOUND
2203#ifdef DEBUG_DYNARR
2204 if (q == 1) // faster for this case
2205 return el[ind.acu(0)];
2206 else
2207 return el[calc_lin_ind(ind)];
2208#else
2209 if (q == 1)
2210 return el[ind.acu(0)];
2211 else
2212 return el.acu(calc_lin_ind(ind));
2213#endif
2214#else
2215 if (q == 1)
2216 return el[ind.acu(0)];
2217 else
2218 return el[calc_lin_ind(ind)];
2219#endif
2220 }
2221
2222 const T& acp(const DynLinArr<long>& ind) const {
2223 long q;
2224 if ((q = qel.get_qel()) > ind.get_qel()) {
2225 mcerr << "ERROR in DynArr::acp(const DynLinArr<long>& ind): "
2226 << "qel.get_qel()!= ind.get_qel()\n"
2227 << "qel.get_qel()=" << qel.get_qel()
2228 << " ind.get_qel()=" << ind.get_qel() << '\n';
2229 mcerr << "Type of T is (in internal notations) " << typeid(T).name()
2230 << '\n';
2231 spexit(mcerr);
2232 }
2233#ifdef ALR_CHECK_EACH_BOUND
2234#ifdef DEBUG_DYNARR
2235 if (q == 1) // faster for this case
2236 return el[ind.acu(0)];
2237 else
2238 return el[calc_lin_ind(ind)];
2239#else
2240 if (q == 1)
2241 return el[ind.acu(0)];
2242 else
2243 return el.acu(calc_lin_ind(ind));
2244#endif
2245#else
2246 if (q == 1)
2247 return el[ind.acu(0)];
2248 else
2249 return el[calc_lin_ind(ind)];
2250#endif
2251 }
2252
2253 T& acu(const DynLinArr<long>& ind) // unchecked
2254 {
2255 if (qel.get_qel() == 1)
2256 return el.acu(ind.acu(0));
2257 else
2258 return el.acu(calc_lin_ind(ind));
2259 }
2260 const T& acu(const DynLinArr<long>& ind) const // unchecked
2261 {
2262 if (qel.get_qel() == 1)
2263 return el.acu(ind.acu(0));
2264 else
2265 return el.acu(calc_lin_ind(ind));
2266 }
2267
2268 T& ac(long i1, long i2) // for 2-dimensional array
2269 {
2270 if (qel.get_qel() == 2) {
2271#ifdef ALR_CHECK_EACH_BOUND
2272 if (i1 >= 0 && i1 < qel.acu(0)) {
2273 if (i2 >= 0 && i2 < qel.acu(1)) {
2274#ifdef DEBUG_DYNARR
2275 return el[i1 * cum_qel.acu(0) + i2];
2276#else
2277 return el.acu(i1 * cum_qel.acu(0) + i2);
2278#endif
2279 } else {
2280 mcerr << "Error in DynArr::ac(long i1, long i2): i2 < 0 || i2 >= "
2281 "qel.acu(1)\n";
2282 Iprint2n(mcout, i2, qel[1]);
2283 }
2284 } else {
2285 mcerr << "Error in DynArr::ac(long i1, long i2): i1 < 0 || i1 >= "
2286 "qel.acu(0)\n";
2287 Iprint2n(mcout, i1, qel[0]);
2288 }
2289 } else {
2290 mcerr << "ERROR in DynArr::ac(long i1, long i2): qel.get_qel()!= 2,"
2291 << " qel.get_qel()=" << qel.get_qel() << '\n';
2292 }
2293 mcerr << "Type of T is (in internal notations) " << typeid(T).name()
2294 << '\n';
2295 spexit(mcerr);
2296#ifdef INS_CRETURN // Insert calming return
2297 return el[0]; // to quiet Microsoft Visual Studio compiler against
2298 // "not all control paths return a value"
2299#endif
2300#else // for ifdef ALR_CHECK_EACH_BOUND
2301 return el[i1 * cum_qel.acu(0) + i2];
2302
2303#endif
2304 }
2305
2306 /*
2307 {
2308 if(qel.get_qel() != 2)
2309 { mcerr<<"ERROR in DynArr::ac(long i1, long i2): qel.get_qel()!= 2,"
2310 <<" qel.get_qel()=" <<qel.get_qel()<<'\n';
2311 mcerr<<"Type of T is (in internal notations) "<<typeid(T).name()<<'\n';
2312 spexit(mcerr); }
2313#ifdef ALR_CHECK_EACH_BOUND
2314 if(i1 < 0 || i1 >= qel.acu(0))
2315 {
2316 mcerr<<"Error in DynArr::ac(long i1, long i2): i1 < 0 || i1 >=
2317qel.acu(0)\n";
2318 Iprint2n(mcout, i1, qel[0]);
2319 spexit(mcerr);
2320 }
2321 if(i2 < 0 || i2 >= qel.acu(1))
2322 {
2323 mcerr<<"Error in DynArr::ac(long i1, long i2): i2 < 0 || i2 >=
2324qel.acu(1)\n";
2325 Iprint2n(mcout, i2, qel[1]);
2326 spexit(mcerr);
2327 }
2328#ifdef DEBUG_DYNARR
2329 return el[i1*cum_qel.acu(0) + i2];
2330#else
2331 return el.acu(i1*cum_qel.acu(0) + i2);
2332#endif
2333#else
2334 return el[i1*cum_qel.acu(0) + i2];
2335#endif
2336 }
2337 */
2338 const T& ac(long i1, long i2) const // for 2-dimensional array
2339 {
2340 if (qel.get_qel() == 2) {
2341#ifdef ALR_CHECK_EACH_BOUND
2342 if (i1 >= 0 && i1 < qel.acu(0)) {
2343 if (i2 >= 0 && i2 < qel.acu(1)) {
2344#ifdef DEBUG_DYNARR
2345 return el[i1 * cum_qel.acu(0) + i2];
2346#else
2347 return el.acu(i1 * cum_qel.acu(0) + i2);
2348#endif
2349 } else {
2350 mcerr << "Error in DynArr::ac(long i1, long i2): i2 < 0 || i2 >= "
2351 "qel.acu(1)\n";
2352 Iprint2n(mcout, i2, qel[1]);
2353 }
2354 } else {
2355 mcerr << "Error in DynArr::ac(long i1, long i2): i1 < 0 || i1 >= "
2356 "qel.acu(0)\n";
2357 Iprint2n(mcout, i1, qel[0]);
2358 }
2359 } else {
2360 mcerr << "ERROR in DynArr::ac(long i1, long i2): qel.get_qel()!= 2,"
2361 << " qel.get_qel()=" << qel.get_qel() << '\n';
2362 }
2363 mcerr << "Type of T is (in internal notations) " << typeid(T).name()
2364 << '\n';
2365 spexit(mcerr);
2366#ifdef INS_CRETURN // Insert calming return
2367 return el[0]; // to quiet Microsoft Visual Studio compiler against
2368 // "not all control paths return a value"
2369#endif
2370#else // for ifdef ALR_CHECK_EACH_BOUND
2371 return el[i1 * cum_qel.acu(0) + i2];
2372
2373#endif
2374 }
2375 /*
2376 {
2377 if(qel.get_qel() != 2)
2378 { mcerr<<"ERROR in DynArr::ac(long i1, long i2): qel.get_qel()!= 2,"
2379 <<" qel.get_qel()=" <<qel.get_qel()<<'\n';
2380 mcerr<<"Type of T is (in internal notations) "<<typeid(T).name()<<'\n';
2381 spexit(mcerr); }
2382#ifdef ALR_CHECK_EACH_BOUND
2383 if(i1 < 0 || i1 >= qel.acu(0))
2384 {
2385 mcerr<<"Error in DynArr::ac(long i1, long i2): i1 < 0 || i1 >=
2386qel.acu(0)\n";
2387 Iprint2n(mcout, i1, qel[0]);
2388 spexit(mcerr);
2389 }
2390 if(i2 < 0 || i2 >= qel.acu(1))
2391 {
2392 mcerr<<"Error in DynArr::ac(long i1, long i2): i2 < 0 || i2 >=
2393qel.acu(1)\n";
2394 Iprint2n(mcout, i2, qel[1]);
2395 spexit(mcerr);
2396 }
2397#ifdef DEBUG_DYNARR
2398 return el.acu(i1*cum_qel.acu(0) + i2);
2399#else
2400 return el[i1*cum_qel.acu(0) + i2];
2401#endif
2402#else
2403 return el[i1*cum_qel.acu(0) + i2];
2404#endif
2405 //return el[i1*cum_qel[0] + i2];
2406 }
2407 */
2408 inline T& acu(long i1,
2409 long i2) // for 2-dimensional array, completely unchecked
2410 {
2411 return el.acu(i1 * cum_qel.acu(0) + i2);
2412 }
2413 inline const T& acu(long i1, long i2) const // for 2-dimensional array
2414 {
2415 return el.acu(i1 * cum_qel.acu(0) + i2);
2416 }
2417
2418 T& ac(long i1, long i2, long i3) // for 3-dimensional array
2419 {
2420 if (qel.get_qel() != 3) {
2421 mcerr << "ERROR in DynArr::ac(long i1, long i2, long i3): "
2422 "qel.get_qel()!= 3,"
2423 << " qel.get_qel()=" << qel.get_qel() << '\n';
2424 mcerr << "Type of T is (in internal notations) " << typeid(T).name()
2425 << '\n';
2426 spexit(mcerr);
2427 }
2428#ifdef ALR_CHECK_EACH_BOUND
2429 if (i1 < 0 || i1 >= qel.acu(0)) {
2430 mcerr << "Error in DynArr::ac(long i1, long i2, long i3): i1 < 0 || i1 "
2431 ">= qel.acu(0)\n";
2432 Iprint2n(mcout, i1, qel[0]);
2433 spexit(mcerr);
2434 }
2435 if (i2 < 0 || i2 >= qel.acu(1)) {
2436 mcerr << "Error in DynArr::ac(long i1, long i2, long i3): i2 < 0 || i2 "
2437 ">= qel.acu(1)\n";
2438 Iprint2n(mcout, i2, qel[1]);
2439 spexit(mcerr);
2440 }
2441 if (i3 < 0 || i3 >= qel.acu(2)) {
2442 mcerr << "Error in DynArr::ac(long i1, long i2, long i3): i3 < 0 || i3 "
2443 ">= qel.acu(2)\n";
2444 Iprint2n(mcout, i3, qel[2]);
2445 spexit(mcerr);
2446 }
2447#ifdef DEBUG_DYNARR
2448 return el.acu(i1 * cum_qel.acu(0) + i2 * cum_qel.acu(1) + i3);
2449#else
2450 return el[i1 * cum_qel.acu(0) + i2 * cum_qel[1] + i3];
2451#endif
2452#else
2453 return el[i1 * cum_qel.acu(0) + i2 * cum_qel[1] + i3];
2454#endif
2455 //return el[i1*cum_qel[0] + i2*cum_qel[1] + i3];
2456 }
2457
2458 const T& ac(long i1, long i2, long i3) const // for 3-dimensional array
2459 {
2460 if (qel.get_qel() != 3) {
2461 mcerr << "ERROR in DynArr::ac(long i1, long i2, long i3): "
2462 "qel.get_qel()!= 3,"
2463 << " qel.get_qel()=" << qel.get_qel() << '\n';
2464 mcerr << "Type of T is (in internal notations) " << typeid(T).name()
2465 << '\n';
2466 spexit(mcerr);
2467 }
2468#ifdef ALR_CHECK_EACH_BOUND
2469 if (i1 < 0 || i1 >= qel.acu(0)) {
2470 mcerr << "Error in DynArr::ac(long i1, long i2, long i3): i1 < 0 || i1 "
2471 ">= qel.acu(0)\n";
2472 Iprint2n(mcout, i1, qel[0]);
2473 spexit(mcerr);
2474 }
2475 if (i2 < 0 || i2 >= qel.acu(1)) {
2476 mcerr << "Error in DynArr::ac(long i1, long i2, long i3): i2 < 0 || i2 "
2477 ">= qel.acu(1)\n";
2478 Iprint2n(mcout, i2, qel[1]);
2479 spexit(mcerr);
2480 }
2481 if (i3 < 0 || i3 >= qel.acu(2)) {
2482 mcerr << "Error in DynArr::ac(long i1, long i2, long i3): i3 < 0 || i3 "
2483 ">= qel.acu(2)\n";
2484 Iprint2n(mcout, i3, qel[2]);
2485 spexit(mcerr);
2486 }
2487#ifdef DEBUG_DYNARR
2488 return el.acu(i1 * cum_qel.acu(0) + i2 * cum_qel.acu(1) + i3);
2489#else
2490 return el[i1 * cum_qel.acu(0) + i2 * cum_qel[1] + i3];
2491#endif
2492#else
2493 return el[i1 * cum_qel.acu(0) + i2 * cum_qel[1] + i3];
2494#endif
2495 //return el[i1*cum_qel[0] + i2*cum_qel[1] + i3];
2496 }
2497
2498 long get_qel_lin(void) const { return el.get_qel(); }
2499
2500 // access to array as linear array
2501 inline T& ac_lin(long n) {
2502 long qelln = el.get_qel();
2503#ifdef ALR_CHECK_BOUND
2504 if (n >= 0 && n < qelln) {
2505 return el[n];
2506 } else {
2507 mcerr << "ERROR in T& DynArr::ac_lin(long n): "
2508 << "n is out of bounds, n=" << n << " qelln=" << qelln << '\n';
2509 mcerr << "Type of T is (in internal notations) " << typeid(T).name()
2510 << '\n';
2511 spexit(mcerr);
2512#ifdef INS_CRETURN
2513 return el[0]; // to quiet Microsoft Visial Studio compiler against
2514 // "not all control paths return a value"
2515#endif
2516 }
2517#else
2518 return el[n];
2519#endif
2520 }
2521 inline const T& ac_lin(long n) const {
2522 long qelln = el.get_qel();
2523#ifdef ALR_CHECK_BOUND
2524 if (n >= 0 && n < qelln) {
2525 return el[n];
2526 } else {
2527 mcerr << "ERROR in T& DynArr::ac_lin(long n): "
2528 << "n is out of bounds, n=" << n << " qelln=" << qelln << '\n';
2529 mcerr << "Type of T is (in internal notations) " << typeid(T).name()
2530 << '\n';
2531 spexit(mcerr);
2532#ifdef INS_CRETURN
2533 return el[0]; // to quiet Microsoft Visial Studio compiler against
2534 // "not all control paths return a value"
2535#endif
2536 }
2537#else
2538 return el[n];
2539#endif
2540 }
2541 // access to array as linear array always without check
2542 inline T& acu_lin(long n) { return el[n]; }
2543 inline const T& acu_lin(long n) const { return el[n]; }
2544
2545 void assignAll(const T& val);
2546
2547 long get_qdim(void) const { return qel.get_qel(); }
2548 const DynLinArr<long>& get_qel(void) const { return qel; }
2549 const DynLinArr<T>& get_el(void) const { return el; }
2550
2551 // The following is mainly for debug (diagnostic print):
2552 const DynLinArr<long>& get_cum_qel(void) const { return cum_qel; }
2553
2554 //void put_qel(const DynLinArr<long>& fqel, T* val=NULL);
2555 void put_qel(T* val = NULL);
2556 // 25.10.2006: Today I do not understand these following comments.
2557 // They looks like simple copy from these in DynLinArr.
2558 // creates array with size fqel
2559 // If old array existed, then
2560 // If it was less than fqel, it all is copied to new array
2561 // and the other elements are either remains not inited
2562 // or assignned *val.
2563 // else its fqel part is copyed to new array.
2564
2565 void clear(void) {
2566 qel.clear();
2567 cum_qel.clear();
2568 el.clear();
2569 }
2570
2571 int confirm_ind(const DynLinArr<long>& ind) { return gconfirm_ind(qel, ind); }
2573 return gconfirm_ind_ext(qel, ind);
2574 }
2576
2577 // Apply any function of one argument (of type T) to each element.
2578 template <class P> friend void apply1(DynArr<P>& ar, void (*fun)(P& f));
2579
2580 // Apply any function of two arguments
2581 // (first of which is of type T and the second is of type of address
2582 // of another function (possibly apply1) to each element.
2583 template <class P, class X>
2584 friend void apply2(DynArr<P>& ar, void (*fun1)(P& f, void (*fun21)(X& f)),
2585 void (*fun2)(X& f));
2586
2587 void check(void) const {
2588 qel.check();
2589 cum_qel.check();
2590 el.check();
2591 }
2592 int get_s_non_emplty(void) const {
2593 long q = qel.get_qel();
2594 if (q == 0) return 0;
2595 long n;
2596 for (n = 0; n < q; n++) {
2597 if (qel[n] <= 0) return 0;
2598 }
2599 return 1;
2600 }
2601#ifndef DONT_USE_ABSPTR
2603#endif
2604 virtual ~DynArr(void) {}
2605
2606 private:
2608 // Linear array with number of elements by each dimension
2610 // "cumulative qel": each element contains product
2611 // of next elements of qel.
2612 // The last element is always 1.
2613 // Used for fast search of proper element in el.
2614
2616 // Contains all elements.
2617 // The last index varies faster.
2618
2619 long calc_lin_ind(const DynLinArr<long>& ind) const {
2620 long i = 0;
2621 long n;
2622 long qdim1 = qel.get_qel() - 1;
2623 /*
2624 // This check is not necessary by two reasons
2625 // 1. The checks of this condition are made in calling functions.
2626 // 2. The correct condition is not != but >.
2627 if(qdim1 != ind.get_qel() - 1)
2628 {
2629 mcerr<<"ERROR in long DynArr::calc_lin_ind(const DynLinArr<long>& ind)
2630const\n";
2631 mcerr<<"qdim1 != ind.get_qel() - 1\n";
2632 Iprint2n(mcerr, qdim1, (ind.get_qel() - 1));
2633 spexit(mcerr);
2634 }
2635 */
2636 for (n = 0; n < qdim1; n++) {
2637#ifdef ALR_CHECK_EACH_BOUND
2638#ifdef DEBUG_DYNARR
2639 if (ind[n] < 0 || ind[n] >= qel[n]) {
2640 mcerr << "ERROR in long DynArr::calc_lin_ind(const DynLinArr<long>& "
2641 "ind) const\n";
2642 mcerr << "ind[n] < 0 || ind[n] >= qel[n]\n";
2643 Iprint3n(mcout, n, ind[n], qel[n]);
2644 Iprintn(mcout, qel);
2645 spexit(mcerr);
2646 }
2647#else
2648 if (ind.acu(n) < 0 || ind.acu(n) >= qel.acu(n)) {
2649 mcerr << "ERROR in long DynArr::calc_lin_ind(const DynLinArr<long>& "
2650 "ind) const\n";
2651 mcerr << "ind.acu(n) < 0 || ind.acu(n) >= qel.acu(n)\n";
2652 Iprint3n(mcout, n, ind[n], qel[n]);
2653 Iprintn(mcout, qel);
2654 spexit(mcerr);
2655 }
2656#endif
2657#endif
2658 i += ind[n] * cum_qel[n];
2659 }
2660#ifdef ALR_CHECK_EACH_BOUND
2661#ifdef DEBUG_DYNARR
2662 if (ind[qdim1] < 0 || ind[qdim1] >= qel[qdim1]) {
2663 mcerr << "ERROR in long DynArr::calc_lin_ind(const DynLinArr<long>& ind) "
2664 "const\n";
2665 mcerr << "ind[qdim1] < 0 || ind[qdim1] >= qel[qdim1]\n";
2666 Iprint3n(mcout, n, ind[qdim1], qel[qdim1]);
2667 Iprintn(mcout, qel);
2668 spexit(mcerr);
2669 }
2670#else
2671 if (ind.acu(qdim1) < 0 || ind.acu(qdim1) >= qel.acu(qdim1)) {
2672 mcerr << "ERROR in long DynArr::calc_lin_ind(const DynLinArr<long>& ind) "
2673 "const\n";
2674 mcerr << "ind.acu(qdim1) < 0 || ind.acu(qdim1) >= qel.acu(qdim1)\n";
2675 Iprint3n(mcout, n, ind[qdim1], qel[qdim1]);
2676 Iprintn(mcout, qel);
2677 spexit(mcerr);
2678 }
2679#endif
2680#endif
2681 i += ind[qdim1]; // the last index, for which multiplication by cum_qel
2682 // is not necessary.
2683 return i;
2684 }
2685#ifdef USE_REPLACE_ALLOC
2687#endif
2688
2689};
2690
2691template <class T> DynArr<T>& DynArr<T>::operator=(const DynArr<T>& f) {
2692#ifdef DEBUG_DYNARR
2693 mcout << "DynArr<T>& DynArr<T>::operator=(const DynArr<T>& f)\n";
2694#endif
2695 if (this != &f) {
2696 //mcout<<"DynLinArr<T>& operator=(const DynLinArr<T>& f): long(el)="
2697 //<<long(el)<<'\n';
2698 check();
2699 f.check();
2700 qel = f.qel;
2701 cum_qel = f.cum_qel;
2702 el = f.el;
2703 }
2704 return *this;
2705}
2706
2707template <class T>
2708template <class D>
2710#ifdef DEBUG_DYNLINARR
2711 mcout << "DynArr<T>& DynArr<T>::operator=(const DynArr<D>& f)\n";
2712#endif
2713 //if(this != &f)
2714 //{
2715 //mcout<<"DynLinArr<T>& operator=(const DynLinArr<T>& f): long(el)="
2716 //<<long(el)<<'\n';
2717 check();
2718 f.check();
2719 DynLinArr<long> qel = f.get_qel();
2720 DynLinArr<long> cum_qel = f.get_cum_qel();
2721 // for example, one of its elements.
2722 long q = f.get_qel_lin();
2723#ifdef USE_REPLACE_ALLOC
2724 T* temp_el;
2725 if (q > 0) {
2726 temp_el = (T*)malloc(sizeof(T) * q);
2727 long n;
2728 for (n = 0; n < q; n++)
2729 new (&(temp_el[n])) T;
2730 } else
2731 temp_el = NULL;
2732#else
2733 T* temp_el = (q > 0) ? (new T[q]) : (T*)NULL;
2734#endif
2735 long n;
2736 for (n = 0; n < q; n++)
2737 temp_el[n] = f.acu_lin(n);
2738 pass(q, qel, cum_qel, temp_el);
2739 //}
2740 return *this;
2741}
2742
2743template <class T> void apply1(DynArr<T>& ar, void (*fun)(T& f)) {
2744 long q = ar.el.get_qel();
2745 long n;
2746 for (n = 0; n < q; n++)
2747 (*fun)(ar.el[n]);
2748}
2749template <class T, class X>
2750void apply2(DynArr<T>& ar, void (*fun1)(T& f, void (*fun21)(X& f)),
2751 void (*fun2)(X& f)) {
2752 long q = ar.el.get_qel();
2753 long n;
2754 for (n = 0; n < q; n++)
2755 (*fun1)(ar.el[n], fun2);
2756}
2757
2761
2762template <class T> class IterDynArr {
2763 public:
2765 : ncur(fdar->get_qdim()), dar((DynArr<T>*)fdar) {
2766 long n;
2767 long qdim1 = ncur.get_qel() - 1;
2768 if (qdim1 >= 0) {
2769 for (n = 0; n < qdim1; n++)
2770 ncur[n] = 0;
2771 ncur[qdim1] = -1;
2772 }
2773 }
2774 T* more(void) // Just next element. Why not "next", do not remember.
2775 {
2776 if (find_next_comb(dar->get_qel(), ncur))
2777 return &(dar->ac(ncur));
2778 else
2779 return NULL;
2780 }
2781
2782 T* current(void) // Element currently pointed by ncut.
2783 {
2784 long n;
2785 long qdim = ncur.get_qel();
2786 if (qdim <= 0) return NULL;
2787 for (n = 0; n < qdim; n++) {
2788 if (ncur[n] < 0 || ncur[n] >= dar->get_qel()[n]) return NULL;
2789 }
2790 return &(dar->ac(ncur));
2791 }
2792
2793 T* less(void) // Switch current to previous.
2794 // Again do not remember why not" prev"
2795 {
2796 if (find_prev_comb(dar->get_qel(), ncur))
2797 return &(dar->ac(ncur));
2798 else
2799 return NULL;
2800 }
2801
2802 const DynLinArr<long>& get_ncur(void) const { return ncur; }
2803
2804 private:
2805 DynLinArr<long> ncur;
2806 DynArr<T>* dar;
2807};
2808
2810
2811template <class T>
2813 // by default val=NULL
2814 {
2815 check();
2816 if (qel.get_qel() == 0) {
2817 *this = DynArr<T>(qel_communicat, val);
2818 return;
2819 }
2820
2821 DynArr<T> datemp(qel_communicat, val); // all init to val
2822 IterDynArr<T> iter(&datemp);
2823 T* at;
2824 while ((at = iter.more()) != NULL) {
2825 if (confirm_ind_ext(iter.get_ncur()))
2826 *at = acp(iter.get_ncur()); // change to old values where they were
2827 }
2828 *this = datemp;
2829}
2830
2831template <class T>
2832 int operator==(const DynLinArr<T>& f1, const DynLinArr<T>& f2) {
2833 if (f1.get_qel() != f2.get_qel()) return 0;
2834 long q = f1.get_qel();
2835 long n;
2836 for (n = 0; n < q; n++) {
2837 if (!(f1.acu(n) == f2.acu(n))) return 0;
2838 }
2839 return 1;
2840}
2841
2842template <class T, class P>
2843int apeq_mant(const DynLinArr<T>& f1, const DynLinArr<T>& f2, P prec) {
2844 if (f1.get_qel() != f2.get_qel()) return 0;
2845 long q = f1.get_qel();
2846 long n;
2847 for (n = 0; n < q; n++) {
2848 if (!apeq_mant(f1.acu(n), f2.acu(n), prec)) return 0;
2849 }
2850 return 1;
2851}
2852
2853template <class T>
2854 int operator!=(const DynLinArr<T>& f1, const DynLinArr<T>& f2) {
2855 if (f1 == f2)
2856 return 0;
2857 else
2858 return 1;
2859}
2860
2861template <class T> int operator==(const DynArr<T>& f1, const DynArr<T>& f2) {
2862 if (f1.get_qel() != f2.get_qel()) return 0;
2863 if (f1.get_el() != f2.get_el()) return 0;
2864 return 1;
2865}
2866
2867template <class T, class P>
2868int apeq_mant(const DynArr<T>& f1, const DynArr<T>& f2, P prec) {
2869 if (f1.get_qel() != f2.get_qel()) return 0;
2870 if (!apeq_mant(f1.get_el(), f2.get_el(), prec)) return 0;
2871 return 1;
2872}
2873
2874template <class T> int operator!=(const DynArr<T>& f1, const DynArr<T>& f2) {
2875 if (f1.get_qel() == f2.get_qel()) return 0;
2876 if (f1.get_el() == f2.get_el()) return 0;
2877 return 1;
2878}
2879
2880template <class T> void DynArr<T>::assignAll(const T& val) {
2881 check();
2882 // try faster and simpler way (30.10.2006):
2883 el.assignAll(val);
2884 /*
2885 IterDynArr<T> iter(this);
2886 T* at;
2887 while( (at=iter.more()) != NULL )
2888 {
2889 *at=val;
2890 }
2891 */
2892}
2893
2894template <class T, class X> void copy_DynArr(const DynArr<T>& s, DynArr<X>& d) {
2895 mfunnamep("template<class T, class X> void copy_DynArr(const DynArr<T>& s, "
2896 "DynArr<X>& d)");
2897 s.check();
2898 d.check();
2899 d = DynArr<X>(s.get_qel(), NULL);
2900 IterDynArr<T> iter(&s);
2901 T* at;
2902 while ((at = iter.more()) != NULL) {
2903 const DynLinArr<long>& ncur = iter.get_ncur();
2904 d.ac(ncur) = *at;
2905 }
2906}
2907
2908// Convert types of elements from T to X.
2909template <class T, class X>
2911 mfunnamep("template<class T, class X> void convert_DynArr(const DynArr<T>& "
2912 "s, DynArr<X>& d)");
2913 s.check();
2914 d.check();
2915 d = DynArr<X>(s.get_qel(), NULL);
2916 IterDynArr<T> iter(&s);
2917 T* at;
2918 while ((at = iter.more()) != NULL) {
2919 const DynLinArr<long>& ncur = iter.get_ncur();
2920 d.ac(ncur) = X(*at);
2921 }
2922}
2923
2924template <class T> DynArr<T> DynLinArr<T>::top(void) {
2925 check();
2926 DynArr<T> r(1, qel);
2927 long n;
2928 for (n = 0; n < qel; n++) {
2929 r.ac(0, n) = el[n];
2930 }
2931 return r;
2932}
2933template <class T> DynArr<T> DynArr<T>::top(void) {
2934 mfunnamep("template<class T> DynArr<T> DynArr<T>::top(void)");
2935 check();
2936 long qdim = get_qdim();
2937 check_econd11(qdim, != 2, mcerr);
2938 long n1, n2;
2939 DynArr<T> r(qel[1], qel[0]);
2940 for (n1 = 0; n1 < qel[0]; n1++) {
2941 for (n2 = 0; n2 < qel[1]; n2++) {
2942 r.ac(n2, n1) = ac(n1, n2);
2943 }
2944 }
2945 return r;
2946}
2947
2948template <class T> DynLinArr<T>::DynLinArr(const DynArr<T>& f) {
2949 //mcout<<"template<class T> DynLinArr<T>::DynLinArr(const DynArr<T>& f):\n";
2950 f.check();
2951 long qdim = f.get_qdim();
2952 if (qdim != 1) {
2953 mcerr << "ERROR in DynLinArr<T>::DynLinArr(const DynArr<T>& f):\n"
2954 << "f.get_qdim() != 1, f.get_qdim()=" << f.get_qdim() << '\n';
2955 mcerr << "Type of T is (in internal notations) " << typeid(T).name()
2956 << '\n';
2957 spexit(mcerr);
2958 }
2959 const DynLinArr<long>& qelem = f.get_qel();
2960 qel = qelem[0];
2961 //mcout<<"qel="<<qel<<'\n';
2962 if (qel > 0) {
2963#ifdef USE_REPLACE_ALLOC
2964 el = (T*)malloc(sizeof(T) * qel);
2965 long n;
2966 for (n = 0; n < qel; n++)
2967 new (&(el[n])) T;
2968#else
2969 el = new T[qel];
2970#endif
2971 long n;
2972 for (n = 0; n < qel; n++)
2973 el[n] = f.ac(n);
2974 } else
2975 el = NULL;
2976}
2977
2978template <class T>
2979DynLinArr<T>::DynLinArr(const DynArr<T>& f, int n_of_dim,
2980 // 0 - first dim) 1 - second dim)
2981 long roc_number)
2982 // takes only mentioned raw or column.
2983 {
2984 f.check();
2985 long qdim = f.get_qdim();
2986 if (qdim != 2) {
2987 mcerr << "ERROR in DynLinArr<T>::DynLinArr(const DynArr<T>& f, int "
2988 "n_of_dim,long roc_number):\n"
2989 << "f.get_qdim() != 2, f.get_qdim()=" << f.get_qdim() << '\n';
2990 mcerr << "Type of T is (in internal notations) " << typeid(T).name()
2991 << '\n';
2992 spexit(mcerr);
2993 }
2994 const DynLinArr<long>& qelem = f.get_qel();
2995 if (n_of_dim == 0) {
2996 qel = qelem[1];
2997 } else {
2998 qel = qelem[0];
2999 }
3000 //mcout<<"qel="<<qel<<'\n';
3001 if (qel > 0) {
3002#ifdef USE_REPLACE_ALLOC
3003 el = (T*)malloc(sizeof(T) * qel);
3004 long n;
3005 for (n = 0; n < qel; n++)
3006 new (&(el[n])) T;
3007#else
3008 el = new T[qel];
3009#endif
3010 long n;
3011 if (n_of_dim == 0) {
3012 for (n = 0; n < qel; n++)
3013 el[n] = f.ac(roc_number, n);
3014 } else {
3015 for (n = 0; n < qel; n++)
3016 el[n] = f.ac(n, roc_number);
3017 }
3018 }
3019}
3020
3021template <class T>
3022 std::ostream& operator<<(std::ostream& file, const DynArr<T>& f) {
3023 //mfunnamep("template<class T> std::ostream& operator<<(std::ostream& file,
3024 //const DynArr<T>& f)");
3025 f.check();
3026 Ifile << "DynArr<T>: qdim=" << f.get_qdim() << '\n';
3027 indn.n += 2;
3028 if (s_short_output > 0) {
3029 Ifile << noindent << f.get_qel() << yesindent;
3030 } else {
3031 Ifile << "qel=" << noindent << f.get_qel() << yesindent;
3032 Ifile << "cum_qel=" << noindent << f.get_cum_qel() << yesindent;
3033 }
3034 if (f.get_s_non_emplty() == 1) {
3035 if (s_short_output == 0) {
3036 Ifile << "Content element by element:\n";
3037 Ifile << "(The first number is sequencial number, then there are "
3038 "indexes, the last is the element)\n";
3039 //DynArr<T>& ff(f);
3040 }
3041 long nseq = 0;
3042 IterDynArr<T> iter_f(&((DynArr<T>&)f));
3043 T* at;
3044 while ((at = iter_f.more()) != NULL) {
3045 std::ostringstream ost;
3046 if (s_short_output == 0) {
3047 //Ifile<<"ncur="<<noindent<<iter_f.get_ncur()<<yesindent;
3048 Ifile << "nseq=" << std::setw(5) << nseq << " ncur=";
3049 long n;
3050 for (n = 0; n < iter_f.get_ncur().get_qel(); n++) {
3051 file << ' ' << std::setw(5) << iter_f.get_ncur()[n];
3052 }
3053 ost << indn << " element=" << noindent << (*at) << yesindent;
3054 } else {
3055 ost << indn << noindent << (*at) << yesindent;
3056 }
3057 put_one_n(ost);
3058 file << ost.str();
3059 nseq++;
3060 }
3061 file << yesindent;
3062 } else {
3063 if (s_short_output == 0) {
3064 Ifile << "Content is empty.\n";
3065 }
3066 }
3067 indn.n -= 2;
3068 return file;
3069}
3070/*
3071template<class T>
3072void DybArr<T>::short_output(std::ostream& file)
3073{
3074 mfunnamep("template<class T> void DybArr<T>::short_output(std::ostream&
3075file))");
3076 f.check();
3077 Ifile<<"DynArr<T>: qdim="<<f.get_qdim()<<'\n';
3078 indn.n+=2;
3079 qel.short_output(file);
3080 if(f.get_s_non_emplty() == 1)
3081 {
3082 long nseq=0;
3083 IterDynArr<T> iter_f( &((DynArr<T>&) f));
3084 T* at;
3085 while( (at=iter_f.more()) != NULL )
3086 {
3087 std::ostringstream ost;
3088 ost<<indn<<noindent<<(*at)<<yesindent;
3089 put_one_n(ost);
3090 file<<ost.str();
3091 nseq++;
3092 }
3093 file<<yesindent;
3094 }
3095 indn.n-=2;
3096 return file;
3097}
3098*/
3099template <class T> std::istream& operator>>(std::istream& file, DynArr<T>& f) {
3100 mfunnamep(
3101 "template<class T> istream& operator>>(istream& file, DynArr<T>& f)");
3102 definp_endpar dep(&file, 0, 1, 0, s_short_output);
3103 long qdim = 0;
3104 dep.s_short = 0;
3105 DEFINPAP(qdim);
3106 dep.s_short = s_short_output;
3107 check_econd11(qdim, < 0, mcerr);
3108 if (s_short_output == 0) {
3109 set_position("qel=DynLinArr<T>:", *dep.istrm, dep.s_rewind, dep.s_req_sep);
3110 } else {
3111 set_position("DynLinArr<T>:", *dep.istrm, dep.s_rewind, dep.s_req_sep);
3112 }
3113 DynLinArr<long> qel_loc;
3114 //mcout<<"now will read qel_loc\n";
3115 file >> qel_loc;
3116 //mcout<<"qel_loc is read\n";
3117 if (s_short_output == 0) {
3118 set_position("cum_qel=DynLinArr<T>:", *dep.istrm, dep.s_rewind,
3119 dep.s_req_sep);
3120 DynLinArr<long> cum_qel_loc;
3121 file >> cum_qel_loc; // this is in general unnecessary
3122 }
3123 if (qel_loc.get_qel() > 0) {
3124 f.pilfer(DynArr<T>(qel_loc, NULL));
3125 long nseq;
3126 long n;
3127 long qseq = qel_loc[0];
3128 for (n = 1; n < qel_loc.get_qel(); n++) {
3129 qseq *= qel_loc[n];
3130 }
3131 for (n = 0; n < qseq; n++) {
3132 if (s_short_output == 0) {
3133 DEFINPAP(nseq);
3134 check_econd12(nseq, !=, n, mcerr);
3135 DynLinArr<long> ncur(qel_loc.get_qel());
3136 set_position("ncur=", *dep.istrm, dep.s_rewind, dep.s_req_sep);
3137 long m;
3138 for (m = 0; m < qel_loc.get_qel(); m++) {
3139 file >> ncur[m];
3140 }
3141 //T element;
3142 //DEFINPAP(element);
3143 //f.ac(ncur) = element;
3144 set_position("element=", *dep.istrm, dep.s_rewind, dep.s_req_sep);
3145 }
3146 file >> f.ac_lin(n);
3147 }
3148 } else {
3149 if (s_short_output == 0) {
3150 // just pass to end
3151 set_position("Content is empty.", *dep.istrm, dep.s_rewind,
3152 dep.s_req_sep);
3153 }
3154 f.pilfer(DynArr<T>());
3155
3156 }
3157 return file;
3158}
3159
3160/*
3161template<class T>
3162void DynArr<T>::short_read(istream& file)
3163{
3164 mfunnamep("template<class T> void DynArr<T>::short_read(istream& file)");
3165 definp_endpar dep(&file, 0, 1, 0);
3166 long qdim=0;
3167 DEFINPAP(qdim);
3168 check_econd11(qdim, < 0 , mcerr);
3169 DynLinArr<long> qel_loc;
3170 qel_loc.short_read(file);
3171 // generate cum
3172 if(qel_loc.get_qel() > 0 )
3173 {
3174 f.pilfer(DynArr<T>(qel_loc, NULL));
3175 long nseq;
3176 long n;
3177 long qseq=qel[0];
3178 for(n=1; n<el.get_qel(); n++)
3179 {
3180 qseq*=el[n];
3181 }
3182 for(n=0; n<qseq; n++)
3183 {
3184 file>>f.ac(ncur);
3185 }
3186 }
3187 else
3188 {
3189 // just pass to end
3190 set_position("Content is empty.",
3191 *dep.istrm, dep.s_rewind, dep.s_req_sep);
3192 }
3193 return file;
3194}
3195*/
3196
3197template <class T>
3198void print_DynArr(std::ostream& file, const DynArr<T>& f, int l) {
3199 //mfunnamep("template<class T> oid print_DynArr(std::ostream& file, const
3200 //DynArr<T>& f, int l)");
3201 f.check();
3202 //Ifile<<"DynArr<T>: qdim="<<f.get_qdim()
3203 // <<" qel="<<noindent<<f.get_qel()<<yesindent<<'\n';
3204 Ifile << "DynArr<T>: qdim=" << f.get_qdim() << '\n';
3205 indn.n += 2;
3206 Ifile << "qel=" << noindent << f.get_qel() << yesindent;
3207 Ifile << "cum_qel=" << noindent << f.get_cum_qel() << yesindent;
3208 Ifile << "Content element by element:\n";
3209 Ifile << "(The first number is sequencial number, then there are indexes, "
3210 "the last is the element)\n";
3211 //DynArr<T>& ff(f);
3212 long nseq = 0;
3213 IterDynArr<T> iter_f(&((DynArr<T>&)f));
3214 T* at;
3215 while ((at = iter_f.more()) != NULL) {
3216 //Ifile<<"ncur="<<noindent<<iter_f.get_ncur()<<yesindent;
3217 Ifile << "nseq=" << std::setw(5) << nseq << " ncur=";
3218 long n;
3219 for (n = 0; n < iter_f.get_ncur().get_qel(); n++) {
3220 file << ' ' << std::setw(5) << iter_f.get_ncur()[n];
3221 }
3222 //file<<'\n';
3223 //Ifile<<"element="<<noindent; at->print(file, l);
3224 //file<<yesindent<<'\n';
3225 std::ostringstream ost;
3226 ost << indn << " element=" << noindent;
3227 at->print(ost, l);
3228 ost << yesindent;
3229 put_one_n(ost);
3230 file << ost.str();
3231 }
3232 file << yesindent;
3233 indn.n -= 2;
3234
3235}
3236
3237// New experimental approach.
3238// give the width of field, which is put in setw().
3239// Whether the array will be printed in single lines
3240// or by columns, is determined by whether 80 symbols are enough
3241void print_DynArr_int_w(std::ostream& file, const DynArr<int>& f, int w);
3242
3243void print_DynArr_float(std::ostream& file, const DynArr<float>& f);
3244void print_DynArr_double(std::ostream& file, const DynArr<double>& f);
3245// ^Identical functions
3246// See AbsArrD for similar function with DoubleAc
3247
3248#define Iprintda_double(file, name) \
3249 file << indn << #name << "=" << noindent; \
3250 print_DynArr_double(file, name);
3251// See AbsArrD for similar function with DoubleAc
3252
3253#endif
void print_adr_DynLinArr(std::ostream &file, const DynLinArr< T > &f, int l, long q)
Definition: AbsArr.h:1474
const int pq_arrelem_in_line
Definition: AbsArr.h:1503
void print_DynLinArr_long(std::ostream &file, const DynLinArr< long > &f)
int operator!=(const DynLinArr< T > &f1, const DynLinArr< T > &f2)
Definition: AbsArr.h:2854
void(* fun)(T &f))
Definition: AbsArr.h:591
DynLinArr< long > qel_communicat
Definition: AbsArr.cpp:539
void print_DynLinArr_float(std::ostream &file, const DynLinArr< float > &f)
void convert_DynArr(const DynArr< T > &s, DynArr< X > &d)
Definition: AbsArr.h:2910
void print_DynArr_float(std::ostream &file, const DynArr< float > &f)
void copy_DynLinArr(const T &s, X &d)
Definition: AbsArr.h:1540
void print_DynArr_int_w(std::ostream &file, const DynArr< int > &f, int w)
int find_next_comb_not_less(const DynLinArr< long > &qel, DynLinArr< long > &f)
Definition: AbsArr.cpp:500
DynLinArr< T > merge(const DynLinArr< T > &fd1, long qfd1, const DynLinArr< T > &fd2, long qfd2)
Definition: AbsArr.h:1670
String DynLinArr_char_we_to_String(DynLinArr< char > &ar)
Definition: AbsArr.cpp:228
void print_DynLinArr_double(std::ostream &file, const DynLinArr< double > &f)
void print_DynArr_double(std::ostream &file, const DynArr< double > &f)
int ifequal(const DynLinArr< T > &fd1, const DynLinArr< T > &fd2, long qfirst=-1)
Definition: AbsArr.h:1631
void convert_DynLinArr(const T &s, X &d)
Definition: AbsArr.h:1553
void print_DynLinArr_int(std::ostream &file, const DynLinArr< int > &f)
void put_qel_1(DynLinArr< T > &f, long fq)
Definition: AbsArr.h:1563
int operator==(const DynLinArr< T > &f1, const DynLinArr< T > &f2)
Definition: AbsArr.h:2832
void print_DynLinArr(std::ostream &file, const DynLinArr< T > &f, int l)
Definition: AbsArr.h:1405
int apeq_mant(const DynLinArr< T > &f1, const DynLinArr< T > &f2, P prec)
Definition: AbsArr.h:2843
int find_next_comb(const DynLinArr< long > &qel, DynLinArr< long > &f)
Definition: AbsArr.cpp:465
void assignAll_1(DynLinArr< T > &f, const T1 &ft)
Definition: AbsArr.h:1573
void apply2(DynLinArr< T > &ar, void(*fun1)(T &f, void(*fun21)(X &f)), void(*fun2)(X &f))
Definition: AbsArr.h:602
void print_DynArr(std::ostream &file, const DynArr< T > &f, int l)
Definition: AbsArr.h:3198
long max_qel_DynLinArr
Definition: AbsArr.cpp:17
void print_DynLinArr_int_double3(std::ostream &file, const DynLinArr< int > &iar, const DynLinArr< double > &dar1, const DynLinArr< double > &dar2, const DynLinArr< double > &dar3)
std::istream & operator>>(std::istream &file, DynLinArr< T > &f)
Definition: AbsArr.h:1346
void print_DynLinArr_int_double(std::ostream &file, const DynLinArr< int > &iar, const DynLinArr< double > &dar)
void copy_DynArr(const DynArr< T > &s, DynArr< X > &d)
Definition: AbsArr.h:2894
void print_DynLinArr_double2(std::ostream &file, const DynLinArr< double > &f1, const DynLinArr< double > &f2)
int find_prev_comb(const DynLinArr< long > &qel, DynLinArr< long > &f)
Definition: AbsArr.cpp:520
void apply1(DynArr< T > &ar, void(*fun)(T &f))
Definition: AbsArr.h:2743
int gconfirm_ind_ext(const DynLinArr< long > &qel, const DynLinArr< long > &ind)
Definition: AbsArr.cpp:448
long append(const T &t, DynLinArr< T > &dla, long &qael, T *tempt=NULL, long new_qel=0)
Definition: AbsArr.h:1247
std::ostream & operator<<(std::ostream &file, const DynLinArr< T > &f)
Definition: AbsArr.h:1320
int gconfirm_ind(const DynLinArr< long > &qel, const DynLinArr< long > &ind)
Definition: AbsArr.cpp:433
Pilfer
Definition: AbsPtr.h:512
@ steal
Definition: AbsPtr.h:513
#define macro_copy_body(type)
Definition: AbsPtr.h:297
#define PILF_MUTABLE
Definition: AbsPtr.h:143
#define PILF_CONST
Definition: AbsPtr.h:142
DoubleAc find_max(const DoubleAc &a, const DoubleAc &b)
Definition: DoubleAc.h:655
#define check_econd11(a, signb, stream)
Definition: FunNameStack.h:366
#define mfunnamep(string)
Definition: FunNameStack.h:77
#define spexit(stream)
Definition: FunNameStack.h:536
#define check_econd12(a, sign, b, stream)
Definition: FunNameStack.h:380
#define macro_alloc
Definition: ReplaceAlloc.h:10
void put_one_n(std::ostringstream &ost)
Definition: String.h:127
std::string String
Definition: String.h:75
D & operator=(const D &f)
Definition: AbsArr.h:1927
IndexingProvider< D > & operator[](long n)
Definition: AbsArr.h:1944
DynArr< D > & arr
Definition: AbsArr.h:1907
const IndexingProvider< D > & operator[](long n) const
Definition: AbsArr.h:1972
IndexingProvider(DynArr< D > &farr, long fq_deref_ind, long fcurrent_pos)
Definition: AbsArr.h:1910
void pilfer(PILF_CONST DynArr< T > &f)
Definition: AbsArr.h:1863
const T & ac(long i1, long i2, long i3) const
Definition: AbsArr.h:2458
T & acp(const DynLinArr< long > &ind)
Definition: AbsArr.h:2187
DynArr(long fqel1, long fqel2, T *val=NULL)
Definition: AbsArr.h:1750
const T & acp(const DynLinArr< long > &ind) const
Definition: AbsArr.h:2222
const T & acu(const DynLinArr< long > &ind) const
Definition: AbsArr.h:2260
DynArr(long fqel, T *val=NULL)
Definition: AbsArr.h:1708
DynArr< T > top(void)
Definition: AbsArr.h:2933
T & ac(const DynLinArr< long > &ind)
Definition: AbsArr.h:2108
void pass(long q, DynLinArr< long > fqel, DynLinArr< long > fcum_qel, T *fel)
Definition: AbsArr.h:1893
const DynLinArr< long > & get_cum_qel(void) const
Definition: AbsArr.h:2552
DynArr(PILF_CONST DynArr< T > &f, Pilfer)
Definition: AbsArr.h:1856
virtual ~DynArr(void)
Definition: AbsArr.h:2604
void assignAll(const T &val)
Definition: AbsArr.h:2880
DynArr(long fqel1, long fqel2, long fqel3, T *val=NULL)
Definition: AbsArr.h:1780
const T & ac(long i1, long i2) const
Definition: AbsArr.h:2338
const DynLinArr< T > & get_el(void) const
Definition: AbsArr.h:2549
T & acu_lin(long n)
Definition: AbsArr.h:2542
DynArr(void)
Definition: AbsArr.h:1706
T & ac_lin(long n)
Definition: AbsArr.h:2501
long get_qdim(void) const
Definition: AbsArr.h:2547
DynArr< T > & operator=(const DynArr< T > &f)
Definition: AbsArr.h:2691
DynArr(const DynLinArr< T > &f)
Definition: AbsArr.h:1741
const T & acu(long i1, long i2) const
Definition: AbsArr.h:2413
DynArr(const DynArr< T > &f)
Definition: AbsArr.h:1846
DynArr(const DynLinArr< long > &fqel, T val, ArgInterp_Val)
Definition: AbsArr.h:1814
const IndexingProvider< T > operator[](long n) const
Definition: AbsArr.h:2030
void check(void) const
Definition: AbsArr.h:2587
const T & ac_lin(long n) const
Definition: AbsArr.h:2521
T & ac(long i)
Definition: AbsArr.h:2057
int confirm_ind_ext(const DynLinArr< long > &ind)
Definition: AbsArr.h:2572
macro_copy_total(DynArr)
DynArr< T > & operator=(const DynArr< D > &f)
Definition: AbsArr.h:2709
DynArr(long fqel, T val, ArgInterp_Val)
Definition: AbsArr.h:1719
int get_s_non_emplty(void) const
Definition: AbsArr.h:2592
void clear(void)
Definition: AbsArr.h:2565
const T & ac(const DynLinArr< long > &ind) const
Definition: AbsArr.h:2142
T & acu(long i1, long i2)
Definition: AbsArr.h:2408
friend void apply2(DynArr< P > &ar, void(*fun1)(P &f, void(*fun21)(X &f)), void(*fun2)(X &f))
T & acu(long i1)
Definition: AbsArr.h:2098
DynArr(long fqel1, long fqel2, T val, ArgInterp_Val)
Definition: AbsArr.h:1764
IndexingProvider< T > operator[](long n)
Definition: AbsArr.h:2006
T & acu(const DynLinArr< long > &ind)
Definition: AbsArr.h:2253
friend void apply1(DynArr< P > &ar, void(*fun)(P &f))
const T & ac(long i) const
Definition: AbsArr.h:2074
int confirm_ind(const DynLinArr< long > &ind)
Definition: AbsArr.h:2571
const T & acu(long i1) const
Definition: AbsArr.h:2102
long get_qel_lin(void) const
Definition: AbsArr.h:2498
const DynLinArr< long > & get_qel(void) const
Definition: AbsArr.h:2548
DynArr(long fqel, const T *ar, ArgInterp_Arr)
Definition: AbsArr.h:1730
T & ac(long i1, long i2, long i3)
Definition: AbsArr.h:2418
const T & acu_lin(long n) const
Definition: AbsArr.h:2543
T & ac(long i1, long i2)
Definition: AbsArr.h:2268
void put_qel(T *val=NULL)
Definition: AbsArr.h:2812
DynArr(const DynLinArr< long > &fqel, T *val)
Definition: AbsArr.h:1829
DynArr(long fqel1, long fqel2, long fqel3, long fqel4, T *val=NULL)
Definition: AbsArr.h:1794
DynLinArr< T > & assignAll1(const X &f)
Definition: AbsArr.h:297
void check(void) const
Definition: AbsArr.h:615
void pilfer(PILF_CONST DynLinArr< T > &f)
Definition: AbsArr.h:454
DynLinArr(const DynArr< T > &f)
Definition: AbsArr.h:2948
void clear(void)
Definition: AbsArr.h:450
DynLinArr< T > & operator=(const DynLinArr< D > &f)
Definition: AbsArr.h:710
DynLinArr(long fqel, const T &val)
Definition: AbsArr.h:189
void increment(const T *val=NULL)
Definition: AbsArr.h:440
long get_qel(void) const
Definition: AbsArr.h:420
DynLinArr(PILF_CONST DynLinArr< T > &f, Pilfer)
Definition: AbsArr.h:274
void put_qel(long fqel)
Definition: AbsArr.h:774
const T & acu(long n) const
Definition: AbsArr.h:376
friend void apply1(DynLinArr< P > &ar, void(*fun)(P &f))
void increment(const T &val)
Definition: AbsArr.h:445
void put_qel(long fqel, const T *val, ArgInterp_SingleAdr t)
Definition: AbsArr.h:842
DynLinArr(const DynArr< T > &f, int n_of_dim, long roc_number)
Definition: AbsArr.h:2979
virtual ~DynLinArr()
Definition: AbsArr.h:562
const T & operator[](long n) const
Definition: AbsArr.h:340
void sort_select_decreasing(DynLinArr< long > &sort_ind, long q_to_sort=0) const
Definition: AbsArr.h:1103
DynLinArr(long fqel)
Definition: AbsArr.h:160
void sort(long q_to_sort=0)
Definition: AbsArr.h:923
friend void apply2(DynLinArr< P > &ar, void(*fun1)(P &f, void(*fun21)(X &f)), void(*fun2)(X &f))
DynLinArr(long fqel, const T *ar, ArgInterp_Arr)
Definition: AbsArr.h:218
T & operator[](long n)
Definition: AbsArr.h:308
void put_qel(long fqel, const T &val)
Definition: AbsArr.h:437
macro_copy_header(DynLinArr)
DynLinArr & assignAll(const T &f)
Definition: AbsArr.h:289
void sort_select_increasing(DynLinArr< long > &sort_ind, long q_to_sort=0) const
Definition: AbsArr.h:1040
DynLinArr< T > & operator=(const DynLinArr< T > &f)
Definition: AbsArr.h:651
T & acu(long n)
Definition: AbsArr.h:372
T & last_el(void)
Definition: AbsArr.h:380
DynLinArr(void)
Definition: AbsArr.h:159
const T & last_el(void) const
Definition: AbsArr.h:400
void pass(long fqel, T *fel)
Definition: AbsArr.h:265
void sort(DynLinArr< long > &sort_ind, long q_to_sort=0) const
Definition: AbsArr.h:985
DynArr< T > top(void)
Definition: AbsArr.h:2924
DynLinArr(const DynLinArr< T > &f)
Definition: AbsArr.h:761
T * current(void)
Definition: AbsArr.h:2782
IterDynArr(const DynArr< T > *fdar)
Definition: AbsArr.h:2764
const DynLinArr< long > & get_ncur(void) const
Definition: AbsArr.h:2802
T * less(void)
Definition: AbsArr.h:2793
T * more(void)
Definition: AbsArr.h:2774
long get_ncur(void)
Definition: AbsArr.h:1606
T * more(void)
Definition: AbsArr.h:1585
T * current(void)
Definition: AbsArr.h:1592
T * less(void)
Definition: AbsArr.h:1598
IterDynLinArr(DynLinArr< T > *fdar)
Definition: AbsArr.h:1584
int s_rewind
Definition: definp.h:42
int s_short
Definition: definp.h:45
std::istream * istrm
Definition: definp.h:38
int s_req_sep
Definition: definp.h:43
long set_position(const String &word, std::istream &istrm, int s_rewind, int s_req_sep)
Definition: definp.cpp:71
void definp_any_par(T &inp, const String &word, const definp_endpar &dep, int fs_short=0)
Definition: definp.h:66
#define DEFINPAP(name)
Definition: definp.h:91
indentation indn
Definition: prstream.cpp:13
std::ostream & yesindent(std::ostream &f)
Definition: prstream.cpp:19
std::ostream & noindent(std::ostream &f)
Definition: prstream.cpp:15
int s_short_output
Definition: prstream.cpp:23
#define mcout
Definition: prstream.h:133
#define Iprint3n(file, name1, name2, name3)
Definition: prstream.h:249
#define Ifile
Definition: prstream.h:207
#define mcerr
Definition: prstream.h:135
#define Iprintn(file, name)
Definition: prstream.h:216
#define Iprint2n(file, name1, name2)
Definition: prstream.h:236