aboutsummaryrefslogtreecommitdiff
path: root/vendor/voclient/libsamp/sampList.c
blob: 28d1288a38d3bbf7e06babf60dfa0e660852c364 (plain) (blame)
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
/**
 *  SAMPLIST.C -- (Internal) interface to support the List structure.
 *
 *                list = samp_newList  ()
 *                      samp_freeList  (List list)
 *		   len = samp_listLen  (List list)
 *        
 *               samp_setStringInList  (List list, char *value)
 *                  samp_setMapInList  (List list, Map map)
 *                 samp_setListInList  (List list1, List list2)
 *                  samp_setIntInList  (List list, int val)
 *                samp_setFloatInList  (List list, float val)
 *  
 *       str = samp_getStringFromList  (List list, int index)  
 *          map = samp_getMapFromList  (List list, int index)  
 *        list = samp_getListFromList  (List list, int index)  
 *         ival = samp_getIntFromList  (List list, int index)  
 *       rval = samp_getFloatFromList  (List list, int index)  
 *
 *  @brief      (Internal) interface to support the List structure.
 *  
 *  @file       sampList.c
 *  @author     Mike Fitzpatrick
 *  @date       7/10/09
 */


#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>
#include <string.h>

#include "samp.h"




/**
 *  SAMP_NEWLIST -- Create a new List object
 *
 *  @brief	Create a new List object
 *  @fn		int samp_newList (void)
 *
 *  @return		handle to List object
 */
handle_t
samp_newList ()
{
    return ( (handle_t) xr_newArray () );
}


/**
 *  SAMP_FREELIST -- Free the given List object
 *
 *  @brief	Free the given List object
 *  @fn		void samp_freeList (List list)
 *
 *  @param  list	List object handle
 *  @return		nothing
 */
void
samp_freeList (List list)
{
    if (list >= 0)
        xr_freeArray (list);
}


/**
 *  SAMP_LISTLEN -- Get number of elements in a List.
 *
 *  @brief	Get number of elements in a List.
 *  @fn		int  = samp_listLen (List list)
 *
 *  @param  list	List object handle
 *  @return		nothing
 */
int
samp_listLen (List list)
{
    return ( xr_arrayLen (list) );
}


/********************************
 *  SET Methods
 ********************************/

/**
 *  SAMP_SETSTRINGINLIST -- Set a string in a List (append)
 *
 *  @brief	Set a string in a List (append)
 *  @fn		void samp_setStringInList (List list, char *value)
 *
 *  @param  list	List object handle
 *  @param  value	string value to set
 *  @return		nothing
 */
void
samp_setStringInList (List list, char *value)
{
    xr_setStringInArray (list, (value ? value : ""));
}


/**
 *  SAMP_SETMAPINLIST -- Set a Map in a List (append)
 *
 *  @brief	Set a Map in a List (append)
 *  @fn		void samp_setMapInList (List list, Map map)
 *
 *  @param  list	List object handle
 *  @param  map		Map object to be set
 *  @return		nothing
 */
void
samp_setMapInList (List list, Map map)
{
    xr_setStructInArray (list, map);
}


/**
 *  SAMP_SETLISTINLIST -- Set a List in another List (append)
 *
 *  @brief	Set a List in another List (append)
 *  @fn		void samp_setListInList (List list1, List list2)
 *
 *  @param  list1	List object handle
 *  @param  list2	List to be appended
 *  @return		nothing
 */
void
samp_setListInList (List list1, List list2)
{
    xr_setArrayInArray (list1, list2);
}


/**
 *  SAMP_SETINTINLIST -- Set an Int in a List (append)
 *
 *  @brief	Set an Int in a List (append)
 *  @fn		void samp_setIntInList (List list, int ival)
 *
 *  @param  list1	List object handle
 *  @param  ival	Integer value to be appended
 *  @return		nothing
 */
void
samp_setIntInList (List list, int ival)
{
    xr_setIntInArray (list, ival);
}


/**
 *  SAMP_SETFLOATINLIST -- Set a Float in a List (append)
 *
 *  @brief	Set a Float in a List (append)
 *  @fn		void samp_setFloatInList (List list, float rval)
 *
 *  @param  list1	List object handle
 *  @param  rval	Float value to be appended
 *  @return		nothing
 */
void
samp_setFloatInList (List list, float rval)
{
    xr_setDoubleInArray (list, (double) rval);
}




/********************************
 *  GET Methods
 ********************************/

/**
 *  SAMP_GETSTRINGFROMLIST -- Get a string from the List
 *
 *  @brief	Get a string from the List
 *  @fn		char *samp_getStringFromList (List list, int index)  
 *
 *  @param  list	List object handle
 *  @param  index	List index containing the string
 *  @return		character string
 */
char *
samp_getStringFromList (List list, int index)  
{
    static char  buf[SZ_SBUF], *res = buf;

    memset (buf, 0, SZ_SBUF);
    xr_getStringFromArray (list, index, &res);

    return ((res));
}


/**
 *  SAMP_GETMAPFROMLIST -- Get a Map from the List
 *
 *  @brief	Get a Map from the List
 *  @fn		Map samp_getMapFromList (List list, int index)  
 *
 *  @param  list	List object handle
 *  @param  index	List index containing the Map
 *  @return		Map handle
 */
Map
samp_getMapFromList (List list, int index)  
{
    Map map = 0;
    xr_getStructFromArray (list, index, &map);

    return (map);
}


/**
 *  SAMP_GETLISTFROMLIST -- Get a List from the List
 *
 *  @brief	Get a List from the List
 *  @fn		List samp_getListFromList (List list, int index)  
 *
 *  @param  list	List object handle
 *  @param  index	List index containing the List
 *  @return		List handle
 */
List
samp_getListFromList (List list, int index)  
{
    List l = 0;
    xr_getArrayFromArray (list, index, &l);

    return (l);
}


/**
 *  SAMP_GETINTFROMLIST -- Get an Int from the List
 *
 *  @brief	Get an Int from the List
 *  @fn		ival =  samp_getListFromList (List list, int index)  
 *
 *  @param  list	List object handle
 *  @param  index	List index containing the desired value
 *  @return		int value
 */
int
samp_getIntFromList (List list, int index)  
{
    int i = 0;
    xr_getIntFromArray (list, index, &i);

    return (i);
}


/**
 *  SAMP_GETFLOATFROMLIST -- Get a Float from the List
 *
 *  @brief	Get a Float from the List
 *  @fn		ival =  samp_getFloatFromList (List list, int index)  
 *
 *  @param  list	List object handle
 *  @param  index	List index containing the desired value
 *  @return		int value
 */
float
samp_getFloatFromList (List list, int index)  
{
    double x = 0.0;
    xr_getDoubleFromArray (list, index, &x);

    return ((float) x);
}