From 8de955668d904cf9adba5e62bcb871b75e263706 Mon Sep 17 00:00:00 2001 From: Josh Klontz Date: Thu, 11 Jun 2015 16:25:39 -0400 Subject: [PATCH] introduced Template::readUniversalTemplate and Template::freeUniversalTemplate --- openbr/openbr_plugin.cpp | 17 +++++++++++++++++ openbr/openbr_plugin.h | 2 ++ 2 files changed, 19 insertions(+), 0 deletions(-) diff --git a/openbr/openbr_plugin.cpp b/openbr/openbr_plugin.cpp index 08633bb..142c451 100644 --- a/openbr/openbr_plugin.cpp +++ b/openbr/openbr_plugin.cpp @@ -439,6 +439,23 @@ Template Template::fromUniversalTemplate(const br_utemplate &ut) return Template(File(map), m); } +br_utemplate Template::readUniversalTemplate(QFile &file) +{ + const size_t headerSize = sizeof(br_universal_template); + br_universal_template *t = (br_universal_template*) malloc(headerSize); + file.read((char*) t, headerSize); + + const size_t dataSize = t->mdSize + t->fvSize; + t = (br_universal_template*) realloc(t, headerSize + dataSize); + file.read((char*) &t->data, dataSize); + return t; +} + +void Template::freeUniversalTemplate(br_const_utemplate t) +{ + free((void*) t); +} + QDataStream &br::operator<<(QDataStream &stream, const Template &t) { return stream << static_cast&>(t) << t.file; diff --git a/openbr/openbr_plugin.h b/openbr/openbr_plugin.h index ac7ef5e..070bc8c 100644 --- a/openbr/openbr_plugin.h +++ b/openbr/openbr_plugin.h @@ -296,6 +296,8 @@ struct Template : public QList static br_utemplate toUniversalTemplate(const Template &t); static Template fromUniversalTemplate(const br_utemplate &ut); + static br_utemplate readUniversalTemplate(QFile &file); + static void freeUniversalTemplate(br_const_utemplate t); }; BR_EXPORT QDataStream &operator<<(QDataStream &stream, const Template &t); -- libgit2 0.21.4