/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
23
#ifndef __H_DYNAMIC_ARRAY__
24
#define __H_DYNAMIC_ARRAY__
25
#include <stdlib.h>
26
#include "defs.h"
30 by Gustav Hartvigsson
* Made the code compile using CMake.
27
#include "Func.h"
5.2.8 by Gustav Hartvigsson
* Copied over LinkedList and DynamicArray from c_sdl_js
28
5.2.9 by Gustav Hartvigsson
* Added license to files
29
BEGIN_DECLS
5.2.8 by Gustav Hartvigsson
* Copied over LinkedList and DynamicArray from c_sdl_js
30
31
/** @file
46 by Gustav Hartvigsson
* Renamed DynamicArray to SDynamicArray.
32
 * @defgroup SDynamicArray SDynamicArray
33
 * @addtogroup SDynamicArray SDynamicArray
34
 * @{
5.2.8 by Gustav Hartvigsson
* Copied over LinkedList and DynamicArray from c_sdl_js
35
 *
46 by Gustav Hartvigsson
* Renamed DynamicArray to SDynamicArray.
36
 * 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
37
 * dealing with lare amounts of data that may change over time, or with an
38
 * unknowned numebr of items.
39
 * 
40
 * Note that accsess time is constant, but write time is not guarenteed to be.
41
 * 
42
 * When the size of the array is equal to the number of elements in it, it will
43
 * re-allocate the array with a larger size.
44
 */
45
46
/**
47
 * The padding that is added when expanding the array.
48
 */
49
#define ARRAY_PADDING 8
50
51
/**
46 by Gustav Hartvigsson
* Renamed DynamicArray to SDynamicArray.
52
 * An SDynamicArray is the standard implementation of a Dynamic Array in SSTS.
53
 *
54
 * It does not depend an SObject, because it should be albe to be used in,
55
 * SObject and SObject based classes.
5.2.8 by Gustav Hartvigsson
* Copied over LinkedList and DynamicArray from c_sdl_js
56
 */
46 by Gustav Hartvigsson
* Renamed DynamicArray to SDynamicArray.
57
typedef struct SDynamicArray SDynamicArray;
58
59
typedef struct SDynamicArrayPrivate SDynamicArrayPrivate;
60
61 by Gustav Hartvigsson
* Made the code more easy to read.
61
struct
62
SDynamicArray {
46 by Gustav Hartvigsson
* Renamed DynamicArray to SDynamicArray.
63
  SDynamicArrayPrivate * priv;
64
  size_t max_size;
47 by Gustav Hartvigsson
* Added a few skeletal functions to Callback.h
65
  size_t last_item;
46 by Gustav Hartvigsson
* Renamed DynamicArray to SDynamicArray.
66
};
5.2.8 by Gustav Hartvigsson
* Copied over LinkedList and DynamicArray from c_sdl_js
67
53 by Gustav Hartvigsson
* Finnished up s_map_add () ???
68
#define S_DYNAMIC_ARRAY(k) (SDynamicArray *)(k)
69
5.2.8 by Gustav Hartvigsson
* Copied over LinkedList and DynamicArray from c_sdl_js
70
/**
71
 * Create a new dynamic array.
72
 *
73
 * @param len The length of the initial array.
74
 * @param free_func The function to be used when freeing the items. Can be \c NULL.
75
 *        If free_func is NULL, it will use the standard library's 
76
 *       <tt>free()</tt>.
77
 *        
78
 *        Normally a function with the signature <tt> (DynamicArray * self,
30 by Gustav Hartvigsson
* Made the code compile using CMake.
79
          spointer item, spointer data) </tt> should be used but cast to FreeFunc.
5.2.8 by Gustav Hartvigsson
* Copied over LinkedList and DynamicArray from c_sdl_js
80
 */
61 by Gustav Hartvigsson
* Made the code more easy to read.
81
SDynamicArray *
82
s_dynamic_array_new (size_t len, FreeFunc free_func);
5.2.8 by Gustav Hartvigsson
* Copied over LinkedList and DynamicArray from c_sdl_js
83
84
/**
85
 * Frees the dynamic array.
86
 * 
87
 * after this is run the data will be lost.
88
 */
61 by Gustav Hartvigsson
* Made the code more easy to read.
89
void
90
s_dynamic_array_free (SDynamicArray * self, sboolean free_data);
5.2.8 by Gustav Hartvigsson
* Copied over LinkedList and DynamicArray from c_sdl_js
91
92
93
/**
94
 * Get an item from the array.
95
 */
61 by Gustav Hartvigsson
* Made the code more easy to read.
96
spointer
97
s_dynamic_array_get (SDynamicArray * self, size_t index);
5.2.8 by Gustav Hartvigsson
* Copied over LinkedList and DynamicArray from c_sdl_js
98
99
/**
47 by Gustav Hartvigsson
* Added a few skeletal functions to Callback.h
100
 *
5.2.8 by Gustav Hartvigsson
* Copied over LinkedList and DynamicArray from c_sdl_js
101
 */
61 by Gustav Hartvigsson
* Made the code more easy to read.
102
void
103
s_dynamic_array_set (SDynamicArray * self, size_t index, spointer item);
5.2.8 by Gustav Hartvigsson
* Copied over LinkedList and DynamicArray from c_sdl_js
104
105
/**
106
 * Get the size of the array, this is not the same as the length of the array.
107
 * The size is the number of elements that can be allocated without resizing
108
 * the array.
109
 * 
46 by Gustav Hartvigsson
* Renamed DynamicArray to SDynamicArray.
110
 * 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
111
 */
61 by Gustav Hartvigsson
* Made the code more easy to read.
112
size_t
113
s_dynamic_array_size (SDynamicArray * self);
5.2.8 by Gustav Hartvigsson
* Copied over LinkedList and DynamicArray from c_sdl_js
114
115
/**
47 by Gustav Hartvigsson
* Added a few skeletal functions to Callback.h
116
 * Get the index of the last item in the array.
117
 *
118
 * @note
119
 * This is not the last item added to the array, necessary, it is the index
120
 * if 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
121
 */
61 by Gustav Hartvigsson
* Made the code more easy to read.
122
size_t
123
s_dynamic_array_last_item (SDynamicArray * self);
5.2.8 by Gustav Hartvigsson
* Copied over LinkedList and DynamicArray from c_sdl_js
124
125
/**
126
 * Dumps a copy of the array. Must be cast.
127
 * 
128
 * Is not freed when the dynamic array is freed.
129
 * 
130
 * Is null-terminated.
131
 */
61 by Gustav Hartvigsson
* Made the code more easy to read.
132
spointer *
133
s_dynamic_array_dump_array (SDynamicArray * self);
5.2.8 by Gustav Hartvigsson
* Copied over LinkedList and DynamicArray from c_sdl_js
134
135
/**
136
 * Use a function on the array.
137
 */
61 by Gustav Hartvigsson
* Made the code more easy to read.
138
void
139
s_dynamic_array_for_each (SDynamicArray * self, ForEachFunc func,
30 by Gustav Hartvigsson
* Made the code compile using CMake.
140
                             spointer data);
5.2.8 by Gustav Hartvigsson
* Copied over LinkedList and DynamicArray from c_sdl_js
141
142
/** TODO
46 by Gustav Hartvigsson
* Renamed DynamicArray to SDynamicArray.
143
 * same as s_dynamic_array_for_each (), with the difference that it returns a new
144
 * SDynamicArray.
5.2.8 by Gustav Hartvigsson
* Copied over LinkedList and DynamicArray from c_sdl_js
145
 */
61 by Gustav Hartvigsson
* Made the code more easy to read.
146
SDynamicArray *
147
s_dynamic_array_for_each_with_return (SDynamicArray * self,
5.2.8 by Gustav Hartvigsson
* Copied over LinkedList and DynamicArray from c_sdl_js
148
                                                   ForEachFunc func,
30 by Gustav Hartvigsson
* Made the code compile using CMake.
149
                                                   spointer data);
5.2.8 by Gustav Hartvigsson
* Copied over LinkedList and DynamicArray from c_sdl_js
150
46 by Gustav Hartvigsson
* Renamed DynamicArray to SDynamicArray.
151
/** @} */
152
5.2.9 by Gustav Hartvigsson
* Added license to files
153
END_DECLS
154
5.2.8 by Gustav Hartvigsson
* Copied over LinkedList and DynamicArray from c_sdl_js
155
#endif /* #define __H_DYNAMIC_ARRAY__ */