From c5001d89b80c73e8edcff4ed3a9db715ad9c86ca Mon Sep 17 00:00:00 2001 From: fred Date: Sat, 30 Nov 1996 10:59:51 +0000 Subject: [PATCH] flower-1.0.18 --- flower/list.tcc | 113 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 113 insertions(+) create mode 100644 flower/list.tcc diff --git a/flower/list.tcc b/flower/list.tcc new file mode 100644 index 0000000000..55e1e20507 --- /dev/null +++ b/flower/list.tcc @@ -0,0 +1,113 @@ +#ifndef LIST_CC +#define LIST_CC + +#include "list.hh" + +template +List::List(List const&src) +{ + set_empty(); + // probably el stupido + for (Cursor c(src); c.ok(); c++) + bottom().add(c); +} + +template +void +List::OK() const +{ + int i = size_; + Link *lp = top_; + while (i--) { + assert(lp); + lp->OK(); + lp = lp->next(); + } + assert(!lp); + i = size_; + lp = bottom_; + while (i--) { + assert(lp); + lp->OK(); + lp = lp->previous(); + } + assert(!lp); +} + + +template +List::~List() +{ + Cursor next(*this); + for ( Cursor c( *this ); c.ok(); c = next ) { + next = c; + next++; + remove( c ); + } +} + +template +void +List::add( const T& thing, Cursor &after_me ) +{ + if (!size_) { // not much choice if list is empty + bottom_ = top_ = new Link( thing ); + if (!after_me.ok()) + after_me = bottom(); + } else { // add at aprioprate place + if (!after_me.ok()) + after_me = bottom(); + Link *p =after_me.pointer(); + p->add(thing); + if (p == bottom_) // adjust bottom_ if necessary. + bottom_ = p->next(); + } + + size_++; +} +/** + + Procedure: + \begin{itemize} + \item if #after_me# is #ok()#, add after #after_me#, else + \item if list !empty simply add to bottom, else + \item list is empty: create first \Ref{Link} and initialize + #bottom_# and #top_#. + \end{itemize} +*/ + +template +void +List::insert( const T& thing, Cursor &before_me ) +{ + if (!size_) { + bottom_ = top_ = new Link( thing ); + if (!before_me.ok()) + before_me = top(); + + } else { + if (!before_me.ok()) + before_me = top(); + + Link *p = before_me.pointer() ; + + p->insert(thing); + if (p == top_) + top_ = p->previous(); + } + + size_++; +} + + +template +void +List::concatenate(List const&s) +{ + Cursor b(bottom()); + for (Cursor c(s); c.ok(); c++) { + b.add(c); + b++; + } +} +#endif -- 2.39.5