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 |
||
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> |
26
by Gustav Hartvigsson
* Fixed the DynamicArray |
9 |
#include "defs.h" |
7
by Gustav Hartvigsson
* Added licensing information to the files. |
10 |
|
34
by Gustav Hartvigsson
* Fixed more problem with Doxygen. |
11 |
/* This file, as the rest of the project is under MIT license.
|
7
by Gustav Hartvigsson
* Added licensing information to the files. |
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 |
*/
|
|
26
by Gustav Hartvigsson
* Fixed the DynamicArray |
38 |
typedef struct DynamicArray DynamicArray; |
16
by Gustav Hartvigsson
* made the code compile. |
39 |
|
27
by Gustav Hartvigsson
* Started working on the an object baseclass to make things |
40 |
#if 0
|
26
by Gustav Hartvigsson
* Fixed the DynamicArray |
41 |
#ifndef __H_DEFS__
|
16
by Gustav Hartvigsson
* made the code compile. |
42 |
/**
|
7
by Gustav Hartvigsson
* Added licensing information to the files. |
43 |
* Represents a for each function.
|
44 |
*
|
|
45 |
* @param self the dynamic array.
|
|
46 |
* @param data the data to be passed to the each iteration.
|
|
26
by Gustav Hartvigsson
* Fixed the DynamicArray |
47 |
* @returns data to be put in a new \c DynamicArray, if used with
|
48 |
* <tt>dynamic_array_for_each_with_return</tt>.
|
|
7
by Gustav Hartvigsson
* Added licensing information to the files. |
49 |
*/
|
29
by Gustav Hartvigsson
* Fixed Makefile |
50 |
typedef _pointer (* ForEachFunc)(DynamicArray * self, _pointer item, _pointer data);
|
7
by Gustav Hartvigsson
* Added licensing information to the files. |
51 |
|
26
by Gustav Hartvigsson
* Fixed the DynamicArray |
52 |
/**
|
53 |
* Represents a function to be used when freeing some item in a dynamic array.
|
|
54 |
*
|
|
55 |
* @param obj The object to be freed.
|
|
56 |
*/
|
|
29
by Gustav Hartvigsson
* Fixed Makefile |
57 |
typedef _pointer (* FreeFunc)(_pointer obj);
|
26
by Gustav Hartvigsson
* Fixed the DynamicArray |
58 |
|
59 |
#endif /* __H_DEFS__ */
|
|
27
by Gustav Hartvigsson
* Started working on the an object baseclass to make things |
60 |
#endif /* #if 0*/
|
7
by Gustav Hartvigsson
* Added licensing information to the files. |
61 |
|
62 |
/**
|
|
63 |
* Create a new dynamic array.
|
|
64 |
*
|
|
65 |
* @param len The length of the initial array.
|
|
26
by Gustav Hartvigsson
* Fixed the DynamicArray |
66 |
* @param free_func The function to be used when freeing the items. Can be \c NULL.
|
67 |
* If free_func is NULL, it will use the standard library's
|
|
68 |
* <tt>free()</tt>.
|
|
69 |
*
|
|
70 |
* Normally a function with the signature <tt> (DynamicArray * self,
|
|
29
by Gustav Hartvigsson
* Fixed Makefile |
71 |
_pointer item, _pointer data) </tt> should be used but cast to FreeFunc.
|
7
by Gustav Hartvigsson
* Added licensing information to the files. |
72 |
*/
|
26
by Gustav Hartvigsson
* Fixed the DynamicArray |
73 |
DynamicArray * dynamic_array_new (size_t len, FreeFunc free_func); |
7
by Gustav Hartvigsson
* Added licensing information to the files. |
74 |
|
75 |
/**
|
|
76 |
* Frees the dynamic array.
|
|
77 |
*
|
|
78 |
* after this is run the data will be lost.
|
|
79 |
*/
|
|
80 |
void dynamic_array_free (DynamicArray * self); |
|
81 |
||
82 |
||
83 |
/**
|
|
84 |
* Get an item from the array.
|
|
85 |
*/
|
|
29
by Gustav Hartvigsson
* Fixed Makefile |
86 |
_pointer dynamic_array_get (DynamicArray * self, size_t index); |
7
by Gustav Hartvigsson
* Added licensing information to the files. |
87 |
|
88 |
/**
|
|
89 |
* Get the length of the array.
|
|
90 |
*/
|
|
26
by Gustav Hartvigsson
* Fixed the DynamicArray |
91 |
size_t dynamic_array_len (DynamicArray * self); |
7
by Gustav Hartvigsson
* Added licensing information to the files. |
92 |
|
93 |
||
94 |
/**
|
|
19
by Gustav Hatvigsson
* Started working on some tests, they do not work... yet. |
95 |
* Get the size of the array, this is not the same as the length of the array.
|
96 |
* The size is the number of elements that can be allocated without resizing
|
|
97 |
* the array.
|
|
98 |
*
|
|
99 |
* To get the length of the array use dynamic_array_len ().
|
|
100 |
*/
|
|
101 |
size_t dynamic_array_size (DynamicArray * self); |
|
102 |
||
103 |
||
104 |
/**
|
|
7
by Gustav Hartvigsson
* Added licensing information to the files. |
105 |
* Add an item to the array.
|
106 |
*/
|
|
29
by Gustav Hartvigsson
* Fixed Makefile |
107 |
void dynamic_array_add (DynamicArray * self, _pointer item); |
7
by Gustav Hartvigsson
* Added licensing information to the files. |
108 |
|
109 |
/**
|
|
19
by Gustav Hatvigsson
* Started working on some tests, they do not work... yet. |
110 |
* Dumps a copy of the array. Must be cast.
|
7
by Gustav Hartvigsson
* Added licensing information to the files. |
111 |
*
|
112 |
* Is not freed when the dynamic array is freed.
|
|
113 |
*
|
|
114 |
* Is null-terminated.
|
|
115 |
*/
|
|
29
by Gustav Hartvigsson
* Fixed Makefile |
116 |
_pointer* dynamic_array_dump_array (DynamicArray * self); |
7
by Gustav Hartvigsson
* Added licensing information to the files. |
117 |
|
118 |
/**
|
|
119 |
* Use a function on the array.
|
|
120 |
*/
|
|
121 |
void dynamic_array_for_each (DynamicArray * self, ForEachFunc func, |
|
29
by Gustav Hartvigsson
* Fixed Makefile |
122 |
_pointer data); |
7
by Gustav Hartvigsson
* Added licensing information to the files. |
123 |
|
26
by Gustav Hartvigsson
* Fixed the DynamicArray |
124 |
/** TODO
|
7
by Gustav Hartvigsson
* Added licensing information to the files. |
125 |
* same as dynamic_array_for_each (), with the difference that it returns a new
|
126 |
* DynamicArray.
|
|
127 |
*/
|
|
128 |
DynamicArray * dynamic_array_for_each_with_return (DynamicArray * self, |
|
129 |
ForEachFunc func, |
|
29
by Gustav Hartvigsson
* Fixed Makefile |
130 |
_pointer data); |
7
by Gustav Hartvigsson
* Added licensing information to the files. |
131 |
|
16
by Gustav Hartvigsson
* made the code compile. |
132 |
#endif /* #define __H_DYNAMIC_ARRAY__ */ |