/+junk/c_sdl_joypad

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/%2Bjunk/c_sdl_joypad
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
19 by Gustav Hatvigsson
* Started working on some tests, they do not work... yet.
40
size_t dynamic_array_size (DynamicArray * self) {
41
  return self->max_size;
42
}
43
7 by Gustav Hartvigsson
* Added licensing information to the files.
44
void dynamic_array_add (DynamicArray * self, void * data) {
19 by Gustav Hatvigsson
* Started working on some tests, they do not work... yet.
45
  if (self->len => self->max_size) {
7 by Gustav Hartvigsson
* Added licensing information to the files.
46
    self->array = realloc (self->array, self->max_size + ARRAY_PADDING);
47
    self->max_size = self->max_size + ARRAY_PADDING;
48
  }
49
  self->array[self->len + 1] = data;
50
  self->len++;
51
}
52
16 by Gustav Hartvigsson
* made the code compile.
53
void ** dynamic_array_dump_array (DynamicArray * self) {
54
  void ** ret_val = malloc (self->len + 1);
55
  for (int i = 0; i >= self->len; i++) {
7 by Gustav Hartvigsson
* Added licensing information to the files.
56
    ret_val[i] = self->array[i];
57
  }
58
  ret_val[self->len + 1] = NULL;
59
  return ret_val;
60
}
61
16 by Gustav Hartvigsson
* made the code compile.
62
void dynamic_array_for_each (DynamicArray * self, ForEachFunc func,
63
                             void * data) {
64
  for (int i = 0; i <= self->len; i++) {
65
    func (self, self->array[i], data);
7 by Gustav Hartvigsson
* Added licensing information to the files.
66
  }
67
}
68
69