]> git.donarmstrong.com Git - lilypond.git/blobdiff - flower/include/cons.hh
(attachment_point): new function.
[lilypond.git] / flower / include / cons.hh
index 8fd58acb7f799b763323b6d94c6808dd91890a4f..6830697fb51628fa6b6c662a29490358da145f1a 100644 (file)
@@ -3,7 +3,7 @@
   
   source file of the GNU LilyPond music typesetter
   
-  (c) 1999 Han-Wen Nienhuys <hanwen@cs.uu.nl>
+  (c) 1999--2004 Han-Wen Nienhuys <hanwen@cs.uu.nl>
   
  */
 
@@ -11,7 +11,7 @@
 #define CONS_HH
 
 
-#include <assert.h>
+#include <cassert>
 
 template<class T>
 class Cons
@@ -40,7 +40,7 @@ class Killing_cons : public Cons<T>
 {
 public:
   Killing_cons (T *t, Cons<T> *p)
-    : Cons<T>( t,p)
+    : Cons<T> ( t,p)
     {
     }
   virtual ~Killing_cons ();
@@ -57,10 +57,10 @@ Cons<T> *remove_cons (Cons<T> **pp)
   return knip;
 }
 
-template<class T> int cons_list_size_i (Cons<T> *l)
+template<class T> int cons_list_size (Cons<T> *l)
 {
   int i=0;
-  while  (l)
+  while (l)
     {
       l = l->next_;
        i++;
@@ -75,7 +75,7 @@ template<class T> int cons_list_size_i (Cons<T> *l)
 template<class T>
 Cons<T> * last_cons (Cons<T> * head)
 {
-  while (head->next_)
+  while (head && head->next_)
     {
       head = head->next_;
     }
@@ -86,7 +86,7 @@ Cons<T> * last_cons (Cons<T> * 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<T> (c,0));
+    }
   void append (Cons<T> *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<T> *remove_cons (Cons<T> **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<T> **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_);
     }
 };