/simpletypesystem/trunk

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/simpletypesystem/trunk
5.2.9 by Gustav Hartvigsson
* Added license to files
1
/*
2
Copyright (c) 2013-2014 Gustav Hartvigsson
3
4
Permission is hereby granted, free of charge, to any person obtaining a copy
5
of this software and associated documentation files (the "Software"), to deal
6
in the Software without restriction, including without limitation the rights
7
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8
copies of the Software, and to permit persons to whom the Software is
9
furnished to do so, subject to the following conditions:
10
11
The above copyright notice and this permission notice shall be included in
12
all copies or substantial portions of the Software.
13
14
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20
THE SOFTWARE.
21
*/
5.2.8 by Gustav Hartvigsson
* Copied over LinkedList and DynamicArray from c_sdl_js
22
146 by Gustav Hartvigsson
* Reorderd includes in SimpleTypeSystem.h
23
#pragma once
24
25
5.2.8 by Gustav Hartvigsson
* Copied over LinkedList and DynamicArray from c_sdl_js
26
#include <stdlib.h>
146 by Gustav Hartvigsson
* Reorderd includes in SimpleTypeSystem.h
27
5.2.8 by Gustav Hartvigsson
* Copied over LinkedList and DynamicArray from c_sdl_js
28
#include "defs.h"
30 by Gustav Hartvigsson
* Made the code compile using CMake.
29
#include "Func.h"
5.2.8 by Gustav Hartvigsson
* Copied over LinkedList and DynamicArray from c_sdl_js
30
110 by Gustav Hartvigsson
* added S_ prifix to my macros. I should not be a scrub.
31
S_BEGIN_DECLS
5.2.8 by Gustav Hartvigsson
* Copied over LinkedList and DynamicArray from c_sdl_js
32
33
/** @file
46 by Gustav Hartvigsson
* Renamed DynamicArray to SDynamicArray.
34
 * @defgroup SDynamicArray SDynamicArray
35
 * @addtogroup SDynamicArray SDynamicArray
36
 * @{
5.2.8 by Gustav Hartvigsson
* Copied over LinkedList and DynamicArray from c_sdl_js
37
 *
46 by Gustav Hartvigsson
* Renamed DynamicArray to SDynamicArray.
38
 * SDynamicArray is an imlpementation of a dynamic array, it is usefule when
5.2.8 by Gustav Hartvigsson
* Copied over LinkedList and DynamicArray from c_sdl_js
39
 * dealing with lare amounts of data that may change over time, or with an
40
 * unknowned numebr of items.
103 by Gustav Hartvigsson
* General cleanup/make it pritty.
41
 *
5.2.8 by Gustav Hartvigsson
* Copied over LinkedList and DynamicArray from c_sdl_js
42
 * Note that accsess time is constant, but write time is not guarenteed to be.
103 by Gustav Hartvigsson
* General cleanup/make it pritty.
43
 *
5.2.8 by Gustav Hartvigsson
* Copied over LinkedList and DynamicArray from c_sdl_js
44
 * When the size of the array is equal to the number of elements in it, it will
45
 * re-allocate the array with a larger size.
46
 */
47
48
/**
49
 * The padding that is added when expanding the array.
50
 */
51
#define ARRAY_PADDING 8
52
53
/**
46 by Gustav Hartvigsson
* Renamed DynamicArray to SDynamicArray.
54
 * An SDynamicArray is the standard implementation of a Dynamic Array in SSTS.
55
 *
56
 * It does not depend an SObject, because it should be albe to be used in,
57
 * SObject and SObject based classes.
5.2.8 by Gustav Hartvigsson
* Copied over LinkedList and DynamicArray from c_sdl_js
58
 */
46 by Gustav Hartvigsson
* Renamed DynamicArray to SDynamicArray.
59
typedef struct SDynamicArray SDynamicArray;
60
68 by Gustav Hartvigsson
* Hid internals of SDynamicArray.
61
62
#define S_DYNAMIC_ARRAY(k) ((SDynamicArray *)(k))
53 by Gustav Hartvigsson
* Finnished up s_map_add () ???
63
5.2.8 by Gustav Hartvigsson
* Copied over LinkedList and DynamicArray from c_sdl_js
64
/**
65
 * Create a new dynamic array.
66
 *
67
 * @param len The length of the initial array.
68 by Gustav Hartvigsson
* Hid internals of SDynamicArray.
68
 * @param free_func The function to be used when freeing the items. Can be NULL.
103 by Gustav Hartvigsson
* General cleanup/make it pritty.
69
 *        If free_func is NULL, it will use the standard library's
5.2.8 by Gustav Hartvigsson
* Copied over LinkedList and DynamicArray from c_sdl_js
70
 *       <tt>free()</tt>.
68 by Gustav Hartvigsson
* Hid internals of SDynamicArray.
71
 *
72
 * The free function should have the the signature <tt> (DynamicArray * self,
73
 * spointer item, spointer data) </tt> should be used but cast to FreeFunc.
74
 */
119 by Gustav Hartvigsson
* added S_EXPERTED to public functions.
75
S_EXPORTED
68 by Gustav Hartvigsson
* Hid internals of SDynamicArray.
76
SDynamicArray *
77
s_dynamic_array_new (size_t len,
78
                     FreeFunc free_func);
79
119 by Gustav Hartvigsson
* added S_EXPERTED to public functions.
80
S_EXPORTED
109.1.5 by Gustav Hartvigsson
* Getting closer to fixing the callbacks...
81
SDynamicArray *
82
s_dynamic_array_new_full (size_t len,
83
                          FreeFunc free_func,
84
                          FuncPointer to_json,
85
                          FuncPointer from_json);
86
68 by Gustav Hartvigsson
* Hid internals of SDynamicArray.
87
/**
88
 * Same as s_dynamic_array_new() but with support for to_json and from_json
89
 * methods.
90
 *
91
 * @param to_json This function is used, on an item basis, to serialise the data
92
 *        in that item into a json representation.
93
 *
94
 * @param from_json This function talkes a string and marchal it into an object.
95
 *
96
 * The to_json function should have the signature:
97
 * <tt>char * name (spointer item)</tt> and return a string.
98
 * If this is not set, it will return <tt>"(pointer)"</tt>.
99
 *
100
 * The from_json function should have the signature:
101
 * <tt>spointer name (char * json)</tt>.
102
 * If this function is not set, the s_matrix_deserialize_json() function will
103
 * not work.
104
 */
119 by Gustav Hartvigsson
* added S_EXPERTED to public functions.
105
S_EXPORTED
68 by Gustav Hartvigsson
* Hid internals of SDynamicArray.
106
SDynamicArray *
107
s_dynamic_array_new_json (size_t len,
108
                          FreeFunc free_func,
109
                          FuncPointer to_json,
110
                          FuncPointer from_json);
5.2.8 by Gustav Hartvigsson
* Copied over LinkedList and DynamicArray from c_sdl_js
111
112
/**
113
 * Frees the dynamic array.
103 by Gustav Hartvigsson
* General cleanup/make it pritty.
114
 *
5.2.8 by Gustav Hartvigsson
* Copied over LinkedList and DynamicArray from c_sdl_js
115
 * after this is run the data will be lost.
116
 */
119 by Gustav Hartvigsson
* added S_EXPERTED to public functions.
117
S_EXPORTED
61 by Gustav Hartvigsson
* Made the code more easy to read.
118
void
103 by Gustav Hartvigsson
* General cleanup/make it pritty.
119
s_dynamic_array_free (SDynamicArray * self,
140 by Gustav Hartvigsson
* Added Better comments to SRingBuffer
120
                      sboolean free_data);
5.2.8 by Gustav Hartvigsson
* Copied over LinkedList and DynamicArray from c_sdl_js
121
122
123
/**
124
 * Get an item from the array.
125
 */
61 by Gustav Hartvigsson
* Made the code more easy to read.
126
spointer
103 by Gustav Hartvigsson
* General cleanup/make it pritty.
127
s_dynamic_array_get (SDynamicArray * self,
150 by Gustav Hartvigsson
* Fixed the tests in the CMake file
128
                     size_t index);
5.2.8 by Gustav Hartvigsson
* Copied over LinkedList and DynamicArray from c_sdl_js
129
130
/**
103 by Gustav Hartvigsson
* General cleanup/make it pritty.
131
 * Set an item at index.
132
 *
133
 * @param self The Dynamic Array to set the item on.
134
 * @param index The index at which to set the item.
135
 * @para item The item to put in the array.
136
 */
119 by Gustav Hartvigsson
* added S_EXPERTED to public functions.
137
S_EXPORTED
103 by Gustav Hartvigsson
* General cleanup/make it pritty.
138
void
139
s_dynamic_array_set (SDynamicArray * self,
140 by Gustav Hartvigsson
* Added Better comments to SRingBuffer
140
                     size_t index,
141
                     spointer item);
103 by Gustav Hartvigsson
* General cleanup/make it pritty.
142
/**
143
 * Append an item to a dynamic array.
144
 * @note The item will not be added to the first free slot in the array, but
145
 *       in the first slot after the last item.
146
 *
147
 * @param self The dynamic array to add the item to.
148
 * @param item The item to add.
149
 */
119 by Gustav Hartvigsson
* added S_EXPERTED to public functions.
150
S_EXPORTED
103 by Gustav Hartvigsson
* General cleanup/make it pritty.
151
void
152
s_dynamic_array_append (SDynamicArray * self,
140 by Gustav Hartvigsson
* Added Better comments to SRingBuffer
153
                        spointer item);
5.2.8 by Gustav Hartvigsson
* Copied over LinkedList and DynamicArray from c_sdl_js
154
155
/**
156
 * Get the size of the array, this is not the same as the length of the array.
157
 * The size is the number of elements that can be allocated without resizing
158
 * the array.
103 by Gustav Hartvigsson
* General cleanup/make it pritty.
159
 *
46 by Gustav Hartvigsson
* Renamed DynamicArray to SDynamicArray.
160
 * To get the length of the array use s_dynamic_array_len ().
5.2.8 by Gustav Hartvigsson
* Copied over LinkedList and DynamicArray from c_sdl_js
161
 */
119 by Gustav Hartvigsson
* added S_EXPERTED to public functions.
162
S_EXPORTED
61 by Gustav Hartvigsson
* Made the code more easy to read.
163
size_t
164
s_dynamic_array_size (SDynamicArray * self);
5.2.8 by Gustav Hartvigsson
* Copied over LinkedList and DynamicArray from c_sdl_js
165
166
/**
47 by Gustav Hartvigsson
* Added a few skeletal functions to Callback.h
167
 * Get the index of the last item in the array.
168
 *
169
 * @note
170
 * This is not the last item added to the array, necessary, it is the index
69 by Gustav Hartvigsson
* Finished of SMap... Sort of...
171
 * of the item that has the highest position in the array.
5.2.8 by Gustav Hartvigsson
* Copied over LinkedList and DynamicArray from c_sdl_js
172
 */
119 by Gustav Hartvigsson
* added S_EXPERTED to public functions.
173
S_EXPORTED
61 by Gustav Hartvigsson
* Made the code more easy to read.
174
size_t
175
s_dynamic_array_last_item (SDynamicArray * self);
5.2.8 by Gustav Hartvigsson
* Copied over LinkedList and DynamicArray from c_sdl_js
176
177
/**
150 by Gustav Hartvigsson
* Fixed the tests in the CMake file
178
 * Dumps a truncation copy of the array. Must be cast.
179
 *
180
 * @param self The Dynamic Array to dump.
181
 * @param out_size Where the size of the array is stored.
182
 *
183
 * @note Freed by caller.
184
 *
185
 * @warning You can not use s_dynamic_array_len to get the length output array.
186
 *
5.2.8 by Gustav Hartvigsson
* Copied over LinkedList and DynamicArray from c_sdl_js
187
 */
119 by Gustav Hartvigsson
* added S_EXPERTED to public functions.
188
S_EXPORTED
61 by Gustav Hartvigsson
* Made the code more easy to read.
189
spointer *
150 by Gustav Hartvigsson
* Fixed the tests in the CMake file
190
s_dynamic_array_dump_array (SDynamicArray * self, size_t * out_size);
5.2.8 by Gustav Hartvigsson
* Copied over LinkedList and DynamicArray from c_sdl_js
191
192
/**
193
 * Use a function on the array.
194
 */
119 by Gustav Hartvigsson
* added S_EXPERTED to public functions.
195
S_EXPORTED
61 by Gustav Hartvigsson
* Made the code more easy to read.
196
void
197
s_dynamic_array_for_each (SDynamicArray * self, ForEachFunc func,
68 by Gustav Hartvigsson
* Hid internals of SDynamicArray.
198
                          spointer data);
5.2.8 by Gustav Hartvigsson
* Copied over LinkedList and DynamicArray from c_sdl_js
199
150 by Gustav Hartvigsson
* Fixed the tests in the CMake file
200
5.2.8 by Gustav Hartvigsson
* Copied over LinkedList and DynamicArray from c_sdl_js
201
46 by Gustav Hartvigsson
* Renamed DynamicArray to SDynamicArray.
202
/** @} */
203
110 by Gustav Hartvigsson
* added S_ prifix to my macros. I should not be a scrub.
204
S_END_DECLS