From a9f6cc535ee5ecd4713ca9a55e08d81aee3aab1a Mon Sep 17 00:00:00 2001 From: fred Date: Thu, 25 Mar 1999 10:16:02 +0000 Subject: [PATCH] lilypond-1.1.37 --- flower/include/cons.hh | 123 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 123 insertions(+) create mode 100644 flower/include/cons.hh diff --git a/flower/include/cons.hh b/flower/include/cons.hh new file mode 100644 index 0000000000..6e62c4c865 --- /dev/null +++ b/flower/include/cons.hh @@ -0,0 +1,123 @@ +/* + cons.hh -- declare LISP like datatypes + + source file of the GNU LilyPond music typesetter + + (c) 1999 Han-Wen Nienhuys + + */ + +#ifndef CONS_HH +#define CONS_HH + + +template +class Cons +{ +public: + T * car_; + Cons * next_; + Cons () + { + car_=0; + next_ =0; + } + Cons (T*t, Cons*c) + { + car_ = t; + next_ = c; + } + virtual ~Cons () + { + delete next_; + } +}; + +template +class Killing_cons : public Cons +{ +public: + Killing_cons (T *t, Cons *p) + : Cons( t,p) + { + } + virtual ~Killing_cons (); +}; + + +/// remove the link pointed to by *p. +template +Cons *remove_cons (Cons **pp) +{ + Cons *knip = *pp; + *pp = (*pp)->next_; + knip->next_ = 0; + return knip; +} + +/** + + Invariants: + + (*tail_) is either the head_ pointer, or a next_ pointer from the list. + + **tail_ == NULL + */ + +template +class Cons_list +{ +public: + Cons * head_; + Cons ** tail_; + Cons_list () { init_list (); } + void init_list () {head_ =0; tail_ = &head_; } + void append (Cons *c) + { + assert (!c->next_); + *tail_ = c; + while (*tail_) + tail_ = &(*tail_)->next_; + } + /** + PRE: *pp should either be the head_ pointer, or the next_ pointer + from a list cell. + */ + Cons *remove_cons (Cons **pp) + { + if (&(*pp)->next_ == tail_) + tail_ = pp; + + return ::remove_cons (pp); + } + void junk () + { + delete head_; + head_ =0; + } + ~Cons_list () { junk (); } +}; + + +template +void copy_killing_cons_list (Cons_list&, Cons *src); +template +void +clone_killing_cons_list (Cons_list&, Cons *src); + +template int cons_list_size_i (Cons *l) +{ + int i=0; + while (l) + { + l = l->next_; + i++; + } + return i; +} + + + + +#endif /* CONS_HH */ + -- 2.39.5