Added forward functions to rsbool, and a few tests for them.
[idzebra-moved-to-github.git] / include / rset.h
1 /* $Id: rset.h,v 1.21 2004-01-30 11:43:40 heikki Exp $
2    Copyright (C) 1995,1996,1997,1998,1999,2000,2001,2002
3    Index Data Aps
4
5 This file is part of the Zebra server.
6
7 Zebra is free software; you can redistribute it and/or modify it under
8 the terms of the GNU General Public License as published by the Free
9 Software Foundation; either version 2, or (at your option) any later
10 version.
11
12 Zebra is distributed in the hope that it will be useful, but WITHOUT ANY
13 WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
15 for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with Zebra; see the file LICENSE.zebra.  If not, write to the
19 Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA
20 02111-1307, USA.
21 */
22
23
24
25 #ifndef RSET_H
26 #define RSET_H
27
28 #include <stdlib.h>
29
30 #ifdef __cplusplus
31 extern "C" {
32 #endif
33 typedef void *RSFD;
34
35 typedef struct rset *RSET;
36 typedef struct rset_term *RSET_TERM;
37
38 struct rset_control
39 {
40     char *desc; /* text description of set type (for debugging) */
41     void *(*f_create)(RSET ct, const struct rset_control *sel, void *parms);
42     RSFD (*f_open)(RSET ct, int wflag);
43     void (*f_close)(RSFD rfd);
44     void (*f_delete)(RSET ct);
45     void (*f_rewind)(RSFD rfd);
46     int (*f_forward)(RSET ct, RSFD rfd, void *buf,  int *term_index,
47                      int (*cmpfunc)(const void *p1, const void *p2), 
48                      const void *untilbuf);
49     int (*f_count)(RSET ct);
50     int (*f_read)(RSFD rfd, void *buf, int *term_index);
51     int (*f_write)(RSFD rfd, const void *buf);
52 };
53
54 int rset_default_forward(RSET ct, RSFD rfd, void *buf, int *term_index, 
55                      int (*cmpfunc)(const void *p1, const void *p2), 
56                      const void *untilbuf);
57
58 struct rset_term {
59     char *name;
60     int  nn;
61     char *flags;
62     int  count;
63     int  type;
64 };
65
66 typedef struct rset
67 {
68     const struct rset_control *control;
69     int  flags;
70     int  count;
71     void *buf;
72     RSET_TERM *rset_terms;
73     int no_rset_terms;
74 } rset;
75
76 RSET_TERM rset_term_create (const char *name, int length, const char *flags,
77                             int type);
78 void rset_term_destroy (RSET_TERM t);
79 RSET_TERM rset_term_dup (RSET_TERM t);
80
81 #define RSETF_READ       0
82 #define RSETF_WRITE      1
83
84 RSET rset_create(const struct rset_control *sel, void *parms); 
85 /* parameters? */
86
87 /* int rset_open(RSET rs, int wflag); */
88 #define rset_open(rs, wflag) (*(rs)->control->f_open)((rs), (wflag))
89
90 /* void rset_close(RSET rs); */
91 #define rset_close(rs, rfd) (*(rs)->control->f_close)(rfd)
92
93 void rset_delete(RSET rs);
94
95 RSET rset_dup (RSET rs);
96
97 /* void rset_rewind(RSET rs); */
98 #define rset_rewind(rs, rfd) (*(rs)->control->f_rewind)((rfd))
99
100 /* int rset_forward(RSET rs, void *buf, int *indx, void *untilbuf); */
101 #define rset_forward(rs, fd, buf, indx, cmpfunc, untilbuf) \
102     (*(rs)->control->f_forward)((rs), (fd), (buf), (indx), (cmpfunc), (untilbuf))
103
104 /* int rset_count(RSET rs); */
105 #define rset_count(rs) (*(rs)->control->f_count)(rs)
106
107 /* int rset_read(RSET rs, void *buf, int *indx); */
108 #define rset_read(rs, fd, buf, indx) (*(rs)->control->f_read)((fd), (buf), indx)
109
110 /* int rset_write(RSET rs, const void *buf); */
111 #define rset_write(rs, fd, buf) (*(rs)->control->f_write)((fd), (buf))
112
113 /* int rset_type (RSET) */
114 #define rset_type(rs) ((rs)->control->desc)
115
116 #define RSET_FLAG_VOLATILE 1
117
118 #define rset_is_volatile(rs) ((rs)->flags & RSET_FLAG_VOLATILE)
119
120 #ifdef __cplusplus
121 }
122 #endif
123
124 #endif