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