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