From 82d4407c78036aadfbd75824e50c7438e667aafd Mon Sep 17 00:00:00 2001 From: Elnur Ismailzada Date: Fri, 17 May 2019 00:36:58 +0200 Subject: [PATCH] vector -> set --- src/QZXing.cpp | 4 ++-- src/QZXing.h | 4 +++- src/zxing/zxing/DecodeHints.cpp | 13 ++++++++----- src/zxing/zxing/DecodeHints.h | 8 ++++---- src/zxing/zxing/oned/UPCEANReader.cpp | 2 +- 5 files changed, 18 insertions(+), 13 deletions(-) diff --git a/src/QZXing.cpp b/src/QZXing.cpp index ebbf84c..522b170 100644 --- a/src/QZXing.cpp +++ b/src/QZXing.cpp @@ -112,9 +112,9 @@ bool QZXing::getTryHarder() } void QZXing::setAllowedExtensions(const QVariantList& extensions) { - std::vector allowedExtensions; + std::set allowedExtensions; for (const QVariant& extension: extensions) { - allowedExtensions.push_back(extension.toInt()); + allowedExtensions.insert(extension.toInt()); } allowedExtensions_ = allowedExtensions; diff --git a/src/QZXing.h b/src/QZXing.h index 6350529..b35bc8d 100644 --- a/src/QZXing.h +++ b/src/QZXing.h @@ -24,6 +24,8 @@ #include #include +#include + #if QT_VERSION >= 0x050000 class QQmlEngine; #endif @@ -220,7 +222,7 @@ private: QString charSet_; bool tryHarder_; bool lastDecodeOperationSucceded_; - std::vector allowedExtensions_; + std::set allowedExtensions_; /** * If true, the decoding operation will take place at a different thread. diff --git a/src/zxing/zxing/DecodeHints.cpp b/src/zxing/zxing/DecodeHints.cpp index 777a0b4..63b9c62 100644 --- a/src/zxing/zxing/DecodeHints.cpp +++ b/src/zxing/zxing/DecodeHints.cpp @@ -77,6 +77,7 @@ const zxing::DecodeHints DecodeHints::DEFAULT_HINT( DecodeHints::DecodeHints() { hints = 0; + allowedEanExtensions = {}; } DecodeHints::DecodeHints(const zxing::DecodeHintType &init) { @@ -151,11 +152,11 @@ bool DecodeHints::getTryHarder() const { return (hints & TRYHARDER_HINT) != 0; } -void DecodeHints::setAllowedEanExtensions(std::vector toset) { +void DecodeHints::setAllowedEanExtensions(std::set toset) { allowedEanExtensions = toset; } -std::vector DecodeHints::getAllowedEanExtensions() const { +std::set DecodeHints::getAllowedEanExtensions() const { return allowedEanExtensions; } @@ -181,8 +182,10 @@ zxing::DecodeHints zxing::operator | (DecodeHints const& l, DecodeHints const& r if (!result.callback) { result.callback = r.callback; } - if (result.allowedEanExtensions.empty()) { - result.allowedEanExtensions = r.allowedEanExtensions; - } + + result.allowedEanExtensions = l.allowedEanExtensions; + result.allowedEanExtensions.insert(r.allowedEanExtensions.begin(), + r.allowedEanExtensions.end()); + return result; } diff --git a/src/zxing/zxing/DecodeHints.h b/src/zxing/zxing/DecodeHints.h index 4a98695..f5261b4 100644 --- a/src/zxing/zxing/DecodeHints.h +++ b/src/zxing/zxing/DecodeHints.h @@ -23,7 +23,7 @@ #include #include -#include +#include namespace zxing { @@ -35,7 +35,7 @@ class DecodeHints { private: DecodeHintType hints; Ref callback; - std::vector allowedEanExtensions; + std::set allowedEanExtensions; public: static const DecodeHintType AZTEC_HINT; @@ -78,8 +78,8 @@ class DecodeHints { void setTryHarder(bool toset); bool getTryHarder() const; - void setAllowedEanExtensions(std::vector toset); - std::vector getAllowedEanExtensions() const; + void setAllowedEanExtensions(std::set toset); + std::set getAllowedEanExtensions() const; void setResultPointCallback(Ref const&); Ref getResultPointCallback() const; diff --git a/src/zxing/zxing/oned/UPCEANReader.cpp b/src/zxing/zxing/oned/UPCEANReader.cpp index c25c9a8..0853871 100644 --- a/src/zxing/zxing/oned/UPCEANReader.cpp +++ b/src/zxing/zxing/oned/UPCEANReader.cpp @@ -177,7 +177,7 @@ Ref UPCEANReader::decodeRow(int rowNumber, // continue } - std::vector allowedExtensions = hints.getAllowedEanExtensions(); + std::set allowedExtensions = hints.getAllowedEanExtensions(); if (allowedExtensions.size() > 0) { bool valid = false; for (int length: allowedExtensions) {