ViewVC logotype

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

Parent Directory Parent Directory | Revision Log Revision Log

Revision 2 - (show annotations)
Sun Oct 3 21:10:47 1999 UTC (22 years ago) by frodo
File MIME type: text/plain
File size: 3534 byte(s)
Imported sources

1 /*
2 list.h - Part of psiconv, a PSION 5 file formats converter
3 Copyright (c) 1999 Frodo Looijaard <frodol@dds.nl>
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.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 GNU General Public License for more details.
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 */
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) */
23 #ifndef PSICONV_LIST_H
24 #define PSICONV_LIST_H
26 #include <stddef.h>
27 #include <stdio.h>
29 /* Always use psiconv_list, never struct psiconv_list */
30 /* No need to export the actual internal format */
31 typedef struct psiconv_list *psiconv_list;
33 /* Before using a list, call list_new. It takes the size of a single element
34 as its argument. Always compute it with a sizeof() expression, just to be
35 safe. The returned list is empty. */
36 extern psiconv_list psiconv_list_new(int element_size);
38 /* This frees the list. If elements contain pointers that need to be freed
39 separately, call list_free_el below. */
40 extern void psiconv_list_free(psiconv_list l);
42 /* This calls free_el first for each element, before doing a list_free.
43 Note that you should *not* do 'free(el)' at any time; that is taken care of
44 automatically. */
45 extern void psiconv_list_free_el(psiconv_list l, void free_el(void *el));
47 /* Return the number of allocated elements */
48 extern int psiconv_list_length(const psiconv_list l);
50 /* Return 1 if the list is empty, 0 if not */
51 extern int psiconv_list_is_empty(const psiconv_list l);
53 /* Get an element from the list, and return a pointer to it. Note: you can
54 directly modify this element, but be careful not to write beyond the
55 element memory space. */
56 extern void * psiconv_list_get(const psiconv_list l, unsigned int indx);
58 /* Add an element at the end of the list. The element is copied from the
59 supplied element. Of course, this does not help if the element contains
60 pointers. */
61 extern void psiconv_list_add(psiconv_list l, void *el);
63 /* Do some action for each element. Note: you can directly modify the
64 elements supplied to action, and they will be changed in the list,
65 but never try a free(el)! */
66 extern void psiconv_list_foreach_el(psiconv_list l, void action(void *el));
68 /* Clone the list, that is, copy it. If elements contain pointers, you
69 should call the next routine. */
70 extern psiconv_list psiconv_list_clone(const psiconv_list l);
72 /* Clone the list. For each element, clone_el is called. The elements which
73 are given to clone_el must be modified in place, as needed. */
74 extern psiconv_list psiconv_list_clone_el(const psiconv_list l,
75 void clone_el(void *el));
77 /* Read upto size_t elements from file f, and put them at the end of list l.
78 Returned is the actual number of elements added. This assumes the file
79 layout and the memory layout of elements is the same. */
80 extern size_t psiconv_list_fread(psiconv_list l,size_t size, FILE *f);
82 #endif

ViewVC Help
Powered by ViewVC 1.1.26