From: Ben Pfaff Date: Sun, 6 Dec 2009 02:30:51 +0000 (-0800) Subject: casereader: New function casereader_create_empty(). X-Git-Tag: sid-i386-build115~1 X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=9f41517ea7a60d879496d4b1cbb3c37a529296ab;p=pspp-builds.git casereader: New function casereader_create_empty(). --- diff --git a/src/data/casereader.c b/src/data/casereader.c index 77278851..57afff84 100644 --- a/src/data/casereader.c +++ b/src/data/casereader.c @@ -699,3 +699,42 @@ static const struct casereader_random_class shim_class = shim_destroy, shim_advance, }; + +static const struct casereader_class casereader_null_class; + +/* Returns a casereader with no cases. The casereader has the prototype + specified by PROTO. PROTO may be specified as a null pointer, in which case + the casereader has no variables. */ +struct casereader * +casereader_create_empty (const struct caseproto *proto_) +{ + struct casereader *reader; + struct caseproto *proto; + + proto = proto_ != NULL ? caseproto_ref (proto_) : caseproto_create (); + reader = casereader_create_sequential (NULL, proto, 0, + &casereader_null_class, NULL); + caseproto_unref (proto); + + return reader; +} + +static struct ccase * +casereader_null_read (struct casereader *reader UNUSED, void *aux UNUSED) +{ + return NULL; +} + +static void +casereader_null_destroy (struct casereader *reader UNUSED, void *aux UNUSED) +{ + /* Nothing to do. */ +} + +static const struct casereader_class casereader_null_class = + { + casereader_null_read, + casereader_null_destroy, + NULL, /* clone */ + NULL, /* peek */ + }; diff --git a/src/data/casereader.h b/src/data/casereader.h index fb9d50ff..5300ee1d 100644 --- a/src/data/casereader.h +++ b/src/data/casereader.h @@ -83,6 +83,8 @@ const struct caseproto *casereader_get_proto (const struct casereader *); casenumber casereader_advance (struct casereader *, casenumber); void casereader_transfer (struct casereader *, struct casewriter *); +struct casereader *casereader_create_empty (const struct caseproto *); + struct casereader * casereader_create_filter_func (struct casereader *, bool (*include) (const struct ccase *,