/+junk/c_sdl_joypad_ducktape

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/%2Bjunk/c_sdl_joypad_ducktape
7 by Gustav Hartvigsson
* Added licensing information to the files.
1
#include <stdlib.h>
2
3
/*
4
 * This file, as the rest of the project is under MIT license.
5
 * see http://opensource.org/licenses/MIT
8 by Gustav Hartvigsson
* added and changed little in the files Lincening information.
6
 *
7
 * Author Gustav Hartvigsson <gustav.hartvigsson _at_ gmail.com> 2014
7 by Gustav Hartvigsson
* Added licensing information to the files.
8
 */
9
10
/** @file
11
 * Dynamic Array.
12
 *
13
 * This file contains an imlpementation of a "dynamic" array, it is usefule when
14
 * dealing with lare amounts of data that may change over time, or with an
15
 * unknowned numebr of items.
16
 * 
17
 * Note that accsess time is constant, but write time is not guarenteed to be.
18
 * 
19
 * When the size of the array is equal to the number of elements in it, it will
20
 * re-allocate the array with a larger size.
21
 */
22
23
/**
24
 * The padding that is added when expanding the array.
25
 */
26
#define ARRAY_PADDING 8
27
28
/**
29
 * Represents a for each function.
30
 * 
31
 * @param self the dynamic array.
32
 * @param data the data to be passed to the each iteration.
33
 * @returns data to be put in a new DynamicArray, if used with
34
 * dynamic_array_for_each_with_return.
35
 */
36
typedef void * (* ForEachFunc)(DynamicArray * self, void * data);
37
38
/**
39
 * an opaque data structure that represents the dynamic array.
40
 */
41
typedef struct _DynamicArray DynamicArray;
42
43
/**
44
 * Create a new dynamic array.
45
 *
46
 * @param len The length of the initial array.
47
 * @param item_size The size of the items to be stored.
48
 */
49
DymamicArray * dynamic_array_new (size_t len);
50
51
/**
52
 * Frees the dynamic array.
53
 * 
54
 * after this is run the data will be lost.
55
 */
56
void dynamic_array_free (DynamicArray * self);
57
58
59
/**
60
 * Get an item from the array.
61
 */
62
void * dynamic_array_get (DynamicArray * self, int index);
63
64
/**
65
 * Get the length of the array.
66
 */
67
size_t dymanic_array_len (DynamicArray * self);
68
69
70
/**
71
 * Add an item to the array.
72
 */
73
void dynamic_array_add (DynamicArray * self, void * item);
74
75
/**
76
 * Dumps a copy of the. Must be cast.
77
 * 
78
 * Is not freed when the dynamic array is freed.
79
 * 
80
 * Is null-terminated.
81
 */
82
void ** dynamic_array_dump_array (DynamicArray * self);
83
84
/**
85
 * Use a function on the array.
86
 */
87
void dynamic_array_for_each (DynamicArray * self, ForEachFunc func,
88
                             void * data);
89
90
/**
91
 * same as dynamic_array_for_each (), with the difference that it returns a new
92
 * DynamicArray.
93
 */
94
DynamicArray * dynamic_array_for_each_with_return (DynamicArray * self,
95
                                                   ForEachFunc func,
96
                                                   void * data);
97