Clean up how transformations work.
[pspp] / src / data / transformations.h
1 /* PSPP - a program for statistical analysis.
2    Copyright (C) 1997-9, 2000, 2006, 2009, 2011 Free Software Foundation, Inc.
3
4    This program is free software: you can redistribute it and/or modify
5    it under the terms of the GNU General Public License as published by
6    the Free Software Foundation, either version 3 of the License, or
7    (at your option) any later version.
8
9    This program is distributed in the hope that it will be useful,
10    but WITHOUT ANY WARRANTY; without even the implied warranty of
11    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12    GNU General Public License for more details.
13
14    You should have received a copy of the GNU General Public License
15    along with this program.  If not, see <http://www.gnu.org/licenses/>. */
16
17 #ifndef TRANSFORMATIONS_H
18 #define TRANSFORMATIONS_H 1
19
20 #include <stdbool.h>
21 #include <stddef.h>
22 #include "data/case.h"
23
24 /* One transformation. */
25
26 enum trns_result
27   {
28     TRNS_CONTINUE,              /* Continue to next transformation. */
29     TRNS_BREAK,                 /* Break out of LOOP. */
30     TRNS_DROP_CASE,             /* Drop this case. */
31     TRNS_ERROR,                 /* A serious error, so stop the procedure. */
32     TRNS_END_CASE,              /* Skip to next case.  INPUT PROGRAM only. */
33     TRNS_END_FILE               /* End of input.  INPUT PROGRAM only. */
34   };
35
36 struct ccase;
37
38 struct trns_class
39   {
40     const char *name;           /* For debugging. */
41     enum trns_result (*execute) (void *aux, struct ccase **, casenumber);
42     bool (*destroy) (void *aux);
43   };
44
45 struct transformation
46   {
47     const struct trns_class *class;
48     void *aux;
49   };
50 \f
51 /* A chain of transformations. */
52
53 struct trns_chain
54   {
55     struct transformation *xforms;
56     size_t n;
57     size_t allocated;
58   };
59
60 #define TRNS_CHAIN_INIT { .n = 0 }
61
62 void trns_chain_init (struct trns_chain *);
63 bool trns_chain_uninit (struct trns_chain *);
64
65 bool trns_chain_clear (struct trns_chain *);
66
67 void trns_chain_append (struct trns_chain *, const struct transformation *);
68 void trns_chain_splice (struct trns_chain *, struct trns_chain *);
69
70 enum trns_result trns_chain_execute (const struct trns_chain *,
71                                      casenumber case_num, struct ccase **);
72
73 #endif /* transformations.h */