// Copyright (C) 1999-2018 // Smithsonian Astrophysical Observatory, Cambridge, MA, USA // For conditions of distribution and use, see copyright notice in "copyright" #include "list.h" #include "vector.h" #include "marker.h" #include "callback.h" #include "contour.h" #include "fitsmask.h" #include "sao.h" #include "lut.h" #include "colormap.h" #include "colortag.h" #include "raytrace.h" template List::List() { head_ = NULL; tail_ = NULL; current_ = NULL; count_ = 0; } template List::List(const List& aa) { head_ = NULL; tail_ = NULL; current_ = NULL; count_ = 0; List& a = (List&)aa; if (a.head()) do append(new T((T)(*(a.current_)))); while (a.next()); } // this is needed because of Marker virtual functions template <> List::List(const List& aa) { head_ = NULL; tail_ = NULL; current_ = NULL; count_ = 0; List& a = (List&)aa; if (a.head()) do append(a.current_->dup()); while (a.next()); } // this is needed because of ColorMapInfo virtual functions template <> List::List(const List& aa) { head_ = NULL; tail_ = NULL; current_ = NULL; count_ = 0; List& a = (List&)aa; if (a.head()) do append(a.current_->dup()); while (a.next()); } template List::~List() { T* ptr = head_; while (ptr) { T* tmp = ptr->next(); delete ptr; ptr = tmp; } } template List& List::operator=(const List& aa) { deleteAll(); List& a = (List&)aa; if (a.head()) do append(new T((T)(*(a.current_)))); while (a.next()); return *this; } // this is needed because of Marker virtual functions template <> List& List::operator=(const List& aa) { deleteAll(); List& a = (List&)aa; if (a.head()) do append(a.current_->dup()); while (a.next()); return *this; } // this is needed because of ColorMapInfo virtual functions template <> List& List::operator=(const List& aa) { deleteAll(); List& a = (List&)aa; if (a.head()) do append(a.current_->dup()); while (a.next()); return *this; } template void List::insertHead(T* t) { if (head_ && t) { t->setNext(head_); t->setPrevious(NULL); head_->setPrevious(t); head_ = t; } else { head_ = t; tail_ = t; } current_ = head_; count_++; } template void List::insert(int which, T* t) { head(); for (int i=0; inext(); t->setPrevious(current_); t->setNext(n); current_->setNext(t); if (n) n->setPrevious(t); else tail_ = t; count_++; } } template void List::insertNext(T* c, T* t) { if (c && t) { T* n = c->next(); t->setPrevious(c); t->setNext(n); c->setNext(t); if (n) n->setPrevious(t); else tail_ = t; count_++; } } template void List::insertPrev(T* c, T* t) { if (c && t) { T* p = c->previous(); t->setPrevious(p); t->setNext(c); c->setPrevious(t); if (p) p->setNext(t); else head_ = t; count_++; } } template void List::append(T* p) { if (tail_) { p->setPrevious(tail_); p->setNext(NULL); tail_->setNext(p); tail_ = p; } else { p->setPrevious(NULL); p->setNext(NULL); head_ = p; tail_ = p; } current_ = tail_; count_++; } template void List::deleteAll() { T* ptr = head_; while (ptr) { T* tmp = ptr->next(); delete ptr; ptr = tmp; } head_ = NULL; tail_ = NULL; current_ = NULL; count_ = 0; } template T* List::pop() { if (tail_) { T* m = tail_; if (tail_ != head_) { T* p = tail_->previous(); p->setNext(NULL); tail_ = p; current_ = p; count_--; } else { head_ = NULL; tail_ = NULL; current_ = NULL; count_ = 0; } return m; } return NULL; } template T* List::fifo() { if (head_) { T* m = head_; if (tail_ != head_) { T* n = head_->next(); n->setPrevious(NULL); head_ = n; current_ = n; count_--; } else { head_ = NULL; tail_ = NULL; current_ = NULL; count_ = 0; } return m; } return NULL; } template T* List::extract() { T* ptr = current_; T* p = ptr->previous(); T* n = ptr->next(); if (p) p->setNext(n); if (n) n->setPrevious(p); if (head_ == ptr) head_ = n; if (tail_ == ptr) tail_ = p; current_ = NULL; count_--; ptr->setNext(NULL); ptr->setPrevious(NULL); return ptr; } template T* List::extractNext(T* ptr) { T* p = ptr->previous(); T* n = ptr->next(); if (p) p->setNext(n); if (n) n->setPrevious(p); if (head_ == ptr) head_ = n; if (tail_ == ptr) tail_ = p; current_ = NULL; count_--; ptr->setNext(NULL); ptr->setPrevious(NULL); return n; } template T* List::extractPrev(T* ptr) { T* p = ptr->previous(); T* n = ptr->next(); if (p) p->setNext(n); if (n) n->setPrevious(p); if (head_ == ptr) head_ = n; if (tail_ == ptr) tail_ = p; current_ = NULL; count_--; ptr->setNext(NULL); ptr->setPrevious(NULL); return p; } template T* List::operator[](int which) { head(); for (int i=0; i int List::index(T* t) { int cnt=0; head(); while (current_) { if (current_ == t) return cnt; cnt++; next(); } return -1; } template void List::transverse(void (*proc)(T*)) { if (head()) do proc(current_); while (next()); } template class List; template class List; template class List; template class List; template class List; template class List; template class List; template class List; template class List; template class List; template class List; template class List;