1 /* PSPP - a program for statistical analysis.
2 Copyright (C) 1997-9, 2000, 2006, 2009, 2011, 2013 Free Software Foundation, Inc.
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.
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.
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/>. */
19 #include "data/transformations.h"
24 #include "libpspp/str.h"
26 #include "gl/xalloc.h"
29 trns_chain_init (struct trns_chain *chain)
31 *chain = (struct trns_chain) TRNS_CHAIN_INIT;
35 trns_chain_uninit (struct trns_chain *chain)
38 for (size_t i = 0; i < chain->n; i++)
40 struct transformation *xform = &chain->xforms[i];
41 if (xform->class->destroy)
42 ok = xform->class->destroy (xform->aux) && ok;
49 trns_chain_clear (struct trns_chain *chain)
51 bool ok = trns_chain_uninit (chain);
52 trns_chain_init (chain);
57 trns_chain_append (struct trns_chain *chain, const struct transformation *t)
59 if (chain->n >= chain->allocated)
60 chain->xforms = x2nrealloc (chain->xforms, &chain->allocated,
61 sizeof *chain->xforms);
63 chain->xforms[chain->n++] = *t;
67 trns_chain_splice (struct trns_chain *dst, struct trns_chain *src)
69 if (dst->n + src->n >= dst->allocated)
71 dst->allocated = dst->n + src->n;
72 dst->xforms = xrealloc (dst->xforms,
73 dst->allocated * sizeof *dst->xforms);
76 memcpy (&dst->xforms[dst->n], src->xforms, src->n * sizeof *src->xforms);
81 /* Executes the N transformations in XFORMS against case *C passing CASE_NR as
82 the case number. The transformations may replace *C by a new case. Returns
83 the result code that caused the transformations to terminate, or
84 TRNS_CONTINUE if the transformations finished due to "falling off the end"
85 of the set of transformations. */
87 trns_chain_execute (const struct trns_chain *chain,
88 casenumber case_nr, struct ccase **c)
90 for (size_t i = 0; i < chain->n; i++)
92 const struct transformation *trns = &chain->xforms[i];
93 int retval = trns->class->execute (trns->aux, c, case_nr);
94 if (retval != TRNS_CONTINUE)