return pxd_builder_commit (&b);
}
-struct ccase *case_load (struct pxd_object *, const struct pxd *);
+struct ccase *
+case_load (struct pxd_object *object, const struct pxd *pxd)
+{
+ struct caseproto *proto;
+ struct pxd_parser p;
+ struct ccase *c;
+ size_t i;
+
+ pxd_parser_init (&p, object, pxd);
+
+ proto = caseproto_load (pxd_parser_get_link (&p), pxd);
+ c = case_create (proto);
+ for (i = 0; i < caseproto_get_n_widths (proto); i++)
+ pxd_parser_get_value (&p, case_data_rw_idx (c, i),
+ caseproto_get_width (proto, i));
+
+ caseproto_unref (proto);
+
+ pxd_parser_destroy (&p);
+
+ return c;
+}
/* Internal helper function for case_unshare. */
struct ccase *
casereader_destroy (reader);
}
+struct pxd_object *
+casereader_save (const struct casereader *reader_, struct pxd *pxd)
+{
+ struct pxd_array_builder ab;
+ struct casereader *reader;
+ struct pxd_builder b;
+ struct ccase *c;
+
+ pxd_array_builder_init (&ab, pxd);
+ reader = casereader_clone (reader_);
+ while ((c = casereader_read (reader)) != NULL)
+ {
+ pxd_array_builder_add (&ab, case_save (c, pxd));
+ case_unref (c);
+ }
+ casereader_destroy (reader);
+
+ pxd_builder_init (&b, pxd);
+ pxd_builder_put_link (&b, caseproto_save (reader->proto, pxd));
+ pxd_builder_put_link (&b, pxd_array_builder_commit (&ab));
+
+ return pxd_builder_commit (&b);
+}
+
+struct casereader *
+casereader_load (struct pxd_object *object, const struct pxd *pxd)
+{
+ struct casewriter *writer;
+ struct caseproto *proto;
+ struct pxd_array array;
+ struct pxd_parser p;
+ size_t i;
+
+ pxd_parser_init (&p, object, pxd);
+
+ proto = caseproto_load (pxd_parser_get_link (&p), pxd);
+ writer = autopaging_writer_create (proto);
+ caseproto_unref (proto);
+
+ pxd_array_init (&array, pxd_parser_get_link (&p), pxd);
+ for (i = 0; i < pxd_array_size (&array); i++)
+ casewriter_write (writer, case_load (pxd_array_get (&array, i), pxd));
+ pxd_array_destroy (&array);
+
+ pxd_parser_destroy (&p);
+
+ return casewriter_make_reader (writer);
+}
+
+
/* Creates and returns a new casereader. This function is
intended for use by casereader implementations, not by
casereader clients.
casenumber casereader_advance (struct casereader *, casenumber);
void casereader_transfer (struct casereader *, struct casewriter *);
+
+struct pxd_object *casereader_save (const struct casereader *, struct pxd *);
+struct casereader *casereader_load (struct pxd_object *, const struct pxd *);
\f
struct casereader *casereader_create_empty (const struct caseproto *);