X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=flower%2Finclude%2Fcons.hh;h=6830697fb51628fa6b6c662a29490358da145f1a;hb=caae40c5780a1fced18472977250e9d96e5ee22f;hp=8fd58acb7f799b763323b6d94c6808dd91890a4f;hpb=cfb5287829e4c8df689ef42e4367c44e51298dcd;p=lilypond.git diff --git a/flower/include/cons.hh b/flower/include/cons.hh index 8fd58acb7f..6830697fb5 100644 --- a/flower/include/cons.hh +++ b/flower/include/cons.hh @@ -3,7 +3,7 @@ source file of the GNU LilyPond music typesetter - (c) 1999 Han-Wen Nienhuys + (c) 1999--2004 Han-Wen Nienhuys */ @@ -11,7 +11,7 @@ #define CONS_HH -#include +#include template class Cons @@ -40,7 +40,7 @@ class Killing_cons : public Cons { public: Killing_cons (T *t, Cons *p) - : Cons( t,p) + : Cons ( t,p) { } virtual ~Killing_cons (); @@ -57,10 +57,10 @@ Cons *remove_cons (Cons **pp) return knip; } -template int cons_list_size_i (Cons *l) +template int cons_list_size (Cons *l) { int i=0; - while (l) + while (l) { l = l->next_; i++; @@ -75,7 +75,7 @@ template int cons_list_size_i (Cons *l) template Cons * last_cons (Cons * head) { - while (head->next_) + while (head && head->next_) { head = head->next_; } @@ -86,7 +86,7 @@ Cons * last_cons (Cons * head) Invariants: - (*tail_) is either the head_ pointer, or a next_ pointer from the list. + (*tail_) is either the head_ pointer, or a next_ pointer from the list. **tail_ == NULL */ @@ -106,12 +106,16 @@ public: head_ =0; nil_pointer_address_ = &head_; } + void append (T *c) + { + append (new Cons (c,0)); + } void append (Cons *c) { assert (!c->next_); *nil_pointer_address_ = c; while (*nil_pointer_address_) - nil_pointer_address_ = &(*nil_pointer_address_)->next_; + nil_pointer_address_ = & (*nil_pointer_address_)->next_; } /** PRE: *pp should either be the head_ pointer, or the next_ pointer @@ -119,11 +123,29 @@ public: */ Cons *remove_cons (Cons **pp) { - if (&(*pp)->next_ == nil_pointer_address_) + if (& (*pp)->next_ == nil_pointer_address_) nil_pointer_address_ = pp; return ::remove_cons (pp); } + + /// junk everything after the first I elements. + void truncate (int i) + { + Cons **p = &head_; + for (; *p && i; p = & ((*p)->next_)) + { + i--; + } + + if (*p) + { + delete *p; + *p = 0; + } + nil_pointer_address_ = p; + } + void junk () { delete head_; @@ -133,9 +155,9 @@ public: { junk (); } - int size_i () + int size () { - return cons_list_size_i (head_); + return cons_list_size (head_); } };