/+junk/c_sdl_joypad_ducktape

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

« back to all changes in this revision

Viewing changes to src/DynamicArray.h

  • Committer: Gustav Hartvigsson
  • Date: 2014-08-30 21:14:57 UTC
  • Revision ID: gustav.hartvigsson@gmail.com-20140830211457-36050zuhlyy8103g
* Fixed the DynamicArray
* Made the docs better (untested)
* Changes a few names.
* and other things.

Show diffs side-by-side

added added

removed removed

Lines of Context:
6
6
#ifndef __H_DYNAMIC_ARRAY__
7
7
#define __H_DYNAMIC_ARRAY__
8
8
#include <stdlib.h>
 
9
#include "defs.h"
9
10
 
10
11
/*
11
12
 * This file, as the rest of the project is under MIT license.
35
36
/**
36
37
 * an opaque data structure that represents the dynamic array.
37
38
 */
38
 
typedef struct _DynamicArray DynamicArray;
 
39
typedef struct DynamicArray DynamicArray;
39
40
 
 
41
#ifndef __H_DEFS__
40
42
/**
41
43
 * Represents a for each function.
42
44
 * 
43
45
 * @param self the dynamic array.
44
46
 * @param data the data to be passed to the each iteration.
45
 
 * @returns data to be put in a new DynamicArray, if used with
46
 
 * dynamic_array_for_each_with_return.
 
47
 * @returns data to be put in a new \c DynamicArray, if used with
 
48
 *          <tt>dynamic_array_for_each_with_return</tt>.
47
49
 */
48
50
typedef void * (* ForEachFunc)(DynamicArray * self, void * item, void * data);
49
51
 
 
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__ */
50
60
 
51
61
/**
52
62
 * Create a new dynamic array.
53
63
 *
54
64
 * @param len The length of the initial array.
55
 
 * @param item_size The size of the items to be stored.
 
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.
56
71
 */
57
 
DynamicArray * dynamic_array_new (size_t len);
 
72
DynamicArray * dynamic_array_new (size_t len, FreeFunc free_func);
58
73
 
59
74
/**
60
75
 * Frees the dynamic array.
72
87
/**
73
88
 * Get the length of the array.
74
89
 */
75
 
size_t dymanic_array_len (DynamicArray * self);
 
90
size_t dynamic_array_len (DynamicArray * self);
76
91
 
77
92
 
78
93
/**
105
120
void dynamic_array_for_each (DynamicArray * self, ForEachFunc func,
106
121
                             void * data);
107
122
 
108
 
/**
 
123
/** TODO
109
124
 * same as dynamic_array_for_each (), with the difference that it returns a new
110
125
 * DynamicArray.
111
126
 */