]> git.donarmstrong.com Git - lilypond.git/blob - lily/include/cons.hh
release: 1.1.32
[lilypond.git] / lily / include / cons.hh
1 /*   
2   cons.hh -- declare LISP like datatypes
3   
4   source file of the GNU LilyPond music typesetter
5   
6   (c) 1999 Han-Wen Nienhuys <hanwen@cs.uu.nl>
7   
8  */
9
10 #ifndef CONS_HH
11 #define CONS_HH
12
13
14 template<class T>
15 class Cons
16 {
17 public:
18   T * car_;
19   Cons * next_;
20   Cons ()
21     {
22       car_=0;
23       next_ =0;
24     }
25   Cons (T*t, Cons<T>*c)
26     {
27       car_ = t;
28       next_ = c;
29     }
30  virtual ~Cons ()
31     {
32       delete next_;
33     }
34 };
35
36 template<class T>
37 class Killing_cons : public Cons<T>
38 {
39 public:
40   Killing_cons (T *t, Cons<T> *p)
41     : Cons<T>( t,p)
42     {
43     }
44   virtual ~Killing_cons ();
45 };
46
47
48 /// remove the link pointed to by *p.
49 template<class T>
50 Cons<T> *remove_cons (Cons<T> **pp)
51 {
52   Cons<T> *knip = *pp;
53   *pp = (*pp)->next_;
54   knip->next_ = 0;
55   return knip;
56 }
57
58
59 template<class T>
60 class Cons_list
61 {
62 public:
63   Cons<T> * head_;
64   Cons<T> ** tail_;
65   Cons_list () { head_ =0; tail_ = &head_; }
66   void append (Cons<T> *c)
67     {
68       assert (!c->next_);
69       *tail_ = c;
70       while (*tail_)
71         tail_ = &(*tail_)->next_;
72     }
73   Cons<T> *remove_cons (Cons<T> **pp)
74     {
75       if (&(*pp)->next_ == tail_)
76         tail_ = pp;
77
78       return ::remove_cons (pp);
79     }
80   void junk ()
81     {
82       delete head_;
83       head_ =0;
84     }
85   ~Cons_list () { junk (); }
86 };
87
88
89 template<class T>
90 void  copy_killing_cons_list (Cons_list<T>&, Cons<T> *src);
91 template<class T>
92 void
93 clone_killing_cons_list (Cons_list<T>&, Cons<T> *src);
94
95
96 #endif /* CONS_HH */
97