Garfield++ v1r0
A toolkit for the detailed simulation of particle detectors based on ionisation measurement in gases and semiconductors
Loading...
Searching...
No Matches
AbsList< T > Class Template Reference

#include <AbsList.h>

+ Inheritance diagram for AbsList< T >:

Public Member Functions

 AbsList (void)
 
 AbsList (const T &fel)
 
AbsListNode< T > * get_first_node (void) const
 
AbsListNode< T > * get_last_node (void) const
 
AbsListNode< T > * get_next_node (AbsListNode< T > *an) const
 
AbsListNode< T > * get_prev_node (AbsListNode< T > *an) const
 
AbsListNode< T > * insert_before (AbsListNode< T > *, const T &fel)
 
AbsListNode< T > * insert_after (AbsListNode< T > *an, const T &fel)
 
AbsListNode< T > * push_front (const T &fel)
 
AbsListNode< T > * prepend (const T &fel)
 
AbsListNode< T > * push_back (const T &fel)
 
AbsListNode< T > * append (const T &fel)
 
void erase (AbsListNode< T > *an)
 
void remove (AbsListNode< T > *an)
 
void remove (const T &t)
 
void remove_all (const T &t)
 
void clear (void)
 
long get_qel (void) const
 
 AbsList (const AbsList< T > &al)
 
 AbsList (PILF_CONST AbsList< T > &al, Pilfer)
 
void pilfer (PILF_CONST AbsList< T > &al)
 
AbsList< T > & operator= (const AbsList< T > &al)
 
virtual ~AbsList ()
 
 macro_copy_total (AbsList)
 

Friends

AbsListNode< T > * glob_insert_before (AbsList< T > &, AbsListNode< T > *, const T &fel)
 
AbsListNode< T > * glob_insert_after (AbsList< T > &, AbsListNode< T > *, const T &fel)
 
void glob_pilfer (AbsList< T > &, PILF_CONST AbsList< T > &)
 
void AbsListNode (void)
 

Detailed Description

template<class T>
class AbsList< T >

Definition at line 156 of file AbsList.h.

Constructor & Destructor Documentation

◆ AbsList() [1/4]

template<class T >
AbsList< T >::AbsList ( void  )
inline

Definition at line 165 of file AbsList.h.

168: first_node(NULL), last_node(NULL), qel(0) { ; }

◆ AbsList() [2/4]

template<class T >
AbsList< T >::AbsList ( const T &  fel)
inline

Definition at line 165 of file AbsList.h.

169 : first_node(NULL), last_node(NULL), qel(0) {
170 insert_after(NULL, fel);
171 }
AbsListNode< T > * insert_after(AbsListNode< T > *an, const T &fel)
Definition: AbsList.h:487

◆ AbsList() [3/4]

template<class T >
AbsList< T >::AbsList ( const AbsList< T > &  al)
inline

Definition at line 236 of file AbsList.h.

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 }
#define mcout
Definition: prstream.h:133

◆ AbsList() [4/4]

template<class T >
AbsList< T >::AbsList ( PILF_CONST AbsList< T > &  al,
Pilfer   
)
inline

Definition at line 249 of file AbsList.h.

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 }
void pilfer(PILF_CONST AbsList< T > &al)
Definition: AbsList.h:664

◆ ~AbsList()

template<class T >
virtual AbsList< T >::~AbsList ( )
inlinevirtual

Definition at line 258 of file AbsList.h.

258{ clear(); }
void clear(void)
Definition: AbsList.h:227

Member Function Documentation

◆ append()

template<class T >
AbsListNode< T > * AbsList< T >::append ( const T &  fel)
inline

Definition at line 216 of file AbsList.h.

216{ return push_back(fel); }
AbsListNode< T > * push_back(const T &fel)
Definition: AbsList.h:213

Referenced by FunNameStack::FunNameStack().

◆ clear()

template<class T >
void AbsList< T >::clear ( void  )
inline

Definition at line 227 of file AbsList.h.

227 {
228 while (first_node != NULL) { //mcout<<"erasing first node\n";
229 erase(first_node);
230 }
231 ;
232 }
void erase(AbsListNode< T > *an)
Definition: AbsList.h:547

Referenced by BlkArr< T >::allocate_block(), BlkArr< T >::clear(), BlkArr< T >::pilfer(), and AbsList< T >::~AbsList().

◆ erase()

template<class T >
void AbsList< T >::erase ( AbsListNode< T > *  an)

Definition at line 547 of file AbsList.h.

547 {
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}
#define spexit(stream)
Definition: FunNameStack.h:536
#define mcerr
Definition: prstream.h:135
#define Iprintn(file, name)
Definition: prstream.h:216

Referenced by AbsList< T >::clear(), BlkArr< T >::put_qel(), and AbsList< T >::remove().

◆ get_first_node()

template<class T >
AbsListNode< T > * AbsList< T >::get_first_node ( void  ) const
inline

◆ get_last_node()

template<class T >
AbsListNode< T > * AbsList< T >::get_last_node ( void  ) const
inline

Definition at line 174 of file AbsList.h.

174{ return last_node; }

Referenced by BlkArr< T >::put_qel().

◆ get_next_node()

◆ get_prev_node()

template<class T >
AbsListNode< T > * AbsList< T >::get_prev_node ( AbsListNode< T > *  an) const
inline

Definition at line 181 of file AbsList.h.

181 {
182 if (an == NULL)
183 return last_node;
184 else
185 return an->get_prev_node();
186 }

◆ get_qel()

template<class T >
long AbsList< T >::get_qel ( void  ) const
inline

Definition at line 235 of file AbsList.h.

235{ return qel; }

Referenced by operator<<(), and print_AbsList().

◆ insert_after()

template<class T >
AbsListNode< T > * AbsList< T >::insert_after ( AbsListNode< T > *  an,
const T &  fel 
)
inline

Definition at line 487 of file AbsList.h.

487 {
488 return glob_insert_after(*this, aln, fel);
489}
friend AbsListNode< T > * glob_insert_after(AbsList< T > &, AbsListNode< T > *, const T &fel)
Definition: AbsList.h:441

Referenced by AbsList< T >::push_back(), and BlkArr< T >::put_qel().

◆ insert_before()

template<class T >
AbsListNode< T > * AbsList< T >::insert_before ( AbsListNode< T > *  aln,
const T &  fel 
)
inline

Definition at line 374 of file AbsList.h.

374 {
375 return glob_insert_before<T>(*this, aln, fel);
376}

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

◆ macro_copy_total()

template<class T >
AbsList< T >::macro_copy_total ( AbsList< T >  )

◆ operator=()

template<class T >
AbsList< T > & AbsList< T >::operator= ( const AbsList< T > &  al)

Definition at line 618 of file AbsList.h.

618 {
619#ifdef DEBUG_ABSLIST
620 mcout
621 << "AbsList<T>& AbsList<T>::operator=(const AbsList<T>& f) is starting\n";
622#endif
623 clear();
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}
AbsListNode< T > * get_next_node(void) const
Definition: AbsList.h:98
AbsListNode< T > * get_last_node(void) const
Definition: AbsList.h:174

◆ pilfer()

template<class T >
void AbsList< T >::pilfer ( PILF_CONST AbsList< T > &  al)

Definition at line 664 of file AbsList.h.

664 {
665 glob_pilfer(*this, al);
666}
friend void glob_pilfer(AbsList< T > &, PILF_CONST AbsList< T > &)
Definition: AbsList.h:635

Referenced by AbsList< T >::AbsList(), and BlkArr< T >::pilfer().

◆ prepend()

template<class T >
AbsListNode< T > * AbsList< T >::prepend ( const T &  fel)
inline

Definition at line 212 of file AbsList.h.

212{ return push_front(fel); }
AbsListNode< T > * push_front(const T &fel)
Definition: AbsList.h:209

◆ push_back()

template<class T >
AbsListNode< T > * AbsList< T >::push_back ( const T &  fel)
inline

Definition at line 213 of file AbsList.h.

213 {
214 return insert_after(last_node, fel);
215 }

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

◆ push_front()

template<class T >
AbsListNode< T > * AbsList< T >::push_front ( const T &  fel)
inline

Definition at line 209 of file AbsList.h.

209 {
210 return insert_before(first_node, fel);
211 }
AbsListNode< T > * insert_before(AbsListNode< T > *, const T &fel)
Definition: AbsList.h:374

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

◆ remove() [1/2]

template<class T >
void AbsList< T >::remove ( AbsListNode< T > *  an)
inline

Definition at line 219 of file AbsList.h.

219 {
220 erase(an);
221 } // function to exclude the node

◆ remove() [2/2]

template<class T >
void AbsList< T >::remove ( const T &  t)

Definition at line 580 of file AbsList.h.

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}
void remove(AbsListNode< T > *an)
Definition: AbsList.h:219
AbsListNode< T > * get_next_node(AbsListNode< T > *an) const
Definition: AbsList.h:175

◆ remove_all()

template<class T >
void AbsList< T >::remove_all ( const T &  t)

Definition at line 593 of file AbsList.h.

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}

Friends And Related Function Documentation

◆ AbsListNode

template<class T >
void AbsListNode ( void  )
friend

◆ glob_insert_after

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

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}
AbsList< T > * get_head_node(void) const
Definition: AbsList.h:96
#define Iprint2n(file, name1, name2)
Definition: prstream.h:236

◆ glob_insert_before

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

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 
)
friend

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}

The documentation for this class was generated from the following file: