aboutsummaryrefslogtreecommitdiff
path: root/src/LinkedList.hh
diff options
context:
space:
mode:
Diffstat (limited to 'src/LinkedList.hh')
-rw-r--r--src/LinkedList.hh131
1 files changed, 131 insertions, 0 deletions
diff --git a/src/LinkedList.hh b/src/LinkedList.hh
new file mode 100644
index 0000000..aa6bc28
--- /dev/null
+++ b/src/LinkedList.hh
@@ -0,0 +1,131 @@
1// LinkedList.hh for Blackbox - an X11 Window manager
2// Copyright (c) 1997 - 2000 Brad Hughes (bhughes@tcac.net)
3//
4// Permission is hereby granted, free of charge, to any person obtaining a
5// copy of this software and associated documentation files (the "Software"),
6// to deal in the Software without restriction, including without limitation
7// the rights to use, copy, modify, merge, publish, distribute, sublicense,
8// and/or sell copies of the Software, and to permit persons to whom the
9// Software is furnished to do so, subject to the following conditions:
10//
11// The above copyright notice and this permission notice shall be included in
12// all copies or substantial portions of the Software.
13//
14// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
17// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
19// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
20// DEALINGS IN THE SOFTWARE.
21
22#ifndef _LINKEDLIST_HH_
23#define _LINKEDLIST_HH_
24
25
26class __llist_node {
27private:
28 __llist_node *next;
29 void *data;
30
31protected:
32
33public:
34 __llist_node(void) { next = (__llist_node *) 0; data = (void *) 0; }
35
36 inline __llist_node *getNext(void) { return next; }
37
38 inline void *getData(void) { return data; }
39 inline void setData(void *d) { data = d; }
40 inline void setNext(__llist_node *n) { next = n; }
41};
42
43
44// forward declaration
45class __llist;
46
47
48class __llist_iterator {
49private:
50 __llist *list;
51 __llist_node *node;
52
53 friend class __llist;
54
55
56protected:
57 __llist_iterator(__llist *);
58 ~__llist_iterator(void);
59
60 const int set(const int);
61
62 void *current(void);
63 void reset(void);
64
65 void operator++(void);
66 void operator++(int);
67};
68
69
70class __llist {
71private:
72 int elements;
73 __llist_node *_first, *_last;
74 __llist *iterators;
75
76 friend class __llist_iterator;
77
78
79protected:
80 __llist(void * = 0);
81 ~__llist(void);
82
83 inline const int &count(void) const { return elements; }
84 inline const int empty(void) const { return (elements == 0); }
85
86 const int insert(void *, int = -1);
87 const int remove(void *);
88
89 void *find(const int);
90 void *remove(const int);
91 void *first(void);
92 void *last(void);
93};
94
95
96template <class Z>
97class LinkedListIterator : public __llist_iterator {
98public:
99 LinkedListIterator(__llist *d = 0) : __llist_iterator(d) { return; }
100
101 inline Z *current(void) { return (Z *) __llist_iterator::current(); }
102
103 inline const int set(const int i) { return __llist_iterator::set(i); }
104
105 inline void reset(void) { __llist_iterator::reset(); }
106
107 inline void operator++(void) { __llist_iterator::operator++(); }
108 inline void operator++(int) { __llist_iterator::operator++(0); }
109};
110
111
112template <class Z>
113class LinkedList : public __llist {
114public:
115 LinkedList(Z *d = 0) : __llist(d) { return; }
116
117 inline Z *find(const int i) { return (Z *) __llist::find(i); }
118 inline Z *remove(const int i) { return (Z *) __llist::remove(i); }
119 inline Z *first(void) { return (Z *) __llist::first(); }
120 inline Z *last(void) { return (Z *) __llist::last(); }
121
122 inline const int count(void) const { return __llist::count(); }
123 inline const int empty(void) const { return __llist::empty(); }
124
125 inline const int insert(Z *d, int i = -1) { return __llist::insert((void *) d, i); }
126 inline const int remove(Z *d) { return __llist::remove((void *) d); }
127};
128
129
130#endif // _LINKEDLIST_HH_
131