/+junk/c_sdl_joypad

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/%2Bjunk/c_sdl_joypad

« back to all changes in this revision

Viewing changes to LinkedList.h

  • Committer: Gustav Hartvigsson
  • Date: 2014-01-11 23:36:14 UTC
  • Revision ID: gustav.hartvigsson@gmail.com-20140111233614-01rmomx08k72qg8q
* added Doxyget file
* started work on Linked List implementation.

Show diffs side-by-side

added added

removed removed

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