/+junk/c_sdl_joypad

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/%2Bjunk/c_sdl_joypad

« back to all changes in this revision

Viewing changes to DynamicArray.h

  • Committer: Gustav Hartvigsson
  • Date: 2014-01-05 18:46:44 UTC
  • Revision ID: gustav.hartvigsson@gmail.com-20140105184644-7avawfjmlf0njm6c
* Added licensing information to the files.
* Started work on the JSParser
* Started work on a dynamic array (Untested).

TODO:
* Figure out how to actualy do the JS Parser.
* Firure out how to make the JS Parser interact with the game mainloop, or
  if I should just ditch the mainloop in the C code all together and just
  use JS to do the game stuffs.
    * The first alternative seems the hardest to implement, but would mean
      that it woud be less for the user of the pragram to do.
    * The second would mean less C code and perhaps less speed too.
      
      If I do the things in C I could, hypothetically, do threading later or
      pseudo threading with great effect/speed. Not that that is actually
      any problem on modern system, but non-blocking interaction is good from
      a usability perspective.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#include <stdlib.h>
 
2
 
 
3
/*
 
4
 * This file, as the rest of the project is under MIT license.
 
5
 * see http://opensource.org/licenses/MIT
 
6
 */
 
7
 
 
8
/** @file
 
9
 * Dynamic Array.
 
10
 *
 
11
 * This file contains an imlpementation of a "dynamic" array, it is usefule when
 
12
 * dealing with lare amounts of data that may change over time, or with an
 
13
 * unknowned numebr of items.
 
14
 * 
 
15
 * Note that accsess time is constant, but write time is not guarenteed to be.
 
16
 * 
 
17
 * When the size of the array is equal to the number of elements in it, it will
 
18
 * re-allocate the array with a larger size.
 
19
 */
 
20
 
 
21
/**
 
22
 * The padding that is added when expanding the array.
 
23
 */
 
24
#define ARRAY_PADDING 8
 
25
 
 
26
/**
 
27
 * Represents a for each function.
 
28
 * 
 
29
 * @param self the dynamic array.
 
30
 * @param data the data to be passed to the each iteration.
 
31
 * @returns data to be put in a new DynamicArray, if used with
 
32
 * dynamic_array_for_each_with_return.
 
33
 */
 
34
typedef void * (* ForEachFunc)(DynamicArray * self, void * data);
 
35
 
 
36
/**
 
37
 * an opaque data structure that represents the dynamic array.
 
38
 */
 
39
typedef struct _DynamicArray DynamicArray;
 
40
 
 
41
/**
 
42
 * Create a new dynamic array.
 
43
 *
 
44
 * @param len The length of the initial array.
 
45
 * @param item_size The size of the items to be stored.
 
46
 */
 
47
DymamicArray * dynamic_array_new (size_t len);
 
48
 
 
49
/**
 
50
 * Frees the dynamic array.
 
51
 * 
 
52
 * after this is run the data will be lost.
 
53
 */
 
54
void dynamic_array_free (DynamicArray * self);
 
55
 
 
56
 
 
57
/**
 
58
 * Get an item from the array.
 
59
 */
 
60
void * dynamic_array_get (DynamicArray * self, int index);
 
61
 
 
62
/**
 
63
 * Get the length of the array.
 
64
 */
 
65
size_t dymanic_array_len (DynamicArray * self);
 
66
 
 
67
 
 
68
/**
 
69
 * Add an item to the array.
 
70
 */
 
71
void dynamic_array_add (DynamicArray * self, void * item);
 
72
 
 
73
/**
 
74
 * Dumps a copy of the. Must be cast.
 
75
 * 
 
76
 * Is not freed when the dynamic array is freed.
 
77
 * 
 
78
 * Is null-terminated.
 
79
 */
 
80
void ** dynamic_array_dump_array (DynamicArray * self);
 
81
 
 
82
/**
 
83
 * Use a function on the array.
 
84
 */
 
85
void dynamic_array_for_each (DynamicArray * self, ForEachFunc func,
 
86
                             void * data);
 
87
 
 
88
/**
 
89
 * same as dynamic_array_for_each (), with the difference that it returns a new
 
90
 * DynamicArray.
 
91
 */
 
92
DynamicArray * dynamic_array_for_each_with_return (DynamicArray * self,
 
93
                                                   ForEachFunc func,
 
94
                                                   void * data);
 
95