/+junk/c_sdl_joypad

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