/[public]/psiconv/trunk/lib/psiconv/list.h
ViewVC logotype

Contents of /psiconv/trunk/lib/psiconv/list.h

Parent Directory Parent Directory | Revision Log Revision Log


Revision 55 - (show annotations)
Sun Dec 10 02:17:45 2000 UTC (19 years, 9 months ago) by frodo
File MIME type: text/plain
File size: 3639 byte(s)
(Frodo) Added C++ extern statements

1 /*
2 list.h - Part of psiconv, a PSION 5 file formats converter
3 Copyright (c) 1999 Frodo Looijaard <frodol@dds.nl>
4
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
9
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18 */
19
20 /* A generic list type. In C++, this would be much neater. All elements must
21 be of the same size (solve it with pointers, if needed) */
22
23 #ifndef PSICONV_LIST_H
24 #define PSICONV_LIST_H
25
26 #include <stddef.h>
27 #include <stdio.h>
28
29 #ifdef __cplusplus
30 extern "C" {
31 #endif /* __cplusplus */
32
33 /* Always use psiconv_list, never struct psiconv_list */
34 /* No need to export the actual internal format */
35 typedef struct psiconv_list *psiconv_list;
36
37 /* Before using a list, call list_new. It takes the size of a single element
38 as its argument. Always compute it with a sizeof() expression, just to be
39 safe. The returned list is empty. */
40 extern psiconv_list psiconv_list_new(int element_size);
41
42 /* This frees the list. If elements contain pointers that need to be freed
43 separately, call list_free_el below. */
44 extern void psiconv_list_free(psiconv_list l);
45
46 /* This calls free_el first for each element, before doing a list_free.
47 Note that you should *not* do 'free(el)' at any time; that is taken care of
48 automatically. */
49 extern void psiconv_list_free_el(psiconv_list l, void free_el(void *el));
50
51 /* Return the number of allocated elements */
52 extern int psiconv_list_length(const psiconv_list l);
53
54 /* Return 1 if the list is empty, 0 if not */
55 extern int psiconv_list_is_empty(const psiconv_list l);
56
57 /* Get an element from the list, and return a pointer to it. Note: you can
58 directly modify this element, but be careful not to write beyond the
59 element memory space. */
60 extern void * psiconv_list_get(const psiconv_list l, unsigned int indx);
61
62 /* Add an element at the end of the list. The element is copied from the
63 supplied element. Of course, this does not help if the element contains
64 pointers. */
65 extern void psiconv_list_add(psiconv_list l, void *el);
66
67 /* Do some action for each element. Note: you can directly modify the
68 elements supplied to action, and they will be changed in the list,
69 but never try a free(el)! */
70 extern void psiconv_list_foreach_el(psiconv_list l, void action(void *el));
71
72 /* Clone the list, that is, copy it. If elements contain pointers, you
73 should call the next routine. */
74 extern psiconv_list psiconv_list_clone(const psiconv_list l);
75
76 /* Clone the list. For each element, clone_el is called. The elements which
77 are given to clone_el must be modified in place, as needed. */
78 extern psiconv_list psiconv_list_clone_el(const psiconv_list l,
79 void clone_el(void *el));
80
81 /* Read upto size_t elements from file f, and put them at the end of list l.
82 Returned is the actual number of elements added. This assumes the file
83 layout and the memory layout of elements is the same. */
84 extern size_t psiconv_list_fread(psiconv_list l,size_t size, FILE *f);
85
86 #ifdef __cplusplus
87 }
88 #endif /* __cplusplus */
89
90 #endif

frodo@frodo.looijaard.name
ViewVC Help
Powered by ViewVC 1.1.26