/+junk/c_sdl_joypad_ducktape

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