1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
|
/*
(C) Gustav Hartvigsson, 2013.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as
published by the Free Software Foundation, either version 3 of the
License.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef __H_MAP__
#define __H_MAP__
/**
* An SMap is a data structure that holds many mappings of objects to objects:
* say, a string to an other string. This can be likened to the Dict structure
* in python, but not fully.
*
* An SMap is made up of SMapItems, each MapItem holds two pointers to data.
* The first pointer is the key, the secold is the value.
*
* please note that SMaps can be slow and are unordered.
*
* @file
*/
#include "SimpleTypeSystem.h"
#include "baseobject.h"
#include <stdbool.h>
/** @brief
* SMapItem holds the mapping of a key to a value.
*/
typedef struct _SMapItem SMapItem;
/** @brief
* An SMap is a map many SMapItems. Mapping between a key and a value.
*
* functions:
* * \c s_map_new \c ()
* * \c s_map_free \c ()
* * \c s_map_add \c ()
* * \c s_map_get \c ()
*/
typedef struct _SMap SMap;
typedef struct _SMapClass SMapClass;
typedef struct _SMapPrivate SMapPrivate;
/**
* Data structure representing an SMapItem
*/
struct _SMapItem {
void * key; /**< The Key */
void * value; /**< The Value */
};
/** @brief
* Data structure representing an SMap
*/
struct _SMap {
SBaseObjectInstance parent; /**< The parent instance */
SMapPrivate * priv; /**< Private data pointer */
};
struct _SMapClass {
SBaseObjectClass parentclass;
CompFunc is_equal; /** method to check if items are equal. */
MethodFunc free_key;
MethodFunc free_value;
};
/* -------------------------------
* The SMapItem functions.
* -------------------------------
*/
/** @breif
* create a new SMapItem.
*
* @param key The key to be added to the item.
* @param value The value to be added to the item.
* @param free_key The function to be used to free the key.
* @param free_value The function to be used to free the value.
*/
SMapItem * s_map_item_new (void * key, void * value);
/** @breif
* Frees a SMapItem.
*
* @param self the item to be freed.
*/
void s_map_item_free (SMapItem * self);
/* -------------------------------
* The SMap functions.
* -------------------------------
*/
/** @brief
* s_map_new creates a new SMap object, it takes a CompFunc as an argument.
*
* @param comp_func tells the SMap object if the key already exists when
* adding key/value pares or when searching after a key when retrieving a value.
*
* The @c CompFunc returns true if the first and second parameters are equal,
* otherwise false.
*
* @TODO:
* Check if free_key and/or free_value is null and set them to something
* appropriate.
*/
SMap * s_map_new ( CompFunc comp_func, MethodFunc free_key,
MethodFunc free_value);
/** @breif
* This function frees an instance of an SMap.
*
* @param self the object to free.
*/
void s_map_free (SMap * self);
/** @breif
* This function adds a key/value pair to an SMap.
*
* @param self the SMap to add the key/value pair to.
* @param key the key that is used to
*
* @TODO:
* make it return false on failiour, or some other nastiness.
*/
void s_map_add (SMap * self ,void * key, void * value);
/** @breif
* Get a value using using a key.
*
* @param self the SMap that you want to retrieve a value from.
* @param key the key that you use to retrieve the value from the SMap from
* with.
*/
void * s_map_get (SMap * self, void * key);
/**
* @TODO
*/
void s_map_remove (SMap * self, void * key);
#endif
|