Garfield++ v1r0
A toolkit for the detailed simulation of particle detectors based on ionisation measurement in gases and semiconductors
Loading...
Searching...
No Matches
AbsList.h
Go to the documentation of this file.
1#ifndef ABSLIST_H
2#define ABSLIST_H
3/*
4Very simple and reliable doubly-linked list class with clear interface.
5The STL library is too hypertrophied regarding containers.
6The statements based on iterators seems to be not very clear.
7There is no clear semantic sense in the most of them.
8The simplest list and simplest operations with it seems to appear
9much more pronounced. The list consists of head node and regular nodes.
10The head node is a class keeping pointer to the first and to the last
11regular node, and the total number of elements.
12Each regular node is a class keeping pointers to head node,
13to previous node, and to the next node, and also the single "target" object.
14The node can be added and removed usually through the interface of
15the head class. Nodes can be iterated directly in both directions
16with looks like this:
17
18 AbsListNode<T>* an=NULL; // AbsListNode<T> is the name of node class
19 while( (an = list.get_next_node(an)) != NULL)
20 {
21 // do anything with valid an
22 // for example, access to element is an->el
23 }
24
25The name of list head class is AbsList<T>, the Abstract List.
26Copying the list results in copying all elements (through the operator=).
27Deletion of list results in deletion of elements.
28
29
30Copyright (c) 2003 I. B. Smirnov
31
32The file can be used, copied, modified, and distributed
33according to the terms of GNU Lesser General Public License version 2.1
34as published by the Free Software Foundation,
35and provided that the above copyright notice, this permission notice,
36and notices about any modifications of the original text
37appear in all copies and in supporting documentation.
38The file is provided "as is" without express or implied warranty.
39*/
40
41#ifndef DONT_USE_ABSPTR // in oder to supply some programs without
42 // smart pointers
44#else
45// Some necessary repetitions from AnsPtr.h:
46// See AnsPtr.h for details regarding the following:
47#define PILF_CONST const
48#define PILF_MUTABLE mutable
49//#define PILF_CONST
50//#define PILF_MUTABLE
51
52#endif
53
54#ifdef USE_REPLACE_ALLOC
56#endif
57
58//#define DEBUG_ABSLIST // make some print
59
60template <class T> class AbsList;
61template <class T> class AbsListNode;
62
63template <class T>
65template <class T>
67
68template <class T> void glob_pilfer(AbsList<T>&, PILF_CONST AbsList<T>&);
69
70#ifndef DONT_USE_ABSPTR
71template <class T>
72class AbsListNode : public RegPassivePtr
73#else
74 template <class T>
75 class AbsListNode
76#endif
77 {
78 private:
79 AbsList<T>* head_node;
80 AbsListNode<T>* prev_node;
81 AbsListNode<T>* next_node;
82 // preservation from copying
84#ifndef DONT_USE_ABSPTR
85 : RegPassivePtr()
86#endif
87 {
88 head_node = f.head_node;
89 prev_node = f.prev_node;
90 next_node = f.next_node;
91 }
92 AbsListNode<T>& operator=(const AbsListNode<T>& /*f*/) { return *this; }
93
94 public:
95 T el;
96 inline AbsList<T>* get_head_node(void) const { return head_node; }
97 inline AbsListNode<T>* get_prev_node(void) const { return prev_node; }
98 inline AbsListNode<T>* get_next_node(void) const { return next_node; }
99
100 // Attention: the following constructor cannot be called directly.
101 // It is assumed to be called only from ListNode functions.
102 private:
103 // The following constructor cannot be called directly.
104 // It is assumed to be called only from ListNode functions.
105 AbsListNode(AbsList<T>* fhead_node, AbsListNode<T>* fprev_node,
106 AbsListNode<T>* fnext_node, const T& fel);
107
108 public:
109 void exclude(void); // exclude this node from list, but don't erase it
110 // Then don't forget to delete it (from heap memory, where it normally
111 // resides).
112 // Really this deletes pointer to head_node, reducing qel in it.
113 // It also deletes pointers to prev_node and next_node
114 // And ties previous and next elements to each other.
115 // There is no the opposite operation - include. There seems to be
116 // no necessity in it, since in most of the cases
117 // the element itself is included and the node is created dynamically
118 // in insert_before, insert_after, etc. functions of AbsList<T>.
119
120 virtual ~AbsListNode() // excludes from list
121 {
122 exclude();
123 /*
124 if(head_node != NULL)
125 mcout<<"~AbsListNode(): error: head_node != NULL\n";
126 if(prev_node != NULL)
127 mcout<<"~AbsListNode(): error: prev_node != NULL\n";
128 if(next_node != NULL)
129 mcout<<"~AbsListNode(): error: next_node != NULL\n";
130 */
131 }
132 friend AbsListNode<T>* glob_insert_before<>(AbsList<T>&, AbsListNode<T>*,
133 const T& fel);
134 friend AbsListNode<T>* glob_insert_after<>(AbsList<T>&, AbsListNode<T>*,
135 const T& fel);
136 friend void glob_pilfer<>(AbsList<T>&, PILF_CONST AbsList<T>&);
137
138// The following is more logical, but not compiled at some newer compilers,
139// alas!
140//friend AbsListNode<T>* AbsList<T>::insert_before(AbsListNode<T>*, const T&
141//fel);
142//friend AbsListNode<T>* AbsList<T>::insert_after(AbsListNode<T>*, const T&
143//fel);
144
145//friend void AbsList<T>::pilfer(PILF_CONST AbsList<T>&);
146#ifndef DONT_USE_ABSPTR
148#endif
149#ifdef USE_REPLACE_ALLOC
151#endif
152};
153
154#ifndef DONT_USE_ABSPTR
155template <class T>
156class AbsList : public RegPassivePtr
157#else
158 template <class T>
159 class AbsList
160#endif
161 {
162 private:
163 PILF_MUTABLE AbsListNode<T>* first_node;
164 PILF_MUTABLE AbsListNode<T>* last_node;
165 PILF_MUTABLE long qel;
166
167 public:
168 AbsList<T>(void) : first_node(NULL), last_node(NULL), qel(0) { ; }
169 AbsList<T>(const T& fel) : first_node(NULL), last_node(NULL), qel(0) {
170 insert_after(NULL, fel);
171 }
172
173 inline AbsListNode<T>* get_first_node(void) const { return first_node; }
174 inline AbsListNode<T>* get_last_node(void) const { return last_node; }
176 if (an == NULL)
177 return first_node;
178 else
179 return an->get_next_node();
180 }
182 if (an == NULL)
183 return last_node;
184 else
185 return an->get_prev_node();
186 }
187 //This function defined above allows simple loops like
188 // AbsListNode<T>* an=NULL;
189 // while( (an = list.get_next_node(an)) != NULL)
190 // { do anything with valid an
191 // }
192
193 // two following functions returns the address of the new node
195 inline AbsListNode<T>* insert_after(AbsListNode<T>* an, const T& fel);
196
197 // The two following functions do the same as those above and actually called
198 // from
199 // above. The following are introduced in order to solve some restrictions
200 // imposed by formal rules and compilers.
201 friend AbsListNode<T>* glob_insert_before<>(AbsList<T>&, AbsListNode<T>*,
202 const T& fel);
203 friend AbsListNode<T>* glob_insert_after<>(AbsList<T>&, AbsListNode<T>*,
204 const T& fel);
205 friend void glob_pilfer<>(AbsList<T>&, PILF_CONST AbsList<T>&);
206
207 // if an == NULL, then only if qel = 0, the insert is made at first place
208 // otherwise it is considered as error.
209 AbsListNode<T>* push_front(const T& fel) {
210 return insert_before(first_node, fel);
211 }
212 AbsListNode<T>* prepend(const T& fel) { return push_front(fel); }
213 AbsListNode<T>* push_back(const T& fel) {
214 return insert_after(last_node, fel);
215 }
216 AbsListNode<T>* append(const T& fel) { return push_back(fel); }
217
218 void erase(AbsListNode<T>* an); // function to exclude the node
219 inline void remove(AbsListNode<T>* an) {
220 erase(an);
221 } // function to exclude the node
222 void remove(const T& t); // function to exclude the first met node
223 // with element equal to t
224 void remove_all(const T& t); // function to exclude all the nodes
225 // with element equal ro t
226
227 inline void clear(void) {
228 while (first_node != NULL) { //mcout<<"erasing first node\n";
229 erase(first_node);
230 }
231 ;
232 }
233 //inline AbsListNode& operator[](long n) const ;
234 //inline const AbsListNode& operator[](long n) const ;
235 long get_qel(void) const { return qel; }
237 :
238#ifndef DONT_USE_ABSPTR
239 RegPassivePtr(),
240#endif
241 first_node(NULL),
242 last_node(NULL),
243 qel(0) {
244#ifdef DEBUG_ABSLIST
245 mcout << "AbsList<T>(const AbsList<T>& al) is working\n";
246#endif
247 *this = al;
248 }
250 : first_node(NULL), last_node(NULL), qel(0) {
251#ifdef DEBUG_ABSLIST
252 mcout << "AbsList<T>(PILF_MUTABLE AbsList<T>& al, Pilfer) is working\n";
253#endif
254 pilfer(al);
255 }
258 virtual ~AbsList() { clear(); }
259 friend void AbsListNode<T>::exclude(void);
260//friend template<class T> void AbsListNode<T>::exclude(void);
261#ifndef DONT_USE_ABSPTR
263#endif
264#ifdef USE_REPLACE_ALLOC
266#endif
267};
268
269template <class T>
271 AbsListNode<T>* fnext_node, const T& fel)
272 : head_node(fhead_node),
273 prev_node(fprev_node),
274 next_node(fnext_node),
275 el(fel) {
276 //mcout<<"Constructor\n";
277 if (fprev_node != NULL) {
278 if (fprev_node->next_node != fnext_node) { // for debug
279 mcerr << "template<class T> AbsListNode<T>::AbsListNode<T>\n";
280 mcerr << "fprev_node->next_node != fnext_node\n";
281 Iprint2n(mcerr, fprev_node->next_node, fnext_node);
282 spexit(mcerr);
283 }
284 fprev_node->next_node = this;
285 }
286 if (fnext_node != NULL) {
287 if (fnext_node->prev_node != fprev_node) { // for debug
288 mcerr << "template<class T> AbsListNode<T>::AbsListNode<T>\n";
289 mcerr << "fnext_node->prev_node != fprev_node\n";
290 Iprint2n(mcerr, fnext_node->prev_node, fprev_node);
291 spexit(mcerr);
292 }
293 fnext_node->prev_node = this;
294 }
295}
296
297template <class T>
299 // exclude this node from list, but don't erase it
300 // Then don't forget to delete it
301 {
302 if (prev_node != NULL) prev_node->next_node = next_node;
303 if (next_node != NULL) next_node->prev_node = prev_node;
304 if (head_node != NULL) // normally cannot be
305 {
306 if (head_node->qel <= 0) {
307 mcerr << "ERROR in template<class T> void AbsListNode<T>::exclude()\n";
308 mcerr << "head_node->qel <= 0, contradicts to request to exclude\n";
309 Iprintn(mcerr, head_node->qel);
310 spexit(mcerr);
311 }
312 if (head_node->first_node == this) head_node->first_node = next_node;
313 if (head_node->last_node == this) head_node->last_node = prev_node;
314 head_node->qel--;
315 }
316 head_node = NULL;
317 prev_node = NULL;
318 next_node = NULL;
319}
320
321template <class T>
323 const T& fel) {
324 AbsListNode<T>* new_aln = NULL;
325 if (aln == NULL) // means to insert at the first place
326 {
327 if (al.qel == 0) // no elements, then the addresses should be empty as well
328 {
329 if (al.first_node != NULL || al.last_node != NULL) {
330 mcerr << "ERROR in template<class T> AbsListNode<T>* "
331 "glob_insert_before\n";
332 mcerr << "qel == 0, but first_node != NULL || last_node != NULL \n";
333 Iprintn(mcerr, al.first_node);
334 Iprintn(mcerr, al.last_node);
335 spexit(mcerr);
336 }
337 al.first_node = new AbsListNode<T>(&al, NULL, NULL, fel);
338 al.last_node = al.first_node;
339 new_aln = al.first_node;
340 al.qel = 1;
341 } else {
342 mcerr
343 << "ERROR in template<class T> AbsListNode<T>* glob_insert_before\n";
344 mcerr << " aln is zero, but the list is not empty\n";
345 spexit(mcerr);
346 }
347 } else {
348 if (aln->get_head_node() != &al) {
349 mcerr
350 << "ERROR in template<class T> AbsListNode<T>* glob_insert_before\n";
351 mcerr << "aln->get_head_node() != this\n";
352 Iprint2n(mcerr, aln->get_head_node(), al);
353 spexit(mcerr);
354 } else {
355 if (al.qel <= 0) {
356 mcerr << "ERROR in template<class T> AbsListNode<T>* "
357 "glob_insert_before\n";
358 mcerr << "qel <= 0 but aln is not empty\n";
359 Iprintn(mcerr, al.qel);
360 spexit(mcerr);
361 } else {
362 new_aln = new AbsListNode<T>(&al, aln->get_prev_node(), aln, fel);
363 if (aln == al.first_node) {
364 al.first_node = new_aln;
365 }
366 al.qel++;
367 }
368 }
369 }
370 return new_aln;
371}
372
373template <class T>
375 return glob_insert_before<T>(*this, aln, fel);
376}
377/*
378template<class T> AbsListNode<T>* AbsList<T>::insert_before
379(AbsListNode<T>* aln, const T& fel)
380{
381 AbsListNode<T>* new_aln = NULL;
382 if(aln == NULL) // means to insert at the first place
383 {
384 if(qel == 0) // no elements, then the addresses should be empty as well
385 {
386 if(first_node != NULL || last_node != NULL)
387 {
388 mcerr<<"ERROR in template<class T> void AbsList<T>::insert_before\n";
389 mcerr<<"qel == 0, but first_node != NULL || last_node != NULL \n";
390 Iprintn(mcerr, first_node);
391 Iprintn(mcerr, last_node);
392 spexit(mcerr);
393 }
394 first_node = new AbsListNode<T>(this, NULL, NULL, fel);
395 last_node = first_node;
396 new_aln = first_node;
397 qel = 1;
398 }
399 else
400 {
401 mcerr<<"ERROR in template<class T> void AbsList<T>::insert_before\n";
402 mcerr<<" aln is zero, but the list is not empty\n";
403 spexit(mcerr);
404 }
405 }
406 else
407 {
408 if(aln->get_head_node() != this)
409 {
410 mcerr<<"ERROR in template<class T> void AbsList<T>::insert_before\n";
411 mcerr<<"aln->get_head_node() != this\n";
412 Iprint2n(mcerr, aln->get_head_node(), this);
413 spexit(mcerr);
414 }
415 else
416 {
417 if(qel <= 0)
418 {
419 mcerr<<"ERROR in template<class T> void AbsList<T>::insert_before\n";
420 mcerr<<"qel <= 0 but aln is not empty\n";
421 Iprintn(mcerr, qel);
422 spexit(mcerr);
423 }
424 else
425 {
426 new_aln = new AbsListNode<T>
427 (this, aln->get_prev_node(), aln, fel);
428 if(aln == first_node)
429 {
430 first_node = new_aln;
431 }
432 qel++;
433 }
434 }
435 }
436 return new_aln;
437}
438*/
439
440template <class T>
442 const T& fel) {
443 AbsListNode<T>* new_aln = NULL;
444 if (aln == NULL) // no node after which it needs to insert
445 {
446 if (al.qel == 0) // empty list, OK
447 {
448 al.first_node = new AbsListNode<T>(&al, NULL, NULL, fel);
449 al.last_node = al.first_node;
450 new_aln = al.first_node;
451 al.qel = 1;
452 } else {
453 mcerr << "ERROR in template<class T> AbsListNode<T>* glob_insert_after\n";
454 mcerr << " aln is zero, but the list is not empty\n";
455 spexit(mcerr);
456 }
457 } else {
458 if (aln->get_head_node() != &al) // not our node or list
459 {
460 mcerr
461 << "ERROR in template<class T> AbsListNode<T>* glob_insert_after\n";
462 mcerr << "aln->get_heed_node() != this\n";
463 Iprint2n(mcerr, aln->get_head_node(), &al);
464 spexit(mcerr);
465 } else {
466 if (al.qel <= 0) // all ours but empty list - it is not consistent
467 {
468 mcerr << "ERROR in template<class T> AbsListNode<T>* "
469 "glob_insert_after\n";
470 mcerr << "qel <= 0 but aln is not empty\n";
471 Iprintn(mcerr, al.qel);
472 spexit(mcerr);
473 } else {
474 new_aln = new AbsListNode<T>(&al, aln, aln->get_next_node(), fel);
475 //if(new_aln->get_next_node().get() == NULL)
476 if (aln == al.last_node) {
477 al.last_node = new_aln;
478 }
479 al.qel++;
480 }
481 }
482 }
483 return new_aln;
484}
485
486template <class T>
488 return glob_insert_after(*this, aln, fel);
489}
490
491/*
492template<class T> AbsListNode<T>* AbsList<T>::insert_after
493(AbsListNode<T>* aln, const T& fel)
494{
495 AbsListNode<T>* new_aln = NULL;
496 if(aln == NULL) // no node after which it needs to insert
497 {
498 if(qel == 0) // empty list, OK
499 {
500 first_node = new AbsListNode<T>(this, NULL, NULL, fel);
501 last_node = first_node;
502 new_aln = first_node;
503 qel = 1;
504 }
505 else
506 {
507 mcerr<<"ERROR in template<class T> void AbsList<T>::insert_after\n";
508 mcerr<<" aln is zero, but the list is not empty\n";
509 spexit(mcerr);
510 }
511 }
512 else
513 {
514 if(aln->get_head_node() != this) // not our node or list
515 {
516 mcerr<<"ERROR in template<class T> void AbsList<T>::insert_after\n";
517 mcerr<<"aln->get_heed_node() != this\n";
518 Iprint2n(mcerr, aln->get_head_node(), this);
519 spexit(mcerr);
520 }
521 else
522 {
523 if(qel <= 0) // all ours but empty list - it is not consistent
524 {
525 mcerr<<"ERROR in template<class T> void AbsList<T>::insert_after\n";
526 mcerr<<"qel <= 0 but aln is not empty\n";
527 Iprintn(mcerr, qel);
528 spexit(mcerr);
529 }
530 else
531 {
532 new_aln = new AbsListNode<T>
533 (this, aln, aln->get_next_node(), fel);
534 //if(new_aln->get_next_node().get() == NULL)
535 if(aln == last_node)
536 {
537 last_node = new_aln;
538 }
539 qel++;
540 }
541 }
542 }
543 return new_aln;
544}
545*/
546
547template <class T> void AbsList<T>::erase(AbsListNode<T>* aln) {
548 if (aln->get_head_node() != this) {
549 mcerr << "ERROR in template<class T> void AbsList<T>::erase(...)\n";
550 mcerr << "aln->get_heed_node() != this\n";
551 spexit(mcerr);
552 }
553 if (qel <= 0) // empty list - it is not consistent
554 {
555 mcerr << "ERROR in template<class T> void AbsList<T>::erase(...)\n";
556 mcerr << "qel <= 0 before erase \n";
557 Iprintn(mcerr, qel);
558 spexit(mcerr);
559 }
560
561 //AbsListNode<T>* aaln = aln.get();
562 //aln->exclude(); now called from delete
563 /*
564 if(first_node == aln)
565 {
566 first_node = aln->get_next_node();
567 }
568 if(last_node == aln)
569 {
570 last_node = aln->get_prev_node();
571 }
572 */
573 delete aln;
574 //qel--; now in exclude();
575 //aaln->get_prev_node()->put_next_node(aaln->get_next_node() );
576 //aaln->get_next_node()->put_prev_node(aaln->get_prev_node() );
577}
578
579template <class T>
580void AbsList<T>::remove(const T& t)
581 // function to exclude the node
582 {
583 AbsListNode<T>* an = NULL;
584 while ((an = get_next_node(an)) != NULL) {
585 if (an->el == t) {
586 remove(an);
587 break;
588 }
589 }
590}
591
592template <class T>
594 // function to exclude the node
595 {
596 AbsListNode<T>* an = NULL;
597 while ((an = get_next_node(an)) != NULL) {
598 if (an->el == t) {
599 remove(an);
600 }
601 }
602}
603
604/*
605template<class T> void AbsListNode<T>::exclude(void)
606{
607 if(prev_node != NULL)
608 {
609 prev_node->next_node = next_node;
610 }
611 if(next_node != NULL)
612 {
613 next_node->prev_node = prev_node;
614 }
615}
616*/
617
618template <class T> AbsList<T>& AbsList<T>::operator=(const AbsList<T>& f) {
619#ifdef DEBUG_ABSLIST
620 mcout
621 << "AbsList<T>& AbsList<T>::operator=(const AbsList<T>& f) is starting\n";
622#endif
623 clear();
624 AbsListNode<T>* aln = get_last_node();
625 AbsListNode<T>* faln = f.get_first_node();
626 while (faln != NULL) {
627 insert_after(aln, faln->el);
628 aln = get_last_node();
629 faln = faln->get_next_node();
630 }
631 return *this;
632}
633
634template <class T>
636#ifdef DEBUG_ABSLIST
637 mcout << "void glob_pilfer(AbsList<T>& this_al, PILF_CONST AbsList<T>& al) "
638 "is starting\n";
639#endif
640 if (this_al.qel != 0) {
641 if (al.qel != 0) {
642 mcerr << "ERROR in glob_pilfer(...):\n";
643 mcerr << "Both the destination and source lists are not empty\n";
644 // For explanations why it is dangerous, see similar function
645 // of ActivePtr.
646 spexit(mcerr);
647 } else {
648 this_al.clear();
649 }
650 }
651 this_al.first_node = al.first_node;
652 this_al.last_node = al.last_node;
653 this_al.qel = al.qel;
654 AbsListNode<T>* cur_node = this_al.first_node;
655 while (cur_node != NULL) {
656 cur_node->head_node = &this_al;
657 cur_node = cur_node->get_next_node();
658 }
659 al.first_node = NULL;
660 al.last_node = NULL;
661 al.qel = 0;
662}
663
664template <class T> void AbsList<T>::pilfer(PILF_CONST AbsList<T>& al) {
665 glob_pilfer(*this, al);
666}
667
668/*
669template<class T>
670void AbsList<T>::pilfer(PILF_CONST AbsList<T>& al)
671{
672#ifdef DEBUG_ABSLIST
673 mcout<<"void AbsList<T>::pilfer(PILF_CONST AbsList<T>& al) is starting\n";
674#endif
675 if(qel != 0)
676 {
677 if(al.qel != 0)
678 {
679 mcerr<<"ERROR in AbsList::pilfer(...):\n";
680 mcerr<<"Both the destination and source lists are not empty\n";
681 // For explanations why it is dangerous, see similar function
682 // of ActivePtr.
683 spexit(mcerr);
684 }
685 else { clear(); }
686 }
687 first_node = al.first_node;
688 last_node = al.last_node;
689 qel = al.qel;
690 AbsListNode<T>* cur_node = first_node;
691 while(cur_node != NULL)
692 {
693 cur_node->head_node = this;
694 cur_node = cur_node->get_next_node();
695 }
696 al.first_node = NULL;
697 al.last_node = NULL;
698 al.qel = 0;
699}
700*/
701
702template <class T>
703void print_AbsList(std::ostream& file, const AbsList<T>& f, int l) {
704 mfunnamep("template<class T> void print_AbsList(std::ostream& file, const "
705 "AbsList<T>& f, int l)");
706 Ifile << "AbsList<T>: qel=" << f.get_qel() << '\n';
707 //f.check();
708 long n = 0;
709 indn.n += 2;
710 AbsListNode<T>* aln = NULL;
711 while ((aln = f.get_next_node(aln)) != NULL) {
712 Ifile << "n=" << n << " el[n]=" << noindent;
713 aln->el.print(file, l);
714 n++;
715 }
716 // Another form of the same loop:
717 //AbsListNode<T>* aln = f.get_first_node();
718 //for( n=0; n<f.get_qel(); n++)
719 //{
720 // Ifile<<"n="<<n<<" el[n]="<<noindent; aln->el.print(file, l);
721 // aln = aln->get_next_node();
722 //}
723 file << yesindent;
724 indn.n -= 2;
725}
726
727template <class T> void print_AbsList(std::ostream& file, const AbsList<T>& f) {
728 mfunnamep("template<class T> void print_AbsList(std::ostream& file, const "
729 "AbsList<T>& f)");
730 Ifile << "AbsList<T>: qel=" << f.get_qel() << '\n';
731 //f.check();
732 long n = 0;
733 indn.n += 2;
734 AbsListNode<T>* aln = NULL;
735 while ((aln = f.get_next_node(aln)) != NULL) {
736 Ifile << "n=" << n << " el[n]=" << noindent;
737 aln->el.print(file);
738 n++;
739 }
740 //AbsListNode<T>* aln = f.get_first_node();
741 //for( n=0; n<f.get_qel(); n++)
742 //{
743 // Ifile<<"n="<<n<<" el[n]="<<noindent; aln->el.print(file);
744 // aln = aln->get_next_node();
745 //}
746 file << yesindent;
747 indn.n -= 2;
748}
749
750template <class T>
751 std::ostream& operator<<(std::ostream& file, const AbsListNode<T>& f) {
752 mfunnamep("template<class T> std::ostream& operator<<(std::ostream& file, "
753 "const AbsListNode<T>& f)");
754 Ifile << "AbsListNode<T>:\n";
755 indn.n += 2;
756#ifdef DONT_USE_ABSPTR
757#else
758 file << (*(static_cast<const RegPassivePtr*>(&f))) << '\n';
759#endif
760 file << "Element:\n";
761 file << f.el;
762 indn.n -= 2;
763 return file;
764}
765
766template <class T>
767 std::ostream& operator<<(std::ostream& file, const AbsList<T>& f) {
768 mfunnamep("template<class T> std::ostream& operator<<(std::ostream& file, "
769 "const AbsList<T>& f)");
770 Ifile << "AbsList<T>: qel=" << f.get_qel() << '\n';
771 //f.check();
772 long n = 0;
773 indn.n += 2;
774 AbsListNode<T>* aln = NULL;
775 while ((aln = f.get_next_node(aln)) != NULL) {
776 Ifile << "n=" << n << " el[n]=" << aln->el << '\n';
777 n++;
778 }
779 //AbsListNode<T>* aln = f.get_first_node();
780 //for( n=0; n<f.get_qel(); n++)
781 //{
782 // Ifile<<"n="<<n<<" el[n]="<<aln->el<<'\n';
783 // aln = aln->get_next_node();
784 // //Iprintn(mcout, aln);
785 //}
786 file << yesindent;
787 indn.n -= 2;
788 return file;
789}
790
791#endif
AbsListNode< T > * glob_insert_before(AbsList< T > &, AbsListNode< T > *, const T &fel)
Definition: AbsList.h:322
void glob_pilfer(AbsList< T > &, PILF_CONST AbsList< T > &)
Definition: AbsList.h:635
void print_AbsList(std::ostream &file, const AbsList< T > &f, int l)
Definition: AbsList.h:703
std::ostream & operator<<(std::ostream &file, const AbsListNode< T > &f)
Definition: AbsList.h:751
AbsListNode< T > * glob_insert_after(AbsList< T > &, AbsListNode< T > *, const T &fel)
Definition: AbsList.h:441
Pilfer
Definition: AbsPtr.h:512
#define PILF_MUTABLE
Definition: AbsPtr.h:143
#define PILF_CONST
Definition: AbsPtr.h:142
#define mfunnamep(string)
Definition: FunNameStack.h:77
#define spexit(stream)
Definition: FunNameStack.h:536
#define macro_alloc
Definition: ReplaceAlloc.h:10
AbsList< T > * get_head_node(void) const
Definition: AbsList.h:96
AbsListNode< T > * get_next_node(void) const
Definition: AbsList.h:98
macro_copy_total(AbsListNode)
virtual ~AbsListNode()
Definition: AbsList.h:120
void exclude(void)
Definition: AbsList.h:298
AbsListNode< T > * get_prev_node(void) const
Definition: AbsList.h:97
AbsListNode< T > * insert_after(AbsListNode< T > *an, const T &fel)
Definition: AbsList.h:487
AbsList(const AbsList< T > &al)
Definition: AbsList.h:236
virtual ~AbsList()
Definition: AbsList.h:258
void erase(AbsListNode< T > *an)
Definition: AbsList.h:547
void remove(AbsListNode< T > *an)
Definition: AbsList.h:219
AbsListNode< T > * get_last_node(void) const
Definition: AbsList.h:174
AbsListNode< T > * get_next_node(AbsListNode< T > *an) const
Definition: AbsList.h:175
void remove(const T &t)
Definition: AbsList.h:580
AbsListNode< T > * push_front(const T &fel)
Definition: AbsList.h:209
AbsListNode< T > * get_prev_node(AbsListNode< T > *an) const
Definition: AbsList.h:181
void clear(void)
Definition: AbsList.h:227
AbsListNode< T > * prepend(const T &fel)
Definition: AbsList.h:212
AbsListNode< T > * append(const T &fel)
Definition: AbsList.h:216
void pilfer(PILF_CONST AbsList< T > &al)
Definition: AbsList.h:664
AbsList(PILF_CONST AbsList< T > &al, Pilfer)
Definition: AbsList.h:249
AbsListNode< T > * push_back(const T &fel)
Definition: AbsList.h:213
long get_qel(void) const
Definition: AbsList.h:235
AbsListNode< T > * insert_before(AbsListNode< T > *, const T &fel)
Definition: AbsList.h:374
macro_copy_total(AbsList)
void remove_all(const T &t)
Definition: AbsList.h:593
AbsList< T > & operator=(const AbsList< T > &al)
Definition: AbsList.h:618
AbsListNode< T > * get_first_node(void) const
Definition: AbsList.h:173
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
#define mcout
Definition: prstream.h:133
#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