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 File Reference

Go to the source code of this file.

Classes

class  AbsListNode< T >
 
class  AbsList< T >
 

Functions

template<class T >
AbsListNode< T > * glob_insert_before (AbsList< T > &, AbsListNode< T > *, const T &fel)
 
template<class T >
AbsListNode< T > * glob_insert_after (AbsList< T > &, AbsListNode< T > *, const T &fel)
 
template<class T >
void glob_pilfer (AbsList< T > &, PILF_CONST AbsList< T > &)
 
template<class T >
void print_AbsList (std::ostream &file, const AbsList< T > &f, int l)
 
template<class T >
void print_AbsList (std::ostream &file, const AbsList< T > &f)
 
template<class T >
std::ostream & operator<< (std::ostream &file, const AbsListNode< T > &f)
 
template<class T >
std::ostream & operator<< (std::ostream &file, const AbsList< T > &f)
 

Function Documentation

◆ glob_insert_after()

template<class T >
AbsListNode< T > * glob_insert_after ( AbsList< T > &  al,
AbsListNode< T > *  aln,
const T &  fel 
)

Definition at line 441 of file AbsList.h.

442 {
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}
#define spexit(stream)
Definition: FunNameStack.h:536
AbsList< T > * get_head_node(void) const
Definition: AbsList.h:96
AbsListNode< T > * get_next_node(void) const
Definition: AbsList.h:98
#define mcerr
Definition: prstream.h:135
#define Iprintn(file, name)
Definition: prstream.h:216
#define Iprint2n(file, name1, name2)
Definition: prstream.h:236

Referenced by AbsList< T >::insert_after().

◆ glob_insert_before()

template<class T >
AbsListNode< T > * glob_insert_before ( AbsList< T > &  al,
AbsListNode< T > *  aln,
const T &  fel 
)

Definition at line 322 of file AbsList.h.

323 {
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}
AbsListNode< T > * get_prev_node(void) const
Definition: AbsList.h:97

◆ glob_pilfer()

template<class T >
void glob_pilfer ( AbsList< T > &  this_al,
PILF_CONST AbsList< T > &  al 
)

Definition at line 635 of file AbsList.h.

635 {
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}
void clear(void)
Definition: AbsList.h:227
#define mcout
Definition: prstream.h:133

Referenced by AbsList< T >::pilfer().

◆ operator<<() [1/2]

template<class T >
std::ostream & operator<< ( std::ostream &  file,
const AbsList< T > &  f 
)

Definition at line 767 of file AbsList.h.

767 {
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}
#define mfunnamep(string)
Definition: FunNameStack.h:77
AbsListNode< T > * get_next_node(AbsListNode< T > *an) const
Definition: AbsList.h:175
long get_qel(void) const
Definition: AbsList.h:235
indentation indn
Definition: prstream.cpp:13
std::ostream & yesindent(std::ostream &f)
Definition: prstream.cpp:19
#define Ifile
Definition: prstream.h:207

◆ operator<<() [2/2]

template<class T >
std::ostream & operator<< ( std::ostream &  file,
const AbsListNode< T > &  f 
)

Definition at line 751 of file AbsList.h.

751 {
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}

◆ print_AbsList() [1/2]

template<class T >
void print_AbsList ( std::ostream &  file,
const AbsList< T > &  f 
)

Definition at line 727 of file AbsList.h.

727 {
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}
std::ostream & noindent(std::ostream &f)
Definition: prstream.cpp:15

◆ print_AbsList() [2/2]

template<class T >
void print_AbsList ( std::ostream &  file,
const AbsList< T > &  f,
int  l 
)

Definition at line 703 of file AbsList.h.

703 {
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}