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 or |
---|
8 | * Jonathan Clark. |
---|
9 | */ |
---|
10 | |
---|
11 | // linked.h - linked list and linked list node classes |
---|
12 | // written June 2, 1992 by Jonathan Clark (at home) |
---|
13 | |
---|
14 | #ifndef __LINKED_H__ |
---|
15 | #define __LINKED_H__ |
---|
16 | |
---|
17 | #include <stdio.h> |
---|
18 | #include <stdlib.h> |
---|
19 | #include <string.h> |
---|
20 | |
---|
21 | class linked_node |
---|
22 | { |
---|
23 | friend class linked_list; |
---|
24 | |
---|
25 | public: |
---|
26 | linked_node() { m_next = m_prev = NULL; } |
---|
27 | virtual ~linked_node() { ; } |
---|
28 | |
---|
29 | inline class linked_node *Next() { return m_next; } |
---|
30 | inline class linked_node *Prev() { return m_prev; } |
---|
31 | inline void SetNext(class linked_node *p) { m_next = p; } |
---|
32 | inline void SetPrev(class linked_node *p) { m_prev = p; } |
---|
33 | |
---|
34 | private: |
---|
35 | class linked_node *m_next, *m_prev; |
---|
36 | }; |
---|
37 | |
---|
38 | // this is the basic class for all linked_list |
---|
39 | // its features should be self-explanatory. |
---|
40 | // openly use the functions listed after the keyword PUBLIC |
---|
41 | // type conversions may be nessary if you derive a class of nodes of your own |
---|
42 | // for example shape is an class derived from linked_node. to add a shape to |
---|
43 | // linked list I have to say mylist.add_end(myshape_pointer); |
---|
44 | // unlink removes a node from the list via pointers but does not deallocate |
---|
45 | // it from the heap |
---|
46 | // the destructor for linked_list will get dispose of all the nodes as |
---|
47 | // well, so if you don't want something deleted then you must unlink |
---|
48 | // it from the list before the destructor is called |
---|
49 | |
---|
50 | class linked_list |
---|
51 | { |
---|
52 | public: |
---|
53 | linked_list(); |
---|
54 | ~linked_list(); |
---|
55 | |
---|
56 | void add_front(class linked_node *p); |
---|
57 | void add_end(class linked_node *p); |
---|
58 | int unlink(linked_node *p); |
---|
59 | |
---|
60 | inline class linked_node *first() { return m_first; } |
---|
61 | inline class linked_node *prev() { return m_first->Prev(); } |
---|
62 | inline size_t Count() { return m_count; } |
---|
63 | |
---|
64 | private: |
---|
65 | linked_node *m_first; |
---|
66 | size_t m_count; |
---|
67 | }; |
---|
68 | |
---|
69 | #endif |
---|
70 | |
---|