source: abuse/trunk/src/include/isllist_bak.hpp @ 56

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