From 879b2db4e70b05736a25287288d8c5ecf2c6d6ab Mon Sep 17 00:00:00 2001 From: bhklein Date: Mon, 26 Jan 2015 17:31:55 -0500 Subject: [PATCH] Construct QList of TemplatePair futures to maintain metadata file order --- openbr/janus_io.cpp | 32 +++++++++++++++++++++----------- 1 file changed, 21 insertions(+), 11 deletions(-) diff --git a/openbr/janus_io.cpp b/openbr/janus_io.cpp index 531fba4..fbf40e8 100644 --- a/openbr/janus_io.cpp +++ b/openbr/janus_io.cpp @@ -37,29 +37,39 @@ janus_error janus_create_gallery(const char *data_path, janus_metadata metadata, return JANUS_SUCCESS; } +typedef QPair TemplatePair; + +TemplatePair _janus_create_flat_template(const char *data_path, TemplateData templateData, bool verbose) +{ + janus_template template_; + janus_template_id templateID; + JANUS_ASSERT(TemplateIterator::create(data_path, templateData, &template_, &templateID, verbose)) + return TemplatePair(templateID, FlatTemplate(template_)); +} + janus_error janus_create_templates(const char *data_path, janus_metadata metadata, const char *gallery_file, int verbose) { TemplateIterator ti(metadata, true); TemplateData templateData = ti.next(); - unsigned int num_templates = 1; - janus_gallery gallery; - JANUS_ASSERT(janus_allocate_gallery(&gallery)) - QFutureSynchronizer futures; + QFutureSynchronizer futures; while (!templateData.templateIDs.empty()) { - futures.addFuture(QtConcurrent::run(_janus_create_template, data_path, templateData, gallery, verbose)); + futures.addFuture(QtConcurrent::run(_janus_create_flat_template, data_path, templateData, verbose)); templateData = ti.next(); - num_templates++; } futures.waitForFinished(); - janus_flat_gallery flat_gallery = new janus_data[num_templates*janus_max_template_size()]; - size_t bytes; - JANUS_ASSERT(janus_flatten_gallery(gallery, flat_gallery, &bytes)) + QList< QFuture > flat_templates = futures.futures(); std::ofstream file; file.open(gallery_file, std::ios::out | std::ios::binary); - file.write((char*)flat_gallery, bytes); + foreach (const QFuture &future, flat_templates) { + janus_template_id templateID = future.result().first; + FlatTemplate flatTemplate = future.result().second; + file.write((char*)&templateID, sizeof(templateID)); + file.write((char*)&flatTemplate.data->bytes, sizeof(flatTemplate.data->bytes)); + file.write((char*)flatTemplate.data->flat_template, flatTemplate.data->bytes); + } + file.close(); - delete[] flat_gallery; return JANUS_SUCCESS; } -- libgit2 0.21.4