Introduced ZXING_NULLPTR and ZXING_NOEXCEPT to abstract differences between C+11 and non-C++11 compilers

Fixed warnings in QZXingFilter.cpp
Removed C++11 requirement from all .pro files
Set compiler warning flags via CONFIG += warn_on instead of using GCC specific switches
This commit is contained in:
Alexander Stillich 2018-11-16 13:05:58 +01:00
parent ac5083feea
commit 3f3a89b2ba
33 changed files with 110 additions and 101 deletions

View File

@ -1,8 +1,6 @@
QT += qml quick
CONFIG += c++11 qzxing_qml
gcc:QMAKE_CXXFLAGS += -Wall -Wextra
CONFIG += qzxing_qml
SOURCES += main.cpp

View File

@ -4,8 +4,6 @@ VERSION = 1.1.0
QT += declarative network
gcc:QMAKE_CXXFLAGS += -Wall -Wextra
!maemo5 {
contains(QT_CONFIG, opengl) {
# QT += opengl

View File

@ -1,14 +1,12 @@
# Add more folders to ship with the application, here
DEPLOYMENTFOLDERS = folder_01
folder_01.source = qml/QZXingDragNDropTest
folder_01.target = qml
DEPLOYMENTFOLDERS = folder_01
QT += widgets
CONFIG += qzxing_qml
gcc:QMAKE_CXXFLAGS += -Wall -Wextra
# Additional import path used to resolve QML modules in Creator's code model
QML_IMPORT_PATH =

View File

@ -1,8 +1,6 @@
TEMPLATE = app
CONFIG += c++11 qzxing_multimedia
gcc:QMAKE_CXXFLAGS += -Wall -Wextra
CONFIG += qzxing_multimedia
CONFIG(debug, debug|release) {
CONFIG+=qml_debug

View File

@ -332,7 +332,7 @@ QString QZXing::decodeImage(const QImage &image, int maxWidth, int maxHeight, bo
return "";
}
CameraImageWrapper *ciw = nullptr;
CameraImageWrapper *ciw = ZXING_NULLPTR;
if ((maxWidth > 0) || (maxHeight > 0))
ciw = CameraImageWrapper::Factory(image, maxWidth, maxHeight, smoothTransformation);
@ -440,7 +440,7 @@ QString QZXing::decodeSubImageQML(QObject *item,
const int offsetX, const int offsetY,
const int width, const int height)
{
if(item == nullptr)
if(item == ZXING_NULLPTR)
{
processingTime = 0;
emit decodingFinished(false);

View File

@ -18,6 +18,8 @@
#define QZXING_H
#include "QZXing_global.h"
#include "zxing/ZXing.h"
#include <QObject>
#include <QImage>
@ -91,10 +93,10 @@ public:
EncodeErrorCorrectionLevel_H
};
QZXing(QObject *parent = NULL);
QZXing(QObject *parent = ZXING_NULLPTR);
~QZXing();
QZXing(DecoderFormat decodeHints, QObject *parent = NULL);
QZXing(DecoderFormat decodeHints, QObject *parent = ZXING_NULLPTR);
#ifdef QZXING_QML

View File

@ -14,7 +14,7 @@
# limitations under the License.
#
CONFIG += qt
CONFIG += qt warn_on
DEFINES += QZXING_LIBRARY \
ZXING_ICONV_CONST \

View File

@ -22,7 +22,6 @@ TARGET = QZXing
TEMPLATE = lib
# CONFIG += staticlib
gcc:QMAKE_CXXFLAGS += -Wall -Wextra
DEFINES -= DISABLE_LIBRARY_FEATURES
symbian {

View File

@ -1,3 +1,4 @@
#include "zxing/ZXing.h"
#include "QZXingFilter.h"
#include <QDebug>
@ -14,13 +15,13 @@ namespace {
}
uchar yuvToGray(uchar Y, uchar U, uchar V)
{
const int C = (int) Y - 16;
const int D = (int) U - 128;
const int E = (int) V - 128;
const int C = int(Y) - 16;
const int D = int(U) - 128;
const int E = int(V) - 128;
return gray(
qBound(0, (298 * C + 409 * E + 128) >> 8, 255),
qBound(0, (298 * C - 100 * D - 208 * E + 128) >> 8, 255),
qBound(0, (298 * C + 516 * D + 128) >> 8, 255)
qBound<uchar>(0, uchar((298 * C + 409 * E + 128) >> 8), 255),
qBound<uchar>(0, uchar((298 * C - 100 * D - 208 * E + 128) >> 8), 255),
qBound<uchar>(0, uchar((298 * C + 516 * D + 128) >> 8), 255)
);
}
}
@ -68,14 +69,14 @@ QVideoFilterRunnable * QZXingFilter::createFilterRunnable()
///
QZXingFilterRunnable::QZXingFilterRunnable(QZXingFilter * filter)
: QObject(nullptr)
: QObject(ZXING_NULLPTR)
, filter(filter)
{
}
QZXingFilterRunnable::~QZXingFilterRunnable()
{
filter = nullptr;
filter = ZXING_NULLPTR;
}
QVideoFrame QZXingFilterRunnable::run(QVideoFrame * input, const QVideoSurfaceFormat &surfaceFormat, RunFlags flags)
@ -133,6 +134,8 @@ struct CaptureRect
{}
bool isValid;
char pad[3]; // avoid warning about padding
int sourceWidth;
int sourceHeight;
@ -172,9 +175,9 @@ static QImage* rgbDataToGrayscale(const uchar* data, const CaptureRect& captureR
uchar b = data[blue];
if (isPremultiplied) {
uchar a = data[alpha];
r = (uint(r) * 255) / a;
g = (uint(g) * 255) / a;
b = (uint(b) * 255) / a;
r = uchar((uint(r) * 255) / a);
g = uchar((uint(g) * 255) / a);
b = uchar((uint(b) * 255) / a);
}
*pixel = gray(r, g, b);
++pixel;
@ -194,17 +197,17 @@ void QZXingFilterRunnable::processVideoFrameProbed(SimpleVideoFrame & videoFrame
const int width = videoFrame.size.width();
const int height = videoFrame.size.height();
const CaptureRect captureRect(_captureRect, width, height);
const uchar* data = (uchar*) videoFrame.data.constData();
const uchar* data = reinterpret_cast<const uchar *>(videoFrame.data.constData());
uchar* pixel;
int wh;
int w_2;
int wh_54;
uint32_t *yuvPtr = (uint32_t *)data;
const uint32_t *yuvPtr = reinterpret_cast<const uint32_t *>(data);
/// Create QImage from QVideoFrame.
QImage *image_ptr = nullptr;
QImage *image_ptr = ZXING_NULLPTR;
switch (videoFrame.pixelFormat) {
case QVideoFrame::Format_RGB32:
@ -287,12 +290,12 @@ void QZXingFilterRunnable::processVideoFrameProbed(SimpleVideoFrame & videoFrame
pixel = image_ptr->bits();
for (int y = captureRect.startY; y < captureRect.endY; y++){
uint32_t *row = &yuvPtr[y*(width/2)-(width/4)];
const uint32_t *row = &yuvPtr[y*(width/2)-(width/4)];
for (int x = captureRect.startX; x < captureRect.endX; x++){
uint32_t pxl = row[x];
const int y0 = (unsigned char)((uint8_t *)&pxl)[0];
const int u = (unsigned char)((uint8_t *)&pxl)[1];
const int v = (unsigned char)((uint8_t *)&pxl)[3];
const uint8_t *pxl = reinterpret_cast<const uint8_t *>(&row[x]);
const uint8_t y0 = pxl[0];
const uint8_t u = pxl[1];
const uint8_t v = pxl[3];
*pixel = yuvToGray(y0, u, v);
++pixel;
}
@ -333,6 +336,6 @@ void QZXingFilterRunnable::processVideoFrameProbed(SimpleVideoFrame & videoFrame
QString QZXingFilterRunnable::decode(const QImage &image)
{
return (filter != nullptr) ?
return (filter != ZXING_NULLPTR) ?
filter->decoder.decodeImage(image, image.width(), image.height()) : QString();
}

View File

@ -23,6 +23,6 @@
using zxing::ChecksumException;
ChecksumException::ChecksumException() noexcept {}
ChecksumException::ChecksumException(const char *msg) noexcept : ReaderException(msg) {}
ChecksumException::~ChecksumException() noexcept {}
ChecksumException::ChecksumException() ZXING_NOEXCEPT {}
ChecksumException::ChecksumException(const char *msg) ZXING_NOEXCEPT : ReaderException(msg) {}
ChecksumException::~ChecksumException() ZXING_NOEXCEPT {}

View File

@ -24,9 +24,9 @@
namespace zxing {
class ChecksumException : public ReaderException {
public:
ChecksumException() noexcept;
ChecksumException(const char *msg) noexcept;
~ChecksumException() noexcept;
ChecksumException() ZXING_NOEXCEPT;
ChecksumException(const char *msg) ZXING_NOEXCEPT;
~ChecksumException() ZXING_NOEXCEPT;
};
}

View File

@ -26,26 +26,26 @@
using zxing::Exception;
Exception::Exception() noexcept
: message(nullptr) {
Exception::Exception() ZXING_NOEXCEPT
: message(ZXING_NULLPTR) {
}
Exception::Exception(const char *msg) noexcept
Exception::Exception(const char *msg) ZXING_NOEXCEPT
: message(copy(msg)) {
}
Exception::Exception(const zxing::Exception &that) noexcept
Exception::Exception(const zxing::Exception &that) ZXING_NOEXCEPT
: std::exception(that),
message(copy(that.message)) {
}
Exception::~Exception() noexcept {
Exception::~Exception() ZXING_NOEXCEPT {
if(message) {
deleteMessage();
}
}
const char *Exception::what() const noexcept {
const char *Exception::what() const ZXING_NOEXCEPT {
return message ? message : "";
}
@ -54,7 +54,7 @@ void Exception::deleteMessage() {
}
char const* Exception::copy(char const* msg) {
char* message = nullptr;
char* message = ZXING_NULLPTR;
if (msg) {
auto l = strlen(msg)+1;
if (l) {

View File

@ -21,6 +21,8 @@
* limitations under the License.
*/
#include <zxing/ZXing.h>
#include <string>
#include <exception>
@ -31,11 +33,11 @@ private:
char const* const message;
public:
Exception() noexcept;
Exception(const char* msg) noexcept;
Exception(Exception const& that) noexcept;
~Exception() noexcept;
char const* what() const noexcept;
Exception() ZXING_NOEXCEPT;
Exception(const char* msg) ZXING_NOEXCEPT;
Exception(Exception const& that) ZXING_NOEXCEPT;
~Exception() ZXING_NOEXCEPT;
char const* what() const ZXING_NOEXCEPT;
private:
static char const* copy(char const*);

View File

@ -29,7 +29,7 @@ FormatException::FormatException(const char *msg) :
ReaderException(msg) {
}
FormatException::~FormatException() noexcept {
FormatException::~FormatException() ZXING_NOEXCEPT {
}
FormatException const&

View File

@ -28,7 +28,7 @@ class FormatException : public ReaderException {
public:
FormatException();
FormatException(const char *msg);
~FormatException() noexcept;
~FormatException() ZXING_NOEXCEPT;
static FormatException const& getFormatInstance();
};

View File

@ -19,12 +19,12 @@
*/
#include <zxing/IllegalStateException.h>
zxing::IllegalStateException::IllegalStateException() noexcept {
zxing::IllegalStateException::IllegalStateException() ZXING_NOEXCEPT {
}
zxing::IllegalStateException::IllegalStateException(const char *msg) noexcept
zxing::IllegalStateException::IllegalStateException(const char *msg) ZXING_NOEXCEPT
: ReaderException(msg) {
}
zxing::IllegalStateException::~IllegalStateException() noexcept {
zxing::IllegalStateException::~IllegalStateException() ZXING_NOEXCEPT {
}

View File

@ -25,9 +25,9 @@ namespace zxing {
class IllegalStateException : public ReaderException {
public:
IllegalStateException() noexcept;
IllegalStateException(const char *msg) noexcept;
~IllegalStateException() noexcept;
IllegalStateException() ZXING_NOEXCEPT;
IllegalStateException(const char *msg) ZXING_NOEXCEPT;
~IllegalStateException() ZXING_NOEXCEPT;
};
}

View File

@ -19,12 +19,12 @@
*/
#include <zxing/NotFoundException.h>
zxing::NotFoundException::NotFoundException() noexcept {
zxing::NotFoundException::NotFoundException() ZXING_NOEXCEPT {
}
zxing::NotFoundException::NotFoundException(const char *msg) noexcept
zxing::NotFoundException::NotFoundException(const char *msg) ZXING_NOEXCEPT
: ReaderException(msg) {
}
zxing::NotFoundException::~NotFoundException() noexcept {
zxing::NotFoundException::~NotFoundException() ZXING_NOEXCEPT {
}

View File

@ -25,9 +25,9 @@ namespace zxing {
class NotFoundException : public ReaderException {
public:
NotFoundException() noexcept;
NotFoundException(const char *msg) noexcept;
~NotFoundException() noexcept;
NotFoundException() ZXING_NOEXCEPT;
NotFoundException(const char *msg) ZXING_NOEXCEPT;
~NotFoundException() ZXING_NOEXCEPT;
};
}

View File

@ -19,12 +19,12 @@
*/
#include <zxing/ReaderException.h>
zxing::ReaderException::ReaderException() noexcept {
zxing::ReaderException::ReaderException() ZXING_NOEXCEPT {
}
zxing::ReaderException::ReaderException(const char *msg) noexcept
zxing::ReaderException::ReaderException(const char *msg) ZXING_NOEXCEPT
: Exception(msg) {
}
zxing::ReaderException::~ReaderException() noexcept {
zxing::ReaderException::~ReaderException() ZXING_NOEXCEPT {
}

View File

@ -27,9 +27,9 @@ namespace zxing {
class ReaderException : public Exception {
public:
ReaderException() noexcept;
ReaderException(char const* msg) noexcept;
~ReaderException() noexcept;
ReaderException() ZXING_NOEXCEPT;
ReaderException(char const* msg) ZXING_NOEXCEPT;
~ReaderException() ZXING_NOEXCEPT;
};
}

View File

@ -19,12 +19,12 @@
*/
#include <zxing/UnsupportedEncodingException.h>
zxing::UnsupportedEncodingException::UnsupportedEncodingException() noexcept {
zxing::UnsupportedEncodingException::UnsupportedEncodingException() ZXING_NOEXCEPT {
}
zxing::UnsupportedEncodingException::UnsupportedEncodingException(const char *msg) noexcept
zxing::UnsupportedEncodingException::UnsupportedEncodingException(const char *msg) ZXING_NOEXCEPT
: Exception(msg) {
}
zxing::UnsupportedEncodingException::~UnsupportedEncodingException() noexcept {
zxing::UnsupportedEncodingException::~UnsupportedEncodingException() ZXING_NOEXCEPT {
}

View File

@ -7,9 +7,9 @@ namespace zxing {
class UnsupportedEncodingException : public Exception {
public:
UnsupportedEncodingException() noexcept;
UnsupportedEncodingException(char const* msg) noexcept;
~UnsupportedEncodingException() noexcept;
UnsupportedEncodingException() ZXING_NOEXCEPT;
UnsupportedEncodingException(char const* msg) ZXING_NOEXCEPT;
~UnsupportedEncodingException() ZXING_NOEXCEPT;
};
}

View File

@ -19,12 +19,12 @@
*/
#include <zxing/WriterException.h>
zxing::WriterException::WriterException() noexcept {
zxing::WriterException::WriterException() ZXING_NOEXCEPT {
}
zxing::WriterException::WriterException(const char *msg) noexcept
zxing::WriterException::WriterException(const char *msg) ZXING_NOEXCEPT
: Exception(msg) {
}
zxing::WriterException::~WriterException() noexcept {
zxing::WriterException::~WriterException() ZXING_NOEXCEPT {
}

View File

@ -7,9 +7,9 @@ namespace zxing {
class WriterException : public Exception {
public:
WriterException() noexcept;
WriterException(char const* msg) noexcept;
~WriterException() noexcept;
WriterException() ZXING_NOEXCEPT;
WriterException(char const* msg) ZXING_NOEXCEPT;
~WriterException() ZXING_NOEXCEPT;
};
}

View File

@ -151,4 +151,18 @@ private:
#define ZXING_TIME_MARK(string) (void)0
#endif
#ifndef ZXING_NULLPTR
#if __cplusplus >= 201103L
#define ZXING_NULLPTR nullptr
#else
#define ZXING_NULLPTR NULL
#endif
#endif // ZXING_NULLPTR
#if __cplusplus >= 201103L
#define ZXING_NOEXCEPT noexcept
#else
#define ZXING_NOEXCEPT throw()
#endif
#endif

View File

@ -24,4 +24,4 @@ using zxing::IllegalArgumentException;
IllegalArgumentException::IllegalArgumentException() : Exception() {}
IllegalArgumentException::IllegalArgumentException(const char *msg) : Exception(msg) {}
IllegalArgumentException::~IllegalArgumentException() noexcept {}
IllegalArgumentException::~IllegalArgumentException() ZXING_NOEXCEPT {}

View File

@ -28,7 +28,7 @@ class IllegalArgumentException : public Exception {
public:
IllegalArgumentException();
IllegalArgumentException(const char *msg);
~IllegalArgumentException() noexcept;
~IllegalArgumentException() ZXING_NOEXCEPT;
};
}

View File

@ -21,10 +21,10 @@
#include <zxing/common/reedsolomon/ReedSolomonException.h>
namespace zxing {
ReedSolomonException::ReedSolomonException(const char *msg) noexcept :
ReedSolomonException::ReedSolomonException(const char *msg) ZXING_NOEXCEPT :
Exception(msg) {
}
ReedSolomonException::~ReedSolomonException() noexcept {
ReedSolomonException::~ReedSolomonException() ZXING_NOEXCEPT {
}
}

View File

@ -25,8 +25,8 @@
namespace zxing {
class ReedSolomonException : public Exception {
public:
ReedSolomonException(const char *msg) noexcept;
~ReedSolomonException() noexcept;
ReedSolomonException(const char *msg) ZXING_NOEXCEPT;
~ReedSolomonException() ZXING_NOEXCEPT;
};
}

View File

@ -16,7 +16,7 @@ namespace datamatrix {
class DetectorException : public Exception {
public:
DetectorException(const char *msg);
virtual ~DetectorException() noexcept;
virtual ~DetectorException() ZXING_NOEXCEPT;
};
} /* namespace nexxera */
} /* namespace zxing */

View File

@ -39,13 +39,13 @@ int Encoder::calculateMaskPenalty(const ByteMatrix& matrix)
Ref<QRCode> Encoder::encode(const std::string& content, ErrorCorrectionLevel &ecLevel)
{
return encode(content, ecLevel, nullptr);
return encode(content, ecLevel, ZXING_NULLPTR);
}
Ref<QRCode> Encoder::encode(const std::string& content, ErrorCorrectionLevel &ecLevel, const EncodeHint* hints)
{
// Determine what character encoding has been specified by the caller, if any
std::string encoding = hints == nullptr ? "" : hints->getCharacterSet();
std::string encoding = hints == ZXING_NULLPTR ? "" : hints->getCharacterSet();
if (encoding == "")
encoding = DEFAULT_BYTE_MODE_ENCODING;
@ -61,7 +61,7 @@ Ref<QRCode> Encoder::encode(const std::string& content, ErrorCorrectionLevel &ec
if (mode == Mode::BYTE && DEFAULT_BYTE_MODE_ENCODING != encoding) {
zxing::common::CharacterSetECI const * eci =
zxing::common::CharacterSetECI::getCharacterSetECIByName(encoding);
if (eci != nullptr) {
if (eci != ZXING_NULLPTR) {
appendECI(*eci, headerBits);
}
}
@ -75,7 +75,7 @@ Ref<QRCode> Encoder::encode(const std::string& content, ErrorCorrectionLevel &ec
appendBytes(content, mode, dataBits, encoding);
Ref<Version> version;
if (hints != nullptr/* && hints->containsKey(EncodeHintType.QR_VERSION)*/) {
if (hints != ZXING_NULLPTR/* && hints->containsKey(EncodeHintType.QR_VERSION)*/) {
version = Version::getVersionForNumber(1);
int bitsNeeded = calculateBitsNeeded(mode, headerBits, dataBits, version);
if (!willFit(bitsNeeded, version, ecLevel)) {

View File

@ -1,6 +1,3 @@
CONFIG += gnu++11
QMAKE_CXXFLAGS += -std=gnu++11
TARGET = QZXingTests
CONFIG += console
CONFIG -= app_bundle