/+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
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
 */
16 by Gustav Hartvigsson
* made the code compile.
50
typedef void * (* ForEachFunc)(DynamicArray * self, void * item, void * 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
 */
57
typedef void * (* FreeFunc)(void * obj);
58
59
#endif /* __H_DEFS__ */
7 by Gustav Hartvigsson
* Added licensing information to the files.
60
61
/**
62
 * Create a new dynamic array.
63
 *
64
 * @param len The length of the initial array.
26 by Gustav Hartvigsson
* Fixed the DynamicArray
65
 * @param free_func The function to be used when freeing the items. Can be \c NULL.
66
 *        If free_func is NULL, it will use the standard library's 
67
 *       <tt>free()</tt>.
68
 *        
69
 *        Normally a function with the signature <tt> (DynamicArray * self,
70
          void * item, void * data) </tt> should be used but cast to FreeFunc.
7 by Gustav Hartvigsson
* Added licensing information to the files.
71
 */
26 by Gustav Hartvigsson
* Fixed the DynamicArray
72
DynamicArray * dynamic_array_new (size_t len, FreeFunc free_func);
7 by Gustav Hartvigsson
* Added licensing information to the files.
73
74
/**
75
 * Frees the dynamic array.
76
 * 
77
 * after this is run the data will be lost.
78
 */
79
void dynamic_array_free (DynamicArray * self);
80
81
82
/**
83
 * Get an item from the array.
84
 */
16 by Gustav Hartvigsson
* made the code compile.
85
void * dynamic_array_get (DynamicArray * self, size_t index);
7 by Gustav Hartvigsson
* Added licensing information to the files.
86
87
/**
88
 * Get the length of the array.
89
 */
26 by Gustav Hartvigsson
* Fixed the DynamicArray
90
size_t dynamic_array_len (DynamicArray * self);
7 by Gustav Hartvigsson
* Added licensing information to the files.
91
92
93
/**
19 by Gustav Hatvigsson
* Started working on some tests, they do not work... yet.
94
 * Get the size of the array, this is not the same as the length of the array.
95
 * The size is the number of elements that can be allocated without resizing
96
 * the array.
97
 * 
98
 * To get the length of the array use dynamic_array_len ().
99
 */
100
size_t dynamic_array_size (DynamicArray * self);
101
102
103
/**
7 by Gustav Hartvigsson
* Added licensing information to the files.
104
 * Add an item to the array.
105
 */
106
void dynamic_array_add (DynamicArray * self, void * item);
107
108
/**
19 by Gustav Hatvigsson
* Started working on some tests, they do not work... yet.
109
 * Dumps a copy of the array. Must be cast.
7 by Gustav Hartvigsson
* Added licensing information to the files.
110
 * 
111
 * Is not freed when the dynamic array is freed.
112
 * 
113
 * Is null-terminated.
114
 */
115
void ** dynamic_array_dump_array (DynamicArray * self);
116
117
/**
118
 * Use a function on the array.
119
 */
120
void dynamic_array_for_each (DynamicArray * self, ForEachFunc func,
121
                             void * data);
122
26 by Gustav Hartvigsson
* Fixed the DynamicArray
123
/** TODO
7 by Gustav Hartvigsson
* Added licensing information to the files.
124
 * same as dynamic_array_for_each (), with the difference that it returns a new
125
 * DynamicArray.
126
 */
127
DynamicArray * dynamic_array_for_each_with_return (DynamicArray * self,
128
                                                   ForEachFunc func,
129
                                                   void * data);
130
16 by Gustav Hartvigsson
* made the code compile.
131
#endif /* #define __H_DYNAMIC_ARRAY__ */