pcsc-lite 2.3.0
simclist.h
1/*
2 * Copyright (c) 2007,2008 Mij <mij@bitchx.it>
3 *
4 * Permission to use, copy, modify, and distribute this software for any
5 * purpose with or without fee is hereby granted, provided that the above
6 * copyright notice and this permission notice appear in all copies.
7 *
8 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15 */
16
17
18/*
19 * SimCList library. See http://mij.oltrelinux.com/devel/simclist
20 */
21
22
23#ifndef SIMCLIST_H
24#define SIMCLIST_H
25
26#ifdef __cplusplus
27extern "C" {
28#endif
29
30#include <inttypes.h>
31#include <errno.h>
32#include <sys/types.h>
33
34#ifndef SIMCLIST_NO_DUMPRESTORE
35# ifndef _WIN32
36# include <sys/time.h> /* list_dump_info_t's struct timeval */
37# else
38# include <time.h>
39# endif
40#endif
41
42
43/* Be friend of both C90 and C99 compilers */
44#if defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L
45 /* "inline" and "restrict" are keywords */
46#else
47# define inline /* inline */
48# define restrict /* restrict */
49#endif
50
51
57typedef int32_t list_hash_t;
58
59#ifndef SIMCLIST_NO_DUMPRESTORE
60typedef struct {
61 uint16_t version; /* dump version */
62 struct timeval timestamp; /* when the list has been dumped, seconds since UNIX epoch */
63 uint32_t list_size;
64 uint32_t list_numels;
65 list_hash_t list_hash; /* hash of the list when dumped, or 0 if invalid */
66 uint32_t dumpsize;
67 int consistent; /* 1 if the dump is verified complete/consistent; 0 otherwise */
69#endif
70
80typedef int (*element_comparator)(const void *a, const void *b);
81
93typedef int (*element_seeker)(const void *el, const void *indicator);
94
104typedef size_t (*element_meter)(const void *el);
105
115typedef list_hash_t (*element_hash_computer)(const void *el);
116
135typedef void *(*element_serializer)(const void *restrict el, uint32_t *restrict serializ_len);
136
152typedef void *(*element_unserializer)(const void *restrict data, uint32_t *restrict data_len);
153
154/* [private-use] list entry -- olds actual user datum */
156 void *data;
157
158 /* doubly-linked list service references */
159 struct list_entry_s *next;
160 struct list_entry_s *prev;
161};
162
163/* [private-use] list attributes */
165 /* user-set routine for comparing list elements */
166 element_comparator comparator;
167 /* user-set routing for seeking elements */
168 element_seeker seeker;
169 /* user-set routine for determining the length of an element */
170 element_meter meter;
171 int copy_data;
172 /* user-set routine for computing the hash of an element */
173 element_hash_computer hasher;
174 /* user-set routine for serializing an element */
175 element_serializer serializer;
176 /* user-set routine for unserializing an element */
177 element_unserializer unserializer;
178};
179
181typedef struct {
182 struct list_entry_s *head_sentinel;
183 struct list_entry_s *tail_sentinel;
184 struct list_entry_s *mid;
185
186 unsigned int numels;
187
188 /* array of spare elements */
189 struct list_entry_s **spareels;
190 unsigned int spareelsnum;
191
192#ifdef SIMCLIST_WITH_THREADS
193 /* how many threads are currently running */
194 unsigned int threadcount;
195#endif
196
197 /* service variables for list iteration */
198 int iter_active;
199 unsigned int iter_pos;
200 struct list_entry_s *iter_curentry;
201
202 /* list attributes */
203 struct list_attributes_s attrs;
204} list_t;
205
212int list_init(list_t *restrict l);
213
223void list_destroy(list_t *restrict l);
224
237int list_attributes_comparator(list_t *restrict l, element_comparator comparator_fun);
238
251int list_attributes_seeker(list_t *restrict l, element_seeker seeker_fun);
252
283int list_attributes_copy(list_t *restrict l, element_meter metric_fun, int copy_data);
284
303int list_attributes_hash_computer(list_t *restrict l, element_hash_computer hash_computer_fun);
304
324int list_attributes_serializer(list_t *restrict l, element_serializer serializer_fun);
325
346int list_attributes_unserializer(list_t *restrict l, element_unserializer unserializer_fun);
347
358int list_append(list_t *restrict l, const void *data);
359
370int list_prepend(list_t *restrict l, const void *restrict data);
371
380void *list_fetch(list_t *restrict l);
381
389void *list_get_at(const list_t *restrict l, unsigned int pos);
390
403void *list_get_max(const list_t *restrict l);
404
417void *list_get_min(const list_t *restrict l);
418
426void *list_extract_at(list_t *restrict l, unsigned int pos);
427
436int list_insert_at(list_t *restrict l, const void *data, unsigned int pos);
437
453int list_delete(list_t *restrict l, const void *data);
454
462int list_delete_at(list_t *restrict l, unsigned int pos);
463
472int list_delete_range(list_t *restrict l, unsigned int posstart, unsigned int posend);
473
485int list_clear(list_t *restrict l);
486
493unsigned int list_size(const list_t *restrict l);
494
503int list_empty(const list_t *restrict l);
504
522int list_locate(const list_t *restrict l, const void *data);
523
537void *list_seek(list_t *restrict l, const void *indicator);
538
558int list_contains(const list_t *restrict l, const void *data);
559
577int list_concat(const list_t *l1, const list_t *l2, list_t *restrict dest);
578
594int list_sort(list_t *restrict l, int versus);
595
606int list_iterator_start(list_t *restrict l);
607
614void *list_iterator_next(list_t *restrict l);
615
622int list_iterator_hasnext(const list_t *restrict l);
623
630int list_iterator_stop(list_t *restrict l);
631
640int list_hash(const list_t *restrict l, list_hash_t *restrict hash);
641
642#ifndef SIMCLIST_NO_DUMPRESTORE
658int list_dump_getinfo_filedescriptor(int fd, list_dump_info_t *restrict info);
659
673int list_dump_getinfo_file(const char *restrict filename, list_dump_info_t *restrict info);
674
709int list_dump_filedescriptor(const list_t *restrict l, int fd, size_t *restrict len);
710
732int list_dump_file(const list_t *restrict l, const char *restrict filename, size_t *restrict len);
733
752int list_restore_filedescriptor(list_t *restrict l, int fd, size_t *restrict len);
753
770int list_restore_file(list_t *restrict l, const char *restrict filename, size_t *len);
771#endif
772
773/* ready-made comparators, meters and hash computers */
774 /* comparator functions */
779int list_comparator_int8_t(const void *a, const void *b);
780
785int list_comparator_int16_t(const void *a, const void *b);
786
791int list_comparator_int32_t(const void *a, const void *b);
792
797int list_comparator_int64_t(const void *a, const void *b);
798
803int list_comparator_uint8_t(const void *a, const void *b);
804
809int list_comparator_uint16_t(const void *a, const void *b);
810
815int list_comparator_uint32_t(const void *a, const void *b);
816
821int list_comparator_uint64_t(const void *a, const void *b);
822
827int list_comparator_float(const void *a, const void *b);
828
833int list_comparator_double(const void *a, const void *b);
834
839int list_comparator_string(const void *a, const void *b);
840
841 /* metric functions */
846size_t list_meter_int8_t(const void *el);
847
852size_t list_meter_int16_t(const void *el);
853
858size_t list_meter_int32_t(const void *el);
859
864size_t list_meter_int64_t(const void *el);
865
870size_t list_meter_uint8_t(const void *el);
871
876size_t list_meter_uint16_t(const void *el);
877
882size_t list_meter_uint32_t(const void *el);
883
888size_t list_meter_uint64_t(const void *el);
889
894size_t list_meter_float(const void *el);
895
900size_t list_meter_double(const void *el);
901
906size_t list_meter_string(const void *el);
907
908 /* hash functions */
913list_hash_t list_hashcomputer_int8_t(const void *el);
914
919list_hash_t list_hashcomputer_int16_t(const void *el);
920
925list_hash_t list_hashcomputer_int32_t(const void *el);
926
931list_hash_t list_hashcomputer_int64_t(const void *el);
932
937list_hash_t list_hashcomputer_uint8_t(const void *el);
938
943list_hash_t list_hashcomputer_uint16_t(const void *el);
944
949list_hash_t list_hashcomputer_uint32_t(const void *el);
950
955list_hash_t list_hashcomputer_uint64_t(const void *el);
956
961list_hash_t list_hashcomputer_float(const void *el);
962
967list_hash_t list_hashcomputer_double(const void *el);
968
973list_hash_t list_hashcomputer_string(const void *el);
974
975#ifdef __cplusplus
976}
977#endif
978
979#endif
980
Definition simclist.h:155
list object
Definition simclist.h:181