source: abuse/tags/pd/abuse/inc/isllist.hpp @ 49

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