source: abuse/trunk/src/isllist.h @ 682

Last change on this file since 682 was 555, checked in by Sam Hocevar, 8 years ago

ps3: make everything compile on the PS3. Of course, nothing links yet
because so much support is missing.

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