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" |
42 |
#include "utils" |
|
|
5.2.1
by Gustav Hartvigsson
Started work on the Map (SMap) data structure. |
43 |
#include <stdbool.h> |
44 |
||
|
5.2.4
by Gustav Hartvigsson
Finished documenting the SMap and SMapItem interfaces. |
45 |
/** @brief
|
46 |
* SMapItem holds the mapping of a key to a value.
|
|
47 |
*/
|
|
|
5.2.1
by Gustav Hartvigsson
Started work on the Map (SMap) data structure. |
48 |
typedef struct _SMapItem SMapItem; |
|
5.2.4
by Gustav Hartvigsson
Finished documenting the SMap and SMapItem interfaces. |
49 |
|
50 |
/** @brief
|
|
51 |
* An SMap is a map many SMapItems. Mapping between a key and a value.
|
|
52 |
*
|
|
53 |
* functions:
|
|
54 |
* * \c s_map_new \c ()
|
|
55 |
* * \c s_map_free \c ()
|
|
56 |
* * \c s_map_add \c ()
|
|
57 |
* * \c s_map_get \c ()
|
|
58 |
*/
|
|
|
5.2.1
by Gustav Hartvigsson
Started work on the Map (SMap) data structure. |
59 |
typedef struct _SMap SMap; |
|
5.2.4
by Gustav Hartvigsson
Finished documenting the SMap and SMapItem interfaces. |
60 |
|
61 |
||
|
5.2.1
by Gustav Hartvigsson
Started work on the Map (SMap) data structure. |
62 |
typedef struct _SMapClass SMapClass; |
|
5.2.4
by Gustav Hartvigsson
Finished documenting the SMap and SMapItem interfaces. |
63 |
|
64 |
||
|
5.2.1
by Gustav Hartvigsson
Started work on the Map (SMap) data structure. |
65 |
typedef struct _SMapPrivate SMapPrivate; |
66 |
||
|
5.2.4
by Gustav Hartvigsson
Finished documenting the SMap and SMapItem interfaces. |
67 |
/**
|
68 |
* Data structure representing an SMapItem
|
|
69 |
*/
|
|
|
5.2.1
by Gustav Hartvigsson
Started work on the Map (SMap) data structure. |
70 |
struct _SMapItem { |
|
11
by Gustav Hartvigsson
* Finnished up a the inheritance documentation. |
71 |
void * key; /**< The Key */ |
72 |
void * value; /**< The Value */ |
|
|
5.2.1
by Gustav Hartvigsson
Started work on the Map (SMap) data structure. |
73 |
};
|
74 |
||
|
5.2.4
by Gustav Hartvigsson
Finished documenting the SMap and SMapItem interfaces. |
75 |
/** @brief
|
76 |
* Data structure representing an SMap
|
|
77 |
*/
|
|
|
5.2.1
by Gustav Hartvigsson
Started work on the Map (SMap) data structure. |
78 |
struct _SMap { |
|
11
by Gustav Hartvigsson
* Finnished up a the inheritance documentation. |
79 |
SBaseObjectInstance parent; /**< The parent instance */ |
80 |
SMapPrivate * priv; /**< Private data pointer */ |
|
|
5.2.1
by Gustav Hartvigsson
Started work on the Map (SMap) data structure. |
81 |
};
|
82 |
||
83 |
struct _SMapClass { |
|
84 |
SBaseObjectClass parentclass; |
|
|
13
by Gustav Hartvigsson
* Fixed two compile errors in SSTS |
85 |
CompFunc is_equal; /** method to check if items are equal. */ |
|
14
by Gustav Hartvigsson
* Think I am 70% done with SMap now... |
86 |
MethodFunc free_key; |
87 |
MethodFunc free_value; |
|
|
5.2.1
by Gustav Hartvigsson
Started work on the Map (SMap) data structure. |
88 |
};
|
89 |
||
|
5.2.4
by Gustav Hartvigsson
Finished documenting the SMap and SMapItem interfaces. |
90 |
/* -------------------------------
|
91 |
* The SMapItem functions.
|
|
92 |
* -------------------------------
|
|
93 |
*/
|
|
94 |
||
95 |
/** @breif
|
|
96 |
* create a new SMapItem.
|
|
97 |
*
|
|
98 |
* @param key The key to be added to the item.
|
|
99 |
* @param value The value to be added to the item.
|
|
|
14
by Gustav Hartvigsson
* Think I am 70% done with SMap now... |
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 |
*/
|
|
5.2.1
by Gustav Hartvigsson
Started work on the Map (SMap) data structure. |
103 |
SMapItem * s_map_item_new (void * key, void * value); |
104 |
||
|
5.2.4
by Gustav Hartvigsson
Finished documenting the SMap and SMapItem interfaces. |
105 |
/** @breif
|
106 |
* Frees a SMapItem.
|
|
107 |
*
|
|
108 |
* @param self the item to be freed.
|
|
|
18
by Gustav Hartvigsson
* Made the includation graphs look sane. |
109 |
* @param free_key The function to be used to free the key.
|
110 |
* @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. |
111 |
*/
|
|
17
by Gustav Hartvigsson
* Blarg, Fixed it... fo' relz tis' time |
112 |
void s_map_item_free (SMapItem * self, MethodFunc free_key, |
113 |
MethodFunc free_value); |
|
|
5.2.1
by Gustav Hartvigsson
Started work on the Map (SMap) data structure. |
114 |
|
|
5.2.4
by Gustav Hartvigsson
Finished documenting the SMap and SMapItem interfaces. |
115 |
/* -------------------------------
|
116 |
* The SMap functions.
|
|
117 |
* -------------------------------
|
|
118 |
*/
|
|
119 |
||
120 |
/** @brief
|
|
121 |
* 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. |
122 |
*
|
|
5.2.4
by Gustav Hartvigsson
Finished documenting the SMap and SMapItem interfaces. |
123 |
* @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. |
124 |
* 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. |
125 |
*
|
|
14
by Gustav Hartvigsson
* Think I am 70% done with SMap now... |
126 |
* 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. |
127 |
* otherwise false.
|
|
14
by Gustav Hartvigsson
* Think I am 70% done with SMap now... |
128 |
*
|
|
16
by Gustav Hartvigsson
* Made sure the code compiled |
129 |
* @todo
|
|
14
by Gustav Hartvigsson
* Think I am 70% done with SMap now... |
130 |
* Check if free_key and/or free_value is null and set them to something
|
131 |
* appropriate.
|
|
|
5.2.1
by Gustav Hartvigsson
Started work on the Map (SMap) data structure. |
132 |
*/
|
|
14
by Gustav Hartvigsson
* Think I am 70% done with SMap now... |
133 |
SMap * s_map_new ( CompFunc comp_func, MethodFunc free_key, |
134 |
MethodFunc free_value); |
|
|
5.2.1
by Gustav Hartvigsson
Started work on the Map (SMap) data structure. |
135 |
|
|
5.2.4
by Gustav Hartvigsson
Finished documenting the SMap and SMapItem interfaces. |
136 |
/** @breif
|
137 |
* This function frees an instance of an SMap.
|
|
138 |
*
|
|
139 |
* @param self the object to free.
|
|
140 |
*/
|
|
|
5.2.1
by Gustav Hartvigsson
Started work on the Map (SMap) data structure. |
141 |
void s_map_free (SMap * self); |
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.
|
|
145 |
*
|
|
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 |
*/
|
|
5.2.1
by Gustav Hartvigsson
Started work on the Map (SMap) data structure. |
152 |
void s_map_add (SMap * self ,void * key, void * value); |
153 |
||
|
5.2.4
by Gustav Hartvigsson
Finished documenting the SMap and SMapItem interfaces. |
154 |
/** @breif
|
155 |
* Get a value using using a key.
|
|
156 |
*
|
|
157 |
* @param self the SMap that you want to retrieve a value from.
|
|
158 |
* @param key the key that you use to retrieve the value from the SMap from
|
|
159 |
* with.
|
|
160 |
*/
|
|
|
5.2.1
by Gustav Hartvigsson
Started work on the Map (SMap) data structure. |
161 |
void * s_map_get (SMap * self, void * key); |
162 |
||
|
15
by Gustav Hartvigsson
* Added some notes... bah |
163 |
/**
|
|
16
by Gustav Hartvigsson
* Made sure the code compiled |
164 |
* @todo
|
|
15
by Gustav Hartvigsson
* Added some notes... bah |
165 |
*/
|
166 |
void s_map_remove (SMap * self, void * key); |
|
167 |
||
|
5.2.1
by Gustav Hartvigsson
Started work on the Map (SMap) data structure. |
168 |
#endif
|