Commit c8ef18525863612736706edb685aef4fcfc06966

Authored by Josh Klontz
1 parent be7b6151

added TemplateList::fromBuffer

openbr/openbr_plugin.cpp
@@ -476,6 +476,18 @@ TemplateList TemplateList::fromGallery(const br::File &gallery) @@ -476,6 +476,18 @@ TemplateList TemplateList::fromGallery(const br::File &gallery)
476 return templates; 476 return templates;
477 } 477 }
478 478
  479 +TemplateList TemplateList::fromBuffer(const QByteArray &buffer)
  480 +{
  481 + TemplateList templateList;
  482 + QDataStream stream(buffer);
  483 + while (!stream.atEnd()) {
  484 + Template t;
  485 + stream >> t;
  486 + templateList.append(t);
  487 + }
  488 + return templateList;
  489 +}
  490 +
479 // indexes some property, assigns an integer id to each unique value of propName 491 // indexes some property, assigns an integer id to each unique value of propName
480 // stores the index values in "Label" of the output template list 492 // stores the index values in "Label" of the output template list
481 TemplateList TemplateList::relabel(const TemplateList &tl, const QString &propName, bool preserveIntegers) 493 TemplateList TemplateList::relabel(const TemplateList &tl, const QString &propName, bool preserveIntegers)
openbr/openbr_plugin.h
@@ -437,6 +437,9 @@ struct TemplateList : public QList<Template> @@ -437,6 +437,9 @@ struct TemplateList : public QList<Template>
437 TemplateList(const QList<File> &files) : uniform(false) { foreach (const File &file, files) append(file); } /*!< \brief Initialize the template list from a file list. */ 437 TemplateList(const QList<File> &files) : uniform(false) { foreach (const File &file, files) append(file); } /*!< \brief Initialize the template list from a file list. */
438 BR_EXPORT static TemplateList fromGallery(const File &gallery); /*!< \brief Create a template list from a br::Gallery. */ 438 BR_EXPORT static TemplateList fromGallery(const File &gallery); /*!< \brief Create a template list from a br::Gallery. */
439 439
  440 + /*!< \brief Create a template list from a memory buffer of individual templates. Compatible with '.gal' galleries. */
  441 + BR_EXPORT static TemplateList fromBuffer(const QByteArray &buffer);
  442 +
440 /*!< \brief Ensure labels are in the range [0,numClasses-1]. */ 443 /*!< \brief Ensure labels are in the range [0,numClasses-1]. */
441 BR_EXPORT static TemplateList relabel(const TemplateList &tl, const QString &propName, bool preserveIntegers); 444 BR_EXPORT static TemplateList relabel(const TemplateList &tl, const QString &propName, bool preserveIntegers);
442 445
openbr/plugins/gallery.cpp
@@ -85,6 +85,9 @@ BR_REGISTER(Gallery, arffGallery) @@ -85,6 +85,9 @@ BR_REGISTER(Gallery, arffGallery)
85 /*! 85 /*!
86 * \ingroup galleries 86 * \ingroup galleries
87 * \brief A binary gallery. 87 * \brief A binary gallery.
  88 + *
  89 + * Designed to be a literal translation of templates to disk.
  90 + * Compatible with TemplateList::fromBuffer.
88 * \author Josh Klontz \cite jklontz 91 * \author Josh Klontz \cite jklontz
89 */ 92 */
90 class galGallery : public Gallery 93 class galGallery : public Gallery