2568
|
1 // This may look like C code, but it is really -*- C++ -*- |
|
2 /* |
|
3 Copyright (C) 1988, 1992 Free Software Foundation |
|
4 written by Doug Lea (dl@rocky.oswego.edu) |
|
5 |
|
6 This file is part of the GNU C++ Library. This library is free |
|
7 software; you can redistribute it and/or modify it under the terms of |
|
8 the GNU Library General Public License as published by the Free |
|
9 Software Foundation; either version 2 of the License, or (at your |
|
10 option) any later version. This library is distributed in the hope |
|
11 that it will be useful, but WITHOUT ANY WARRANTY; without even the |
|
12 implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR |
|
13 PURPOSE. See the GNU Library General Public License for more details. |
|
14 You should have received a copy of the GNU Library General Public |
|
15 License along with this library; if not, write to the Free Software |
|
16 Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
|
17 */ |
|
18 |
|
19 #ifndef _SLList_h |
|
20 #define _SLList_h 1 |
|
21 |
2580
|
22 #if defined (__GNUG__) |
|
23 #pragma interface |
|
24 #endif |
|
25 |
2568
|
26 #include <Pix.h> |
2616
|
27 |
|
28 #include "BaseSLList.h" |
2568
|
29 |
|
30 template<class T> |
3585
|
31 class |
|
32 SLNode : public BaseSLNode |
2568
|
33 { |
|
34 public: |
|
35 T hd; // Data part of node |
|
36 SLNode() { } |
|
37 SLNode(const T& h, SLNode* t = 0) |
|
38 : hd(h) { tl = t; } |
|
39 ~SLNode() { } |
|
40 }; |
|
41 |
|
42 template <class T> |
3585
|
43 class |
|
44 SLList : public BaseSLList |
2568
|
45 { |
|
46 private: |
|
47 virtual void delete_node(BaseSLNode *node) { delete (SLNode<T>*)node; } |
|
48 virtual BaseSLNode* copy_node(const void *datum) |
|
49 { return new SLNode<T>(*(const T*)datum); } |
|
50 virtual void copy_item(void *dst, void *src) { *(T*)dst = *(T*)src; } |
|
51 |
|
52 public: |
|
53 SLList() : BaseSLList() { } |
|
54 SLList(const SLList<T>& a) : BaseSLList() { copy(a); } |
|
55 SLList<T>& operator = (const SLList<T>& a) |
|
56 { BaseSLList::operator=((const BaseSLList&) a); return *this; } |
2580
|
57 ~SLList (void); |
2568
|
58 |
|
59 Pix prepend(const T& item) {return BaseSLList::prepend(&item);} |
|
60 Pix append(const T& item) {return BaseSLList::append(&item);} |
|
61 Pix prepend(SLNode<T>* node) {return BaseSLList::prepend(node);} |
|
62 Pix append(SLNode<T>* node) {return BaseSLList::append(node);} |
|
63 |
|
64 T& operator () (Pix p) { |
|
65 if (p == 0) error("null Pix"); |
|
66 return ((SLNode<T>*)(p))->hd; } |
|
67 const T& operator () (Pix p) const { |
|
68 if (p == 0) error("null Pix"); |
|
69 return ((SLNode<T>*)(p))->hd; } |
|
70 inline Pix first() const { return (last == 0) ? 0 : Pix(last->tl); } |
|
71 void next(Pix& p) const |
|
72 { p = (p == 0 || p == last) ? 0 : Pix(((SLNode<T>*)(p))->tl); } |
|
73 Pix ins_after(Pix p, const T& item) |
|
74 { return BaseSLList::ins_after(p, &item); } |
|
75 void join(SLList<T>& a) { BaseSLList::join(a); } |
|
76 |
|
77 T& front() { |
|
78 if (last == 0) error("front: empty list"); |
|
79 return ((SLNode<T>*)last->tl)->hd; } |
|
80 T& rear() { |
|
81 if (last == 0) error("rear: empty list"); |
|
82 return ((SLNode<T>*)last)->hd; } |
|
83 const T& front() const { |
|
84 if (last == 0) error("front: empty list"); |
|
85 return ((SLNode<T>*)last->tl)->hd; } |
|
86 const T& rear() const { |
|
87 if (last == 0) error("rear: empty list"); |
|
88 return ((SLNode<T>*)last)->hd; } |
|
89 int remove_front(T& x) { return BaseSLList::remove_front(&x); } |
|
90 T remove_front() { T dst; BaseSLList::remove_front(&dst, 1); return dst; } |
|
91 }; |
|
92 |
|
93 #endif |
|
94 |
|
95 /* |
|
96 ;;; Local Variables: *** |
|
97 ;;; mode: C++ *** |
|
98 ;;; End: *** |
|
99 */ |