1 | /* |
---|
2 | * Abuse - dark 2D side-scrolling platform game |
---|
3 | * Copyright (c) 1995 Crack dot Com |
---|
4 | * |
---|
5 | * This software was released into the Public Domain. As with most public |
---|
6 | * domain software, no warranty is made or implied by Crack dot Com or |
---|
7 | * Jonathan Clark. |
---|
8 | */ |
---|
9 | |
---|
10 | #ifndef ISLLIST_HH |
---|
11 | #define ISLLIST_HH |
---|
12 | |
---|
13 | // "inc/isllist.hpp", line 13.10: 1540-016: (S) protected member "isllist<tcpip_protocol::RequestItem*>::list_node *" cannot be accessed. |
---|
14 | |
---|
15 | template <class T> |
---|
16 | class isllist |
---|
17 | { |
---|
18 | public: |
---|
19 | class list_node |
---|
20 | { |
---|
21 | public: |
---|
22 | list_node * next; |
---|
23 | T data; |
---|
24 | |
---|
25 | list_node() {} |
---|
26 | list_node(const T& item) { data = item; } |
---|
27 | }; |
---|
28 | |
---|
29 | list_node * list; |
---|
30 | |
---|
31 | class iterator |
---|
32 | { |
---|
33 | public: |
---|
34 | // pseudo-protected - don't use unless you really have to |
---|
35 | list_node * node; |
---|
36 | iterator(list_node * p) : node(p) {} |
---|
37 | |
---|
38 | iterator() {} |
---|
39 | iterator(const iterator &p) : node(p.node) {} |
---|
40 | |
---|
41 | int operator==(const iterator &p) { return (node == p.node); } |
---|
42 | int operator!=(const iterator &p) { return (node != p.node); } |
---|
43 | |
---|
44 | iterator& operator++() { node = node->next; return *this; } |
---|
45 | iterator next() { return node->next; } |
---|
46 | |
---|
47 | T& operator*() { return node->data; } |
---|
48 | }; |
---|
49 | |
---|
50 | iterator end() { return (list_node *)(&list); } |
---|
51 | iterator begin_prev() { return end(); } |
---|
52 | iterator begin() { return list; } |
---|
53 | |
---|
54 | int empty() { return begin() == end(); } |
---|
55 | |
---|
56 | iterator insert_next(iterator pos, T& item) |
---|
57 | { |
---|
58 | list_node * p = new list_node(item); |
---|
59 | p->next = pos.node->next; |
---|
60 | pos.node->next = p; |
---|
61 | |
---|
62 | return p; |
---|
63 | } |
---|
64 | |
---|
65 | void erase_next(iterator pos) |
---|
66 | { |
---|
67 | list_node * p = pos.node->next; |
---|
68 | pos.node->next = p->next; |
---|
69 | delete p; |
---|
70 | } |
---|
71 | |
---|
72 | int find_prev(iterator& p, T& item) |
---|
73 | { |
---|
74 | while (p.node->next != end().node) |
---|
75 | { |
---|
76 | if (*(p.next())==item) |
---|
77 | return 1; |
---|
78 | ++p; |
---|
79 | } |
---|
80 | return 0; |
---|
81 | } |
---|
82 | |
---|
83 | void move_next(const iterator&p, const iterator&q) |
---|
84 | { |
---|
85 | list_node * tmp; |
---|
86 | |
---|
87 | tmp = p.node->next; |
---|
88 | if (tmp == q.node) |
---|
89 | return; |
---|
90 | p.node->next = tmp->next; |
---|
91 | tmp->next = q.node->next; |
---|
92 | q.node->next = tmp; |
---|
93 | } |
---|
94 | |
---|
95 | int find(T& item) { iterator p = begin_prev(); return find_prev(p, item); } |
---|
96 | void insert(T& item) { insert_next( begin_prev(), item); } |
---|
97 | void erase() { erase_next( begin_prev() ); } |
---|
98 | |
---|
99 | void erase_all() |
---|
100 | { |
---|
101 | while (!empty()) |
---|
102 | erase(); |
---|
103 | } |
---|
104 | |
---|
105 | isllist() |
---|
106 | { |
---|
107 | list = (list_node *)&list; |
---|
108 | } |
---|
109 | |
---|
110 | ~isllist() |
---|
111 | { |
---|
112 | erase_all(); |
---|
113 | } |
---|
114 | }; |
---|
115 | |
---|
116 | #endif |
---|
117 | |
---|
118 | /* |
---|
119 | "inc/isllist.hpp", line 9.8: 1540-051: (S) A declaration has been made without a type specification. |
---|
120 | "inc/isllist.hpp", line 9.8: 1540-022: (S) "isllist" was previously declared as "type name". |
---|
121 | "inc/isllist.hpp", line 9.1: 1540-377: (I) "isllist" is declared on line 6 of "/u/crack/abuse/inc/isllist.hpp". |
---|
122 | "inc/isllist.hpp", line 16.10: 1540-016: (S) protected member "isllist<tcpip_protocol::RequestItem*>::list_node *" cannot be accessed. |
---|
123 | */ |
---|