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 |
||
|
5.2.1
by Gustav Hartvigsson
Started work on the Map (SMap) data structure. |
23 |
#ifndef __H_MAP__
|
24 |
#define __H_MAP__
|
|
25 |
||
|
44
by Gustav Hartvigsson
* Started to structuce the dectumentation a little better. |
26 |
|
27 |
#include "baseobject.h" |
|
28 |
#include "Func.h" |
|
29 |
#include "defs.h" |
|
30 |
#include "utils.h" |
|
31 |
#include <stdbool.h> |
|
32 |
||
33 |
BEGIN_DECLS
|
|
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.
|
|
43 |
*
|
|
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.
|
|
|
5.2.4
by Gustav Hartvigsson
Finished documenting the SMap and SMapItem interfaces. |
48 |
*
|
|
44
by Gustav Hartvigsson
* Started to structuce the dectumentation a little better. |
49 |
* TODO: Total rewrite.
|
|
5.2.1
by Gustav Hartvigsson
Started work on the Map (SMap) data structure. |
50 |
*/
|
51 |
||
|
22
by Gustav Hartvigsson
* Made code compile |
52 |
|
|
5.2.4
by Gustav Hartvigsson
Finished documenting the SMap and SMapItem interfaces. |
53 |
/** @brief
|
54 |
* SMapItem holds the mapping of a key to a value.
|
|
55 |
*/
|
|
|
44
by Gustav Hartvigsson
* Started to structuce the dectumentation a little better. |
56 |
typedef struct SMapItem SMapItem; |
|
5.2.4
by Gustav Hartvigsson
Finished documenting the SMap and SMapItem interfaces. |
57 |
|
58 |
/** @brief
|
|
59 |
* An SMap is a map many SMapItems. Mapping between a key and a value.
|
|
60 |
*
|
|
61 |
* functions:
|
|
|
44
by Gustav Hartvigsson
* Started to structuce the dectumentation a little better. |
62 |
* * s_map_new()
|
63 |
* * s_map_free()
|
|
64 |
* * s_map_add()
|
|
65 |
* * s_map_get()
|
|
|
5.2.4
by Gustav Hartvigsson
Finished documenting the SMap and SMapItem interfaces. |
66 |
*/
|
|
44
by Gustav Hartvigsson
* Started to structuce the dectumentation a little better. |
67 |
typedef struct SMap SMap; |
68 |
||
69 |
||
70 |
typedef struct SMapClass SMapClass; |
|
71 |
||
72 |
||
73 |
typedef struct SMapPrivate SMapPrivate; |
|
|
5.2.1
by Gustav Hartvigsson
Started work on the Map (SMap) data structure. |
74 |
|
|
5.2.4
by Gustav Hartvigsson
Finished documenting the SMap and SMapItem interfaces. |
75 |
/**
|
76 |
* Data structure representing an SMapItem
|
|
77 |
*/
|
|
|
44
by Gustav Hartvigsson
* Started to structuce the dectumentation a little better. |
78 |
struct SMapItem { |
|
11
by Gustav Hartvigsson
* Finnished up a the inheritance documentation. |
79 |
void * key; /**< The Key */ |
80 |
void * value; /**< The Value */ |
|
|
5.2.1
by Gustav Hartvigsson
Started work on the Map (SMap) data structure. |
81 |
};
|
82 |
||
|
5.2.4
by Gustav Hartvigsson
Finished documenting the SMap and SMapItem interfaces. |
83 |
/** @brief
|
84 |
* Data structure representing an SMap
|
|
85 |
*/
|
|
|
44
by Gustav Hartvigsson
* Started to structuce the dectumentation a little better. |
86 |
struct SMap { |
87 |
SObject parent; |
|
|
11
by Gustav Hartvigsson
* Finnished up a the inheritance documentation. |
88 |
SMapPrivate * priv; /**< Private data pointer */ |
|
5.2.1
by Gustav Hartvigsson
Started work on the Map (SMap) data structure. |
89 |
};
|
90 |
||
|
44
by Gustav Hartvigsson
* Started to structuce the dectumentation a little better. |
91 |
struct SMapClass { |
92 |
SObjectClass parent_class; |
|
|
13
by Gustav Hartvigsson
* Fixed two compile errors in SSTS |
93 |
CompFunc is_equal; /** method to check if items are equal. */ |
|
22
by Gustav Hartvigsson
* Made code compile |
94 |
FuncPointer free_key; |
95 |
FuncPointer free_value; |
|
|
5.2.1
by Gustav Hartvigsson
Started work on the Map (SMap) data structure. |
96 |
};
|
97 |
||
|
5.2.4
by Gustav Hartvigsson
Finished documenting the SMap and SMapItem interfaces. |
98 |
/* -------------------------------
|
99 |
* The SMapItem functions.
|
|
100 |
* -------------------------------
|
|
101 |
*/
|
|
102 |
||
103 |
/** @breif
|
|
104 |
* create a new SMapItem.
|
|
105 |
*
|
|
106 |
* @param key The key to be added to the item.
|
|
107 |
* @param value The value to be added to the item.
|
|
108 |
*/
|
|
|
5.2.1
by Gustav Hartvigsson
Started work on the Map (SMap) data structure. |
109 |
SMapItem * s_map_item_new (void * key, void * value); |
110 |
||
|
5.2.4
by Gustav Hartvigsson
Finished documenting the SMap and SMapItem interfaces. |
111 |
/** @breif
|
112 |
* Frees a SMapItem.
|
|
113 |
*
|
|
114 |
* @param self the item to be freed.
|
|
|
18
by Gustav Hartvigsson
* Made the includation graphs look sane. |
115 |
* @param free_key The function to be used to free the key.
|
116 |
* @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. |
117 |
*/
|
|
22
by Gustav Hartvigsson
* Made code compile |
118 |
void s_map_item_free (SMapItem * self, FuncPointer free_key, |
119 |
FuncPointer free_value); |
|
|
5.2.1
by Gustav Hartvigsson
Started work on the Map (SMap) data structure. |
120 |
|
|
5.2.4
by Gustav Hartvigsson
Finished documenting the SMap and SMapItem interfaces. |
121 |
/* -------------------------------
|
122 |
* The SMap functions.
|
|
123 |
* -------------------------------
|
|
124 |
*/
|
|
125 |
||
126 |
/** @brief
|
|
127 |
* 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. |
128 |
*
|
|
5.2.4
by Gustav Hartvigsson
Finished documenting the SMap and SMapItem interfaces. |
129 |
* @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. |
130 |
* 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. |
131 |
*
|
|
14
by Gustav Hartvigsson
* Think I am 70% done with SMap now... |
132 |
* 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. |
133 |
* otherwise false.
|
|
14
by Gustav Hartvigsson
* Think I am 70% done with SMap now... |
134 |
*
|
|
16
by Gustav Hartvigsson
* Made sure the code compiled |
135 |
* @todo
|
|
14
by Gustav Hartvigsson
* Think I am 70% done with SMap now... |
136 |
* Check if free_key and/or free_value is null and set them to something
|
137 |
* appropriate.
|
|
|
5.2.1
by Gustav Hartvigsson
Started work on the Map (SMap) data structure. |
138 |
*/
|
|
22
by Gustav Hartvigsson
* Made code compile |
139 |
SMap * s_map_new ( CompFunc comp_func, FuncPointer free_key, |
140 |
FuncPointer free_value); |
|
|
5.2.1
by Gustav Hartvigsson
Started work on the Map (SMap) data structure. |
141 |
|
|
5.2.4
by Gustav Hartvigsson
Finished documenting the SMap and SMapItem interfaces. |
142 |
/** @breif
|
143 |
* This function frees an instance of an SMap.
|
|
144 |
*
|
|
145 |
* @param self the object to free.
|
|
146 |
*/
|
|
|
5.2.1
by Gustav Hartvigsson
Started work on the Map (SMap) data structure. |
147 |
void s_map_free (SMap * self); |
148 |
||
|
5.2.4
by Gustav Hartvigsson
Finished documenting the SMap and SMapItem interfaces. |
149 |
/** @breif
|
150 |
* This function adds a key/value pair to an SMap.
|
|
151 |
*
|
|
152 |
* @param self the SMap to add the key/value pair to.
|
|
|
15
by Gustav Hartvigsson
* Added some notes... bah |
153 |
* @param key the key that is used to
|
154 |
*
|
|
|
16
by Gustav Hartvigsson
* Made sure the code compiled |
155 |
* @todo
|
|
18
by Gustav Hartvigsson
* Made the includation graphs look sane. |
156 |
* make it return false on failure, or some other nastiness.
|
|
5.2.4
by Gustav Hartvigsson
Finished documenting the SMap and SMapItem interfaces. |
157 |
*/
|
|
5.2.1
by Gustav Hartvigsson
Started work on the Map (SMap) data structure. |
158 |
void s_map_add (SMap * self ,void * key, void * value); |
159 |
||
|
5.2.4
by Gustav Hartvigsson
Finished documenting the SMap and SMapItem interfaces. |
160 |
/** @breif
|
161 |
* Get a value using using a key.
|
|
162 |
*
|
|
163 |
* @param self the SMap that you want to retrieve a value from.
|
|
164 |
* @param key the key that you use to retrieve the value from the SMap from
|
|
165 |
* with.
|
|
166 |
*/
|
|
|
5.2.1
by Gustav Hartvigsson
Started work on the Map (SMap) data structure. |
167 |
void * s_map_get (SMap * self, void * key); |
168 |
||
|
15
by Gustav Hartvigsson
* Added some notes... bah |
169 |
/**
|
|
16
by Gustav Hartvigsson
* Made sure the code compiled |
170 |
* @todo
|
|
15
by Gustav Hartvigsson
* Added some notes... bah |
171 |
*/
|
172 |
void s_map_remove (SMap * self, void * key); |
|
173 |
||
|
22
by Gustav Hartvigsson
* Made code compile |
174 |
/**
|
175 |
*
|
|
176 |
*/
|
|
177 |
int s_map_ref (SMap * self); |
|
178 |
||
179 |
/**
|
|
180 |
*
|
|
181 |
*/
|
|
182 |
int s_map_unref (SMap * self); |
|
183 |
||
|
44
by Gustav Hartvigsson
* Started to structuce the dectumentation a little better. |
184 |
/** @} */
|
185 |
||
|
22
by Gustav Hartvigsson
* Made code compile |
186 |
END_DECLS
|
187 |
||
|
5.2.1
by Gustav Hartvigsson
Started work on the Map (SMap) data structure. |
188 |
#endif
|