bzr branch
http://gegoxaren.bato24.eu/bzr/%2Bjunk/c_sdl_joypad_ducktape
21
by Gustav Hatvigsson
* added Modeline to (almost) all files. |
1 |
/* c-basic-offset: 2; tab-width: 2; indent-tabs-mode: nil
|
2 |
* vi: set shiftwidth=2 tabstop=2 expandtab:
|
|
3 |
* :indentSize=2:tabSize=2:noTabs=true:
|
|
4 |
*/
|
|
5 |
||
13
by Gustav Hartvigsson
* added Doxyget file |
6 |
#ifndef __H_LINKED_LIST__
|
7 |
#define __H_LINKED_LIST__
|
|
8 |
||
9 |
#include <stdlib.h> |
|
10 |
#include <stdbool.h> |
|
11 |
||
12 |
/**
|
|
13 |
* This file, as the rest of the project is under MIT license.
|
|
14 |
* see http://opensource.org/licenses/MIT
|
|
15 |
*
|
|
16 |
* Author Gustav Hartvigsson <gustav.hartvigsson _at_ gmail.com> 2014
|
|
17 |
*/
|
|
18 |
||
19 |
/** @file
|
|
20 |
* A LinkedList represents a linked list. A linked list is an efficient data
|
|
21 |
* structure. It is not posible to index a linked list.
|
|
22 |
*/
|
|
23 |
||
24 |
/**
|
|
25 |
* Represents an object in a LinkedList.
|
|
26 |
*/
|
|
27 |
typedef struct LinkedListNode { |
|
28 |
LinkedListNode * prev; |
|
29 |
LinkedListNode * next; |
|
30 |
void * data; |
|
31 |
} LinkedListNode; |
|
32 |
||
33 |
/**
|
|
34 |
* A linked list is a data stucture that holds information in a non-idexible
|
|
35 |
* way. It is good when the objects in the list in verry mutable, but has a
|
|
36 |
* linear search time.
|
|
37 |
*/
|
|
38 |
typedef struct LinkedList { |
|
39 |
size_t len; /**< The length of the list, may be wrong.*/ |
|
40 |
void (* free_func)(void *); /**< The function that frees the data. */ |
|
41 |
LinkedListNode * head; /**< head->prev must be NULL */ |
|
42 |
LinkedListNode * tail; /**< tail->next must be NULL */ |
|
43 |
LinkedListNode * current; /**< Represents the curret object*/ |
|
44 |
} LinkedList; |
|
45 |
||
46 |
/**
|
|
47 |
* Create a new linked list.
|
|
48 |
*
|
|
49 |
* @param free_func the function to be used when freeing a linked list,
|
|
50 |
* if it is NULL the free func will be set to the standard free() function.
|
|
51 |
*/
|
|
52 |
LinkedList * linked_list_new (void (* free_func)(void *)); |
|
53 |
||
54 |
/**
|
|
55 |
* frees a linked list.
|
|
56 |
*
|
|
57 |
* @param self the linked list to free.
|
|
58 |
* @param free_data default:true, wether or not to free the data in the list
|
|
59 |
* as well as the list.
|
|
60 |
*/
|
|
21
by Gustav Hatvigsson
* added Modeline to (almost) all files. |
61 |
void linked_list_free (LinkedList * self, bool free_data); |
13
by Gustav Hartvigsson
* added Doxyget file |
62 |
|
63 |
/**
|
|
64 |
* Add an item to a linked list.
|
|
65 |
*
|
|
66 |
* @param self the list to add an itme to.
|
|
67 |
* @param data the data to be stored.
|
|
68 |
*/
|
|
69 |
void linked_list_add (LinkedList * self, void * data); |
|
70 |
||
71 |
/**
|
|
72 |
* Iterate to the next item. This function does not return anything.
|
|
73 |
*
|
|
74 |
* @param self the list to iterate over.
|
|
75 |
*/
|
|
76 |
void linked_list_next (LinkedList * self); |
|
77 |
||
78 |
/**
|
|
79 |
* Iterate to the provious item. This function does not return anything.
|
|
80 |
*
|
|
81 |
* @param self the list to iterate over.
|
|
82 |
*/
|
|
83 |
void linked_list_pev (LinkedList * self); |
|
84 |
||
85 |
/**
|
|
86 |
* Get the current item.
|
|
87 |
*/
|
|
88 |
void * linked_list_get_current (LinkedList * self); |
|
89 |
||
90 |
/**
|
|
91 |
* Get the next item.
|
|
92 |
*/
|
|
93 |
void * linked_list_get_next (LinkedList * self); |
|
94 |
||
95 |
/**
|
|
96 |
* Get previous item.
|
|
97 |
*/
|
|
98 |
void * linked_list_get_prev (LinkedList * self); |
|
99 |
||
100 |
/**
|
|
101 |
* Wind the list to the head (start).
|
|
102 |
*/
|
|
103 |
void linked_list_head (LinkedList * self); |
|
104 |
||
105 |
/**
|
|
106 |
* Wind the the list to the tail (end).
|
|
107 |
*/
|
|
108 |
void linked_list_tail (LinkedList * self); |
|
109 |
||
110 |
/**
|
|
111 |
* Get the length of the list.
|
|
112 |
*
|
|
113 |
* @warning the value may be wrong.
|
|
114 |
*/
|
|
115 |
size_t linked_list_len (LinkedList * self); |
|
116 |
||
21
by Gustav Hatvigsson
* added Modeline to (almost) all files. |
117 |
/**
|
118 |
* Romoves the cerrunt object useing the free function provided when
|
|
119 |
* creating the list in linked_list_new ().
|
|
120 |
*/
|
|
121 |
void linked_list_remove_current (LinkedList * self); |
|
122 |
||
13
by Gustav Hartvigsson
* added Doxyget file |
123 |
#endif /* __H_LINKED_LIST__ */ |