subcase
[pspp] / src / data / subcase.c
index 32056215e4ace37d4fcd9b544c3e48c493d82dec..36ee9bf32758177ce79b37994058db5a53ed8e61 100644 (file)
@@ -1,5 +1,5 @@
 /* PSPP - a program for statistical analysis.
-   Copyright (C) 2008, 2009 Free Software Foundation, Inc.
+   Copyright (C) 2008, 2009, 2010 Free Software Foundation, Inc.
 
    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
@@ -163,6 +163,17 @@ subcase_add_var_always (struct subcase *sc, const struct variable *var,
                              var_get_width (var), direction);
 }
 
+void
+subcase_add_vars_always (struct subcase *sc,
+                         const struct variable *const *vars, size_t n_vars,
+                         enum subcase_direction direction)
+{
+  size_t i;
+
+  for (i = 0; i < n_vars; i++)
+    subcase_add_var_always (sc, vars[i], direction);
+}
+
 /* Add a field for CASE_INDEX, WIDTH to SC, with DIRECTION as the
    sort order, regardless of whether CASE_INDEX already has a
    field in SC. */
@@ -201,6 +212,39 @@ subcase_add_proto_always (struct subcase *sc, const struct caseproto *proto)
   invalidate_proto (sc);
 }
 
+void
+subcase_concat (struct subcase *sc, const struct subcase *other)
+{
+  size_t i;
+
+  for (i = 0; i < other->n_fields; i++)
+    {
+      const struct subcase_field *f = &other->fields[i];
+      subcase_add (sc, f->case_index, f->width, f->direction);
+    }
+}
+
+void
+subcase_concat_always (struct subcase *sc, const struct subcase *other)
+{
+  size_t i;
+
+  for (i = 0; i < other->n_fields; i++)
+    {
+      const struct subcase_field *f = &other->fields[i];
+      subcase_add_always (sc, f->case_index, f->width, f->direction);
+    }
+}
+
+void
+subcase_project (struct subcase *sc, size_t offset)
+{
+  size_t i;
+
+  for (i = 0; i < sc->n_fields; i++)
+    sc->fields[i].case_index = i + offset;
+}
+
 /* Obtains a caseproto for a case described by SC.  The caller
    must not modify or unref the returned case prototype. */
 const struct caseproto *