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