From 392c853531c97fd8192cea98ab7c8e067436bf8b Mon Sep 17 00:00:00 2001 From: Ben Pfaff Date: Wed, 31 Mar 2010 22:06:28 -0700 Subject: [PATCH] subcase --- src/data/subcase.c | 20 ++++++++++++++++++++ src/data/subcase.h | 13 ++++++++++--- 2 files changed, 30 insertions(+), 3 deletions(-) diff --git a/src/data/subcase.c b/src/data/subcase.c index bac32ddefb..36ee9bf327 100644 --- a/src/data/subcase.c +++ b/src/data/subcase.c @@ -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. */ @@ -225,6 +236,15 @@ subcase_concat_always (struct subcase *sc, const struct subcase *other) } } +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 * diff --git a/src/data/subcase.h b/src/data/subcase.h index ba4119b346..88992bb9dd 100644 --- a/src/data/subcase.h +++ b/src/data/subcase.h @@ -67,27 +67,28 @@ bool subcase_add (struct subcase *, int case_index, int width, enum subcase_direction direction); bool subcase_add_var (struct subcase *, const struct variable *, enum subcase_direction); -bool subcase_add_vars (struct subcase *, const struct variable *const *, +void subcase_add_vars (struct subcase *, const struct variable *const *, size_t n_vars, enum subcase_direction); void subcase_add_always (struct subcase *sc, int case_index, int width, enum subcase_direction direction); void subcase_add_var_always (struct subcase *, const struct variable *, enum subcase_direction); -bool subcase_add_vars_always (struct subcase *, const struct variable *const *, +void subcase_add_vars_always (struct subcase *, const struct variable *const *, size_t n_vars, enum subcase_direction); void subcase_add_proto_always (struct subcase *, const struct caseproto *); void subcase_concat (struct subcase *, const struct subcase *); void subcase_concat_always (struct subcase *, const struct subcase *); -void subcase_project (struct subcase *); +void subcase_project (struct subcase *, size_t offset); const struct caseproto *subcase_get_proto (const struct subcase *); static inline bool subcase_is_empty (const struct subcase *); static inline size_t subcase_get_n_fields (const struct subcase *); +static inline size_t subcase_get_width (const struct subcase *, size_t idx); static inline size_t subcase_get_case_index (const struct subcase *, size_t idx); static inline enum subcase_direction subcase_get_direction ( @@ -125,6 +126,12 @@ subcase_get_case_index (const struct subcase *sc, size_t idx) return sc->fields[idx].case_index; } +static inline size_t +subcase_get_width (const struct subcase *sc, size_t idx) +{ + return sc->fields[idx].width; +} + static inline enum subcase_direction subcase_get_direction (const struct subcase *sc, size_t idx) { -- 2.30.2