/simpletypesystem/trunk

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/simpletypesystem/trunk
5.2.4 by Gustav Hartvigsson
Finished documenting the SMap and SMapItem interfaces.
1
/*
5.2.7 by Gustav Hartvigsson
* Switched licence to a more permisive one.
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.
5.2.4 by Gustav Hartvigsson
Finished documenting the SMap and SMapItem interfaces.
21
*/
22
126.1.1 by Gustav Hartvigsson
* Using
23
#pragma once
5.2.1 by Gustav Hartvigsson
Started work on the Map (SMap) data structure.
24
44 by Gustav Hartvigsson
* Started to structuce the dectumentation a little better.
25
#include "Func.h"
26
#include "defs.h"
27
#include "utils.h"
53 by Gustav Hartvigsson
* Finnished up s_map_add () ???
28
#include "hash.h"
29
#include "DynamicArray.h"
44 by Gustav Hartvigsson
* Started to structuce the dectumentation a little better.
30
110 by Gustav Hartvigsson
* added S_ prifix to my macros. I should not be a scrub.
31
S_BEGIN_DECLS
44 by Gustav Hartvigsson
* Started to structuce the dectumentation a little better.
32
69 by Gustav Hartvigsson
* Finished of SMap... Sort of...
33
#define S_MAP_DEFAULT_NUMBER_OF_BUCKETS 257
52 by Gustav Hartvigsson
* Reorderd CMakeLists.txt list of files
34
5.2.1 by Gustav Hartvigsson
Started work on the Map (SMap) data structure.
35
/**
44 by Gustav Hartvigsson
* Started to structuce the dectumentation a little better.
36
 * @file
37
 * @defgroup SMap SMap
38
 * @addtogroup SMap
39
 * @{
5.2.1 by Gustav Hartvigsson
Started work on the Map (SMap) data structure.
40
 * An SMap is a data structure that holds many mappings of objects to objects:
41
 * say, a string to an other string. This can be likened to the Dict structure
42
 * in python, but not fully.
150 by Gustav Hartvigsson
* Fixed the tests in the CMake file
43
 *
5.2.1 by Gustav Hartvigsson
Started work on the Map (SMap) data structure.
44
 * An SMap is made up of SMapItems, each MapItem holds two pointers to data.
45
 * The first pointer is the key, the secold is the value.
46
 *
47
 * please note that SMaps can be slow and are unordered.
48
 */
49
22 by Gustav Hartvigsson
* Made code compile
50
5.2.4 by Gustav Hartvigsson
Finished documenting the SMap and SMapItem interfaces.
51
/** @brief
52
 * SMapItem holds the mapping of a key to a value.
53
 */
44 by Gustav Hartvigsson
* Started to structuce the dectumentation a little better.
54
typedef struct SMapItem SMapItem;
5.2.4 by Gustav Hartvigsson
Finished documenting the SMap and SMapItem interfaces.
55
56
/** @brief
57
 * An SMap is a map many SMapItems. Mapping between a key and a value.
150 by Gustav Hartvigsson
* Fixed the tests in the CMake file
58
 *
46 by Gustav Hartvigsson
* Renamed DynamicArray to SDynamicArray.
59
 * An SMap is not dependent on SObject, because it should be more generic
60
 * and have the ability to be used more easily in other SObject based classes
61
 * without causing circular dependencies.
62
 *
63
 * @sa SDynamicArray
64
 * @sa SLinkedList
5.2.4 by Gustav Hartvigsson
Finished documenting the SMap and SMapItem interfaces.
65
 */
44 by Gustav Hartvigsson
* Started to structuce the dectumentation a little better.
66
typedef struct SMap SMap;
67
69 by Gustav Hartvigsson
* Finished of SMap... Sort of...
68
#define SMAP(k) ((SMap *) k)
5.2.1 by Gustav Hartvigsson
Started work on the Map (SMap) data structure.
69
5.2.4 by Gustav Hartvigsson
Finished documenting the SMap and SMapItem interfaces.
70
/**
71
 * Data structure representing an SMapItem
72
 */
61 by Gustav Hartvigsson
* Made the code more easy to read.
73
struct
74
SMapItem {
11 by Gustav Hartvigsson
* Finnished up a the inheritance documentation.
75
  void * key; /**< The Key */
76
  void * value; /**< The Value */
5.2.1 by Gustav Hartvigsson
Started work on the Map (SMap) data structure.
77
};
78
69 by Gustav Hartvigsson
* Finished of SMap... Sort of...
79
#define SMAPITEM(k) ((SMapItem *) k)
5.2.1 by Gustav Hartvigsson
Started work on the Map (SMap) data structure.
80
5.2.4 by Gustav Hartvigsson
Finished documenting the SMap and SMapItem interfaces.
81
/* -------------------------------
82
 * The SMapItem functions.
83
 * -------------------------------
84
 */
85
86
/** @breif
87
 * create a new SMapItem.
88
 *
89
 * @param key The key to be added to the item.
90
 * @param value The value to be added to the item.
91
 */
119 by Gustav Hartvigsson
* added S_EXPERTED to public functions.
92
S_EXPORTED
61 by Gustav Hartvigsson
* Made the code more easy to read.
93
SMapItem *
94
s_map_item_new (void * key, void * value);
5.2.1 by Gustav Hartvigsson
Started work on the Map (SMap) data structure.
95
5.2.4 by Gustav Hartvigsson
Finished documenting the SMap and SMapItem interfaces.
96
/** @breif
97
 * Frees a SMapItem.
150 by Gustav Hartvigsson
* Fixed the tests in the CMake file
98
 *
5.2.4 by Gustav Hartvigsson
Finished documenting the SMap and SMapItem interfaces.
99
 * @param self the item to be freed.
18 by Gustav Hartvigsson
* Made the includation graphs look sane.
100
 * @param free_key The function to be used to free the key.
101
 * @param free_value The function to be used to free the value.
5.2.4 by Gustav Hartvigsson
Finished documenting the SMap and SMapItem interfaces.
102
 */
119 by Gustav Hartvigsson
* added S_EXPERTED to public functions.
103
S_EXPORTED
61 by Gustav Hartvigsson
* Made the code more easy to read.
104
void
69 by Gustav Hartvigsson
* Finished of SMap... Sort of...
105
s_map_item_free (SMapItem * self,
106
                 FreeFunc free_key,
107
                 FreeFunc free_value);
5.2.1 by Gustav Hartvigsson
Started work on the Map (SMap) data structure.
108
5.2.4 by Gustav Hartvigsson
Finished documenting the SMap and SMapItem interfaces.
109
/* -------------------------------
110
 * The SMap functions.
111
 * -------------------------------
112
 */
113
114
/** @brief
115
 * s_map_new creates a new SMap object, it takes a CompFunc as an argument.
5.2.1 by Gustav Hartvigsson
Started work on the Map (SMap) data structure.
116
 *
5.2.4 by Gustav Hartvigsson
Finished documenting the SMap and SMapItem interfaces.
117
 * @param comp_func tells the SMap object if the key already exists when
5.2.1 by Gustav Hartvigsson
Started work on the Map (SMap) data structure.
118
 * adding key/value pares or when searching after a key when retrieving a value.
5.2.4 by Gustav Hartvigsson
Finished documenting the SMap and SMapItem interfaces.
119
 *
14 by Gustav Hartvigsson
* Think I am 70% done with SMap now...
120
 * The @c CompFunc returns true if the first and second parameters are equal,
5.2.4 by Gustav Hartvigsson
Finished documenting the SMap and SMapItem interfaces.
121
 * otherwise false.
14 by Gustav Hartvigsson
* Think I am 70% done with SMap now...
122
 *
16 by Gustav Hartvigsson
* Made sure the code compiled
123
 * @todo
14 by Gustav Hartvigsson
* Think I am 70% done with SMap now...
124
 * Check if free_key and/or free_value is null and set them to something
125
 * appropriate.
5.2.1 by Gustav Hartvigsson
Started work on the Map (SMap) data structure.
126
 */
119 by Gustav Hartvigsson
* added S_EXPERTED to public functions.
127
S_EXPORTED
61 by Gustav Hartvigsson
* Made the code more easy to read.
128
SMap *
129
s_map_new (CompFunc comp_func,
109.1.7 by Gustav Hartvigsson
* Fixed SMap, for the time being...
130
           HashFunc key_hash_func,
131
           FreeFunc free_key,
132
           FreeFunc free_value);
5.2.1 by Gustav Hartvigsson
Started work on the Map (SMap) data structure.
133
5.2.4 by Gustav Hartvigsson
Finished documenting the SMap and SMapItem interfaces.
134
/** @breif
135
 * This function frees an instance of an SMap.
150 by Gustav Hartvigsson
* Fixed the tests in the CMake file
136
 *
5.2.4 by Gustav Hartvigsson
Finished documenting the SMap and SMapItem interfaces.
137
 * @param self the object to free.
138
 */
119 by Gustav Hartvigsson
* added S_EXPERTED to public functions.
139
S_EXPORTED
61 by Gustav Hartvigsson
* Made the code more easy to read.
140
void
79 by Gustav Hartvigsson
* Clean up of SMap's for each code.
141
s_map_free (SMap * self, sboolean free_data);
5.2.1 by Gustav Hartvigsson
Started work on the Map (SMap) data structure.
142
5.2.4 by Gustav Hartvigsson
Finished documenting the SMap and SMapItem interfaces.
143
/** @breif
144
 * This function adds a key/value pair to an SMap.
150 by Gustav Hartvigsson
* Fixed the tests in the CMake file
145
 *
5.2.4 by Gustav Hartvigsson
Finished documenting the SMap and SMapItem interfaces.
146
 * @param self the SMap to add the key/value pair to.
15 by Gustav Hartvigsson
* Added some notes... bah
147
 * @param key the key that is used to
148
 *
16 by Gustav Hartvigsson
* Made sure the code compiled
149
 * @todo
18 by Gustav Hartvigsson
* Made the includation graphs look sane.
150
 *  make it return false on failure, or some other nastiness.
5.2.4 by Gustav Hartvigsson
Finished documenting the SMap and SMapItem interfaces.
151
 */
119 by Gustav Hartvigsson
* added S_EXPERTED to public functions.
152
S_EXPORTED
61 by Gustav Hartvigsson
* Made the code more easy to read.
153
void
154
s_map_add (SMap * self, spointer key, spointer value);
5.2.1 by Gustav Hartvigsson
Started work on the Map (SMap) data structure.
155
5.2.4 by Gustav Hartvigsson
Finished documenting the SMap and SMapItem interfaces.
156
/** @breif
157
 * Get a value using using a key.
150 by Gustav Hartvigsson
* Fixed the tests in the CMake file
158
 *
5.2.4 by Gustav Hartvigsson
Finished documenting the SMap and SMapItem interfaces.
159
 * @param self the SMap that you want to retrieve a value from.
160
 * @param key the key that you use to retrieve the value from the SMap from
161
 *            with.
162
 */
119 by Gustav Hartvigsson
* added S_EXPERTED to public functions.
163
S_EXPORTED
61 by Gustav Hartvigsson
* Made the code more easy to read.
164
spointer
165
s_map_get (SMap * self, spointer key);
5.2.1 by Gustav Hartvigsson
Started work on the Map (SMap) data structure.
166
109.1.7 by Gustav Hartvigsson
* Fixed SMap, for the time being...
167
119 by Gustav Hartvigsson
* added S_EXPERTED to public functions.
168
S_EXPORTED
109.1.7 by Gustav Hartvigsson
* Fixed SMap, for the time being...
169
SMapItem *
170
s_map_get_item (SMap * self, spointer key);
171
15 by Gustav Hartvigsson
* Added some notes... bah
172
/**
150 by Gustav Hartvigsson
* Fixed the tests in the CMake file
173
 * This function removes an item from
15 by Gustav Hartvigsson
* Added some notes... bah
174
 */
119 by Gustav Hartvigsson
* added S_EXPERTED to public functions.
175
S_EXPORTED
61 by Gustav Hartvigsson
* Made the code more easy to read.
176
void
177
s_map_remove (SMap * self, spointer key);
178
70 by Gustav Hartvigsson
* removed s_dynamic_array_foreach_with_return.
179
/**
180
 * Do a for each on each key/value pair.
181
 *
182
 * @note This function <em>must not</em> change the key. Changing of the
183
 * value is permited.
184
 *
185
 * The foreach should have the following signature:
186
 @code{.c}
187
void
188
my_foreach_func (SMap * map, SMapItem * item, spointer user_data);
189
 @endcode
190
 * The <tt>user_data</tt> is passed to the function, and the <tt>item</tt>
191
 * is what you operate on inside the function. <tt>map</tt> can be ignored.
192
 */
119 by Gustav Hartvigsson
* added S_EXPERTED to public functions.
193
S_EXPORTED
70 by Gustav Hartvigsson
* removed s_dynamic_array_foreach_with_return.
194
void
79 by Gustav Hartvigsson
* Clean up of SMap's for each code.
195
s_map_for_each (SMap * self, ForEachFunc foreach_func, spointer user_data);
70 by Gustav Hartvigsson
* removed s_dynamic_array_foreach_with_return.
196
197
44 by Gustav Hartvigsson
* Started to structuce the dectumentation a little better.
198
/** @} */
199
110 by Gustav Hartvigsson
* added S_ prifix to my macros. I should not be a scrub.
200
S_END_DECLS