From 400d5e7d2b0c848b092bccbd55591e8ccac658de Mon Sep 17 00:00:00 2001 From: Josh Klontz Date: Thu, 26 Feb 2015 11:36:45 -0500 Subject: [PATCH] br_iterate_utemplates_file now returns the number of templates iterated --- openbr/universal_template.cpp | 8 +++++--- openbr/universal_template.h | 3 ++- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/openbr/universal_template.cpp b/openbr/universal_template.cpp index 8b7d18d..9ddf732 100644 --- a/openbr/universal_template.cpp +++ b/openbr/universal_template.cpp @@ -74,15 +74,16 @@ static bool read_buffer(FILE *file, char *buffer, size_t bytes, bool eofAllowed) return true; } -void br_iterate_utemplates_file(FILE *file, br_utemplate_callback callback, br_callback_context context, bool parallel) +int br_iterate_utemplates_file(FILE *file, br_utemplate_callback callback, br_callback_context context, bool parallel) { + int count = 0; QFutureSynchronizer futures; while (true) { br_utemplate t = (br_utemplate) malloc(sizeof(br_universal_template)); if (!read_buffer(file, (char*) t, sizeof(br_universal_template), true)) { free(t); - return; + break; } t = (br_utemplate) realloc(t, sizeof(br_universal_template) + t->urlSize + t->fvSize); @@ -90,8 +91,9 @@ void br_iterate_utemplates_file(FILE *file, br_utemplate_callback callback, br_c if (parallel) futures.addFuture(QtConcurrent::run(callAndFree, callback, t, context)); else callAndFree(callback, t, context); + count++; } - futures.waitForFinished(); + return count; } void br_log(const char *message) diff --git a/openbr/universal_template.h b/openbr/universal_template.h index 733175e..edb90d4 100644 --- a/openbr/universal_template.h +++ b/openbr/universal_template.h @@ -86,9 +86,10 @@ BR_EXPORT void br_iterate_utemplates(br_const_utemplate begin, br_const_utemplat /*! * \brief Iterate over br_universal_template in a file. + * \return The number of templates iterated * \see br_iterate_utemplates */ -BR_EXPORT void br_iterate_utemplates_file(FILE *file, br_utemplate_callback callback, br_callback_context context, bool parallel); +BR_EXPORT int br_iterate_utemplates_file(FILE *file, br_utemplate_callback callback, br_callback_context context, bool parallel); /*! * \brief Write a message annotated with the current time to stderr. -- libgit2 0.21.4