]> icculus.org git repositories - mikachu/openbox.git/blob - src/LinkedList.h
converted the remaining LinkedLists in Screen to STL objects.
[mikachu/openbox.git] / src / LinkedList.h
1 // LinkedList.h for Openbox
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
26 class __llist_node {
27 private:
28   __llist_node *next;
29   void *data;
30
31 protected:
32
33 public:
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
45 class __llist;
46
47
48 class __llist_iterator {
49 private:
50   __llist *list;
51   __llist_node *node;
52
53   friend class __llist;
54
55
56 protected:
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
70 class __llist {
71 private:
72   int elements;
73   __llist_node *_first, *_last;
74   __llist *iterators;
75
76   friend class __llist_iterator;
77
78
79 protected:
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
96 template <class Z>
97 class LinkedListIterator : public __llist_iterator {
98 public:
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
112 template <class Z>
113 class LinkedList : public __llist {
114 public:
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