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