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