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
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
|
/**
* SAMPMAP.C -- (Internal) Interface to support the Map structure
*
* map = samp_newMap ()
* samp_freeMap (Map map)
*
* nelem = samp_getMapSize (Map map)
* key = samp_getMapKey (Map map, int index)
* val = samp_getMapVal (Map map, int index)
*
* samp_setStringInMap (Map map, char *value)
* samp_setMapInMap (Map map1, Map map2)
* samp_setListInMap (Map map, List list)
* samp_setIntInMap (Map map, int ival)
* samp_setFloatInMap (Map map, float rval)
*
* str = samp_getStringFromMap (Map map, char *key)
* map = samp_getMapFromMap (Map map, char *key)
* list = samp_getListFromMap (Map map, char *key)
* ival = samp_getIntFromMap (Map map, char *key)
* rval = samp_getFloatFromMap (Map map, char *key)
*
*
* @brief (Internal) Interface to support the Map structure
*
* @file sampMap.c
* @author Mike Fitzpatrick
* @date 7/10/09
*/
#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>
#include <string.h>
#include "samp.h"
/**
* SAMP_NEWMAP -- Create a new Map object
*
* @brief Create a new Map object
* @fn int samp_newMap (void)
*
* @return handle to new Map
*/
handle_t
samp_newMap ()
{
return ( (handle_t) xr_newStruct() );
}
/**
* SAMP_FREEMAP -- Free the given Map object
*
* @brief Free the given Map object
* @fn void samp_freeMap (Map map)
*
* @param map Map object to free
* @return nothing
*/
void
samp_freeMap (Map map)
{
if (map > 0)
xr_freeStruct (map);
}
/*
* SAMP_GETMAPSIZE -- Get the number of elements in a Map.
*
* @brief Get the number of elements in a Map.
* @fn int nelem = samp_getMapSize (Map map)
*
* @param map handle to Map object
* @return number of elements
*/
int samp_getMapSize (Map map)
{
return (xr_structSize (map));
}
/*
* SAMP_GETMAPKEY -- Get a Map keyword by index.
*
* @brief Get a Map keyword by index.
* @fn char *key = samp_getMapKey (Map map, int index)
*
* @param map handle to Map object
* @param index Map element index
* @return Map keyword
*/
char *
samp_getMapKey (Map map, int index)
{
return (xr_getStructKey (map, index));
}
/*
* SAMP_GETMAPVAL -- Get a Map value by index.
*
* @brief Get a Map value by index.
* @fn char *val = samp_getMapVal (Map map, int index)
*
* @param map handle to Map object
* @param index Map element index
* @return Map value
*/
char *
samp_getMapVal (Map map, int index)
{
return (xr_getStructVal (map, index));
}
/**
* SAMP_SETSTRINGINMAP -- Set a string in a Map (append)
*
* @brief Set a string in a Map (append)
* @fn void samp_setStringInMap (Map map, char *key, char *value)
*
* @param map handle to Map object
* @param key Map key
* @param value Map value
* @return nothing
*/
void
samp_setStringInMap (Map map, char *key, char *value)
{
xr_setStringInStruct (map, key, value);
}
/**
* SAMP_SETMAPINMAP -- Set a Map in a Map (append)
*
* @brief Set a Map in a Map (append)
* @fn void samp_setMapInMap (Map map1, char *key, Map map2)
*
* @param map1 handle to Map object
* @param key Map key
* @param map2 handle to Map object to set
* @return nothing
*/
void
samp_setMapInMap (Map map1, char *key, Map map2)
{
xr_setStructInStruct (map1, key, map2);
}
/**
* SAMP_SETLISTINMAP -- Set a List in a Map (append)
*
* @brief Set a List in a Map (append)
* @fn void samp_setListInMap (Map map, char *key, List list)
*
* @param map handle to Map object
* @param key Map key
* @param list handle to List object to set
* @return nothing
*/
void
samp_setListInMap (Map map, char *key, List list)
{
xr_setArrayInStruct (map, key, list);
}
/**
* SAMP_SETINTINMAP -- Set a Int in a Map (append)
*
* @brief Set a Int in a Map (append)
* @fn void samp_setIntInMap (Map map, char *key, int value)
*
* @param map handle to Map object
* @param key Map key
* @param value value
* @return nothing
*/
void
samp_setIntInMap (Map map, char *key, int value)
{
xr_setIntInStruct (map, key, value);
}
/**
* SAMP_SETFLOATINMAP -- Set a Float in a Map (append)
*
* @brief Set a string in a Map (append)
* @fn void samp_setFloatInMap (Map map, char *key, float value)
*
* @param map handle to Map object
* @param key Map key
* @param value value
* @return nothing
*/
void
samp_setFloatInMap (Map map, char *key, float value)
{
xr_setDoubleInStruct (map, key, (double)value);
}
/****************************************************************************/
/**
* SAMP_GETSTRINGFROMMAP -- Get a string from the Map
*
* @brief Get a string from the Map
* @fn char *samp_getStringFromMap (Map map, char *key)
*
* @param map handle to Map object
* @param key Map key
* @return string value from Map
*/
char *
samp_getStringFromMap (Map map, char *key)
{
static char buf[SZ_SBUF], *res = buf;
memset (buf, 0, SZ_SBUF);
xr_getStringFromStruct (map, key, &res);
return (res);
}
/**
* SAMP_GETMAPFROMMAP -- Get a Map from the Map
*
* @brief Get a Map from the Map
* @fn Map samp_getMapFromMap (Map map, char *key)
*
* @param map handle to Map object
* @param key Map key
* @return handle to Map value
*/
Map
samp_getMapFromMap (Map map, char *key)
{
Map m = 0;
xr_getStructFromStruct (map, key, &m);
return (m);
}
/**
* SAMP_GETLISTFROMMAP -- Get a LIST from the Map
*
* @brief Get a LIST from the Map
* @fn List samp_getListFromMap (Map map, char *key)
*
* @param map handle to Map object
* @param key Map key
* @return handle to List value
*/
List
samp_getListFromMap (Map map, char *key)
{
List list = 0;
xr_getArrayFromStruct (map, key, &list);
return (list);
}
/**
* SAMP_GETINTFROMMAP -- Get a integer from the Map
*
* @brief Get a integer from the Map
* @fn ival = samp_getIntFromMap (Map map, char *key)
*
* @param map handle to Map object
* @param key Map key
* @return integer value
*/
int
samp_getIntFromMap (Map map, char *key)
{
int ival = 0;
xr_getIntFromStruct (map, key, &ival);
return (ival);
}
/**
* SAMP_GETFLOATFROMMAP -- Get a float from the Map
*
* @brief Get a float from the Map
* @fn rval = samp_getFloatFromMap (Map map, char *key)
*
* @param map handle to Map object
* @param key Map key
* @return floating point value
*/
float
samp_getFloatFromMap (Map map, char *key)
{
double dval = 0.0;
xr_getDoubleFromStruct (map, key, &dval);
return ((float) dval);
}
|