41#ifndef DONT_USE_ABSPTR
47#define PILF_CONST const
48#define PILF_MUTABLE mutable
54#ifdef USE_REPLACE_ALLOC
60template <
class T>
class AbsList;
70#ifndef DONT_USE_ABSPTR
84#ifndef DONT_USE_ABSPTR
88 head_node = f.head_node;
89 prev_node = f.prev_node;
90 next_node = f.next_node;
146#ifndef DONT_USE_ABSPTR
149#ifdef USE_REPLACE_ALLOC
154#ifndef DONT_USE_ABSPTR
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) {
179 return an->get_next_node();
185 return an->get_prev_node();
228 while (first_node != NULL) {
238#ifndef DONT_USE_ABSPTR
245 mcout <<
"AbsList<T>(const AbsList<T>& al) is working\n";
250 : first_node(NULL), last_node(NULL), qel(0) {
252 mcout <<
"AbsList<T>(PILF_MUTABLE AbsList<T>& al, Pilfer) is working\n";
261#ifndef DONT_USE_ABSPTR
264#ifdef USE_REPLACE_ALLOC
272 : head_node(fhead_node),
273 prev_node(fprev_node),
274 next_node(fnext_node),
277 if (fprev_node != NULL) {
278 if (fprev_node->next_node != fnext_node) {
279 mcerr <<
"template<class T> AbsListNode<T>::AbsListNode<T>\n";
280 mcerr <<
"fprev_node->next_node != fnext_node\n";
284 fprev_node->next_node =
this;
286 if (fnext_node != NULL) {
287 if (fnext_node->prev_node != fprev_node) {
288 mcerr <<
"template<class T> AbsListNode<T>::AbsListNode<T>\n";
289 mcerr <<
"fnext_node->prev_node != fprev_node\n";
293 fnext_node->prev_node =
this;
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)
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";
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;
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";
338 al.last_node = al.first_node;
339 new_aln = al.first_node;
343 <<
"ERROR in template<class T> AbsListNode<T>* glob_insert_before\n";
344 mcerr <<
" aln is zero, but the list is not empty\n";
350 <<
"ERROR in template<class T> AbsListNode<T>* glob_insert_before\n";
351 mcerr <<
"aln->get_head_node() != this\n";
356 mcerr <<
"ERROR in template<class T> AbsListNode<T>* "
357 "glob_insert_before\n";
358 mcerr <<
"qel <= 0 but aln is not empty\n";
363 if (aln == al.first_node) {
364 al.first_node = new_aln;
375 return glob_insert_before<T>(*
this, aln, fel);
449 al.last_node = al.first_node;
450 new_aln = al.first_node;
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";
461 <<
"ERROR in template<class T> AbsListNode<T>* glob_insert_after\n";
462 mcerr <<
"aln->get_heed_node() != this\n";
468 mcerr <<
"ERROR in template<class T> AbsListNode<T>* "
469 "glob_insert_after\n";
470 mcerr <<
"qel <= 0 but aln is not empty\n";
476 if (aln == al.last_node) {
477 al.last_node = new_aln;
549 mcerr <<
"ERROR in template<class T> void AbsList<T>::erase(...)\n";
550 mcerr <<
"aln->get_heed_node() != this\n";
555 mcerr <<
"ERROR in template<class T> void AbsList<T>::erase(...)\n";
556 mcerr <<
"qel <= 0 before erase \n";
584 while ((an = get_next_node(an)) != NULL) {
597 while ((an = get_next_node(an)) != NULL) {
621 <<
"AbsList<T>& AbsList<T>::operator=(const AbsList<T>& f) is starting\n";
626 while (faln != NULL) {
627 insert_after(aln, faln->
el);
628 aln = get_last_node();
637 mcout <<
"void glob_pilfer(AbsList<T>& this_al, PILF_CONST AbsList<T>& al) "
640 if (this_al.qel != 0) {
642 mcerr <<
"ERROR in glob_pilfer(...):\n";
643 mcerr <<
"Both the destination and source lists are not empty\n";
651 this_al.first_node = al.first_node;
652 this_al.last_node = al.last_node;
653 this_al.qel = al.qel;
655 while (cur_node != NULL) {
656 cur_node->head_node = &this_al;
659 al.first_node = NULL;
704 mfunnamep(
"template<class T> void print_AbsList(std::ostream& file, const "
705 "AbsList<T>& f, int l)");
713 aln->
el.print(file, l);
728 mfunnamep(
"template<class T> void print_AbsList(std::ostream& file, const "
752 mfunnamep(
"template<class T> std::ostream& operator<<(std::ostream& file, "
753 "const AbsListNode<T>& f)");
754 Ifile <<
"AbsListNode<T>:\n";
756#ifdef DONT_USE_ABSPTR
758 file << (*(static_cast<const RegPassivePtr*>(&f))) <<
'\n';
760 file <<
"Element:\n";
768 mfunnamep(
"template<class T> std::ostream& operator<<(std::ostream& file, "
769 "const AbsList<T>& f)");
776 Ifile <<
"n=" << n <<
" el[n]=" << aln->
el <<
'\n';
AbsListNode< T > * glob_insert_before(AbsList< T > &, AbsListNode< T > *, const T &fel)
void glob_pilfer(AbsList< T > &, PILF_CONST AbsList< T > &)
void print_AbsList(std::ostream &file, const AbsList< T > &f, int l)
std::ostream & operator<<(std::ostream &file, const AbsListNode< T > &f)
AbsListNode< T > * glob_insert_after(AbsList< T > &, AbsListNode< T > *, const T &fel)
#define mfunnamep(string)
AbsList< T > * get_head_node(void) const
AbsListNode< T > * get_next_node(void) const
macro_copy_total(AbsListNode)
AbsListNode< T > * get_prev_node(void) const
AbsListNode< T > * insert_after(AbsListNode< T > *an, const T &fel)
AbsList(const AbsList< T > &al)
void erase(AbsListNode< T > *an)
void remove(AbsListNode< T > *an)
AbsListNode< T > * get_last_node(void) const
AbsListNode< T > * get_next_node(AbsListNode< T > *an) const
AbsListNode< T > * push_front(const T &fel)
AbsListNode< T > * get_prev_node(AbsListNode< T > *an) const
AbsListNode< T > * prepend(const T &fel)
AbsListNode< T > * append(const T &fel)
void pilfer(PILF_CONST AbsList< T > &al)
AbsList(PILF_CONST AbsList< T > &al, Pilfer)
AbsListNode< T > * push_back(const T &fel)
AbsListNode< T > * insert_before(AbsListNode< T > *, const T &fel)
macro_copy_total(AbsList)
void remove_all(const T &t)
AbsList< T > & operator=(const AbsList< T > &al)
AbsListNode< T > * get_first_node(void) const
std::ostream & yesindent(std::ostream &f)
std::ostream & noindent(std::ostream &f)
#define Iprintn(file, name)
#define Iprint2n(file, name1, name2)