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