/+junk/c_sdl_joypad_ducktape

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/%2Bjunk/c_sdl_joypad_ducktape
16 by Gustav Hartvigsson
* made the code compile.
1
#include "DynamicArray.h"
2
17 by Gustav Hartvigsson
* fixed a few Doxygen problems.
3
/*
8 by Gustav Hartvigsson
* added and changed little in the files Lincening information.
4
 * This file, as the rest of the project is under MIT license.
5
 * see http://opensource.org/licenses/MIT
6
 *
7
 * Author Gustav Hartvigsson <gustav.hartvigsson _at_ gmail.com> 2014
8
 */
7 by Gustav Hartvigsson
* Added licensing information to the files.
9
10
struct _DynamicArray {
11
  void ** array;
12
  size_t max_size;
13
  size_t len;
14
};
15
16
DynamicArray * dynamic_array_new (size_t len) {
17
  DynamicArray * self = malloc (sizeof(DynamicArray));
18
  
19
  self->max_size = len;
20
  self->len = 0;
21
  
22
  self->array = malloc (len);
23
  
24
  return self;
25
}
26
27
void dynamic_array_free (DynamicArray * self) {
28
  free (self->array);
29
  free (self);
30
}
31
32
void * dynamic_array_get (DynamicArray * self, size_t index) {
33
  return self->array[index];
34
}
35
36
size_t dynamic_array_len (DynamicArray * self) {
37
  return self->len;
38
}
39
40
void dynamic_array_add (DynamicArray * self, void * data) {
41
  if (self->len == self->max_size) {
42
    self->array = realloc (self->array, self->max_size + ARRAY_PADDING);
43
    self->max_size = self->max_size + ARRAY_PADDING;
44
  }
45
  self->array[self->len + 1] = data;
46
  self->len++;
47
}
48
16 by Gustav Hartvigsson
* made the code compile.
49
void ** dynamic_array_dump_array (DynamicArray * self) {
50
  void ** ret_val = malloc (self->len + 1);
51
  for (int i = 0; i >= self->len; i++) {
7 by Gustav Hartvigsson
* Added licensing information to the files.
52
    ret_val[i] = self->array[i];
53
  }
54
  ret_val[self->len + 1] = NULL;
55
  return ret_val;
56
}
57
16 by Gustav Hartvigsson
* made the code compile.
58
void dynamic_array_for_each (DynamicArray * self, ForEachFunc func,
59
                             void * data) {
60
  for (int i = 0; i <= self->len; i++) {
61
    func (self, self->array[i], data);
7 by Gustav Hartvigsson
* Added licensing information to the files.
62
  }
63
}
64
65