eddf6abaa51b03a4db5f72fc62b459099ed5c9fc
[pspp-builds.git] / src / data / casefile-private.h
1 /* PSPP - computes sample statistics.
2    Copyright (C) 2004, 2006 Free Software Foundation, Inc.
3    Written by Ben Pfaff <blp@gnu.org>.
4
5    This program is free software; you can redistribute it and/or
6    modify it under the terms of the GNU General Public License as
7    published by the Free Software Foundation; either version 2 of the
8    License, or (at your option) any later version.
9
10    This program is distributed in the hope that it will be useful, but
11    WITHOUT ANY WARRANTY; without even the implied warranty of
12    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13    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., 51 Franklin Street, Fifth Floor, Boston, MA
18    02110-1301, USA. */
19
20 #ifndef CASEFILE_PRIVATE_H
21 #define CASEFILE_PRIVATE_H
22
23 #include <config.h>
24 #include <stdbool.h>
25 #include <libpspp/ll.h>
26
27 struct ccase;
28 struct casereader;
29 struct casefile;
30 struct casefilter;
31
32 struct class_casefile
33 {
34   void (*destroy) (struct casefile *) ;
35
36   bool (*error) (const struct casefile *) ;
37
38   size_t (*get_value_cnt) (const struct casefile *) ;
39   unsigned long (*get_case_cnt) (const struct casefile *) ;
40
41   struct casereader * (*get_reader) (const struct casefile *) ; 
42
43   bool (*append) (struct casefile *, const struct ccase *) ;
44
45
46   bool (*in_core) (const struct casefile *) ;
47   bool (*to_disk) (const struct casefile *) ;
48   bool (*sleep) (const struct casefile *) ;
49 };
50
51 struct casefile
52 {
53   const struct class_casefile *class ;   /* Class pointer */
54
55   struct ll_list reader_list ;       /* List of our readers. */
56   struct ll ll ;                    /* Element in the class' list 
57                                        of casefiles. */
58   bool being_destroyed;            /* A destructive reader exists */
59 };
60
61
62 struct class_casereader
63 {
64   struct ccase * (*get_next_case) (struct casereader *);
65
66   unsigned long (*cnum) (const struct casereader *);
67
68   void (*destroy) (struct casereader * r);
69
70   struct casereader * (*clone) (const struct casereader *);
71 };
72
73
74 #define CLASS_CASEREADER(K) ( (struct class_casereader *) K)
75
76 struct casereader
77 {
78   const struct class_casereader *class;  /* Class pointer */
79
80   struct casefile *cf;   /* The casefile to which this reader belongs */
81   struct ll ll;          /* Element in the casefile's list of readers */
82
83   struct casefilter *filter; /* The filter to be used */
84   bool destructive;      /* True if this reader is destructive */
85 };
86
87
88 #define CASEFILE(C)        ( (struct casefile *) C)
89 #define CONST_CASEFILE(C) ( (const struct casefile *) C)
90
91 #define CASEFILEREADER(CR) ((struct casereader *) CR)
92
93
94 /* Functions for implementations' use  only */
95
96 void casefile_register (struct casefile *cf, 
97                         const struct class_casefile *k);
98
99 void casereader_register (struct casefile *cf, 
100                           struct casereader *reader, 
101                           const struct class_casereader *k);
102
103 #endif