From 46cd54ab644ef27b3d1db780aea42c8ba68cdae1 Mon Sep 17 00:00:00 2001 From: "smparkes@smparkes.net" Date: Tue, 29 Nov 2011 18:50:25 +0000 Subject: [PATCH] A few portability fixes and one stupid string error (mine). Closes Issue 1082. - remove some uses of floating min/max fns: use the same integer code as java - Generalize counted pointers to compare against pointers instead of just integer 0 - Careless string error I added when porting some java code git-svn-id: https://zxing.googlecode.com/svn/trunk@2054 59b500cc-1b3d-0410-9834-0bbf25fbcc57 --- cpp/core/src/zxing/common/CharacterSetECI.cpp | 5 ++++- cpp/core/src/zxing/common/Counted.h | 12 +++++------- cpp/core/src/zxing/common/ECI.cpp | 5 ++++- cpp/core/src/zxing/oned/Code128Reader.cpp | 10 +++++----- cpp/core/src/zxing/oned/Code39Reader.cpp | 8 ++------ 5 files changed, 20 insertions(+), 20 deletions(-) diff --git a/cpp/core/src/zxing/common/CharacterSetECI.cpp b/cpp/core/src/zxing/common/CharacterSetECI.cpp index 534138cac..4a9b1c2de 100644 --- a/cpp/core/src/zxing/common/CharacterSetECI.cpp +++ b/cpp/core/src/zxing/common/CharacterSetECI.cpp @@ -16,6 +16,7 @@ */ #include +#include #include using std::string; @@ -77,7 +78,9 @@ void CharacterSetECI::addCharacterSet(int value, char const* const* encodingName CharacterSetECI* CharacterSetECI::getCharacterSetECIByValue(int value) { if (value < 0 || value >= 900) { - throw IllegalArgumentException("Bad ECI value: " + value); + std::ostringstream oss; + oss << "Bad ECI value: " << value; + throw IllegalArgumentException(oss.str().c_str()); } return VALUE_TO_ECI[value]; } diff --git a/cpp/core/src/zxing/common/Counted.h b/cpp/core/src/zxing/common/Counted.h index dad79e3ad..ccfcf509c 100644 --- a/cpp/core/src/zxing/common/Counted.h +++ b/cpp/core/src/zxing/common/Counted.h @@ -1,10 +1,8 @@ +// -*- mode:c++; tab-width:2; indent-tabs-mode:nil; c-basic-offset:2 -*- #ifndef __COUNTED_H__ #define __COUNTED_H__ /* - * Counted.h - * zxing - * * Copyright 2010 ZXing authors All rights reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -177,8 +175,8 @@ public: return object_; } - bool operator==(const int x) { - return x == 0 ? object_ == 0 : false; + bool operator==(const T* that) { + return object_ == that; } bool operator==(const Ref &other) const { return object_ == other.object_ || *object_ == *(other.object_); @@ -188,8 +186,8 @@ public: return object_ == other.object_ || *object_ == *(other.object_); } - bool operator!=(const int x) { - return x == 0 ? object_ != 0 : true; + bool operator!=(const T* that) { + return !(*this == that); } bool empty() const { diff --git a/cpp/core/src/zxing/common/ECI.cpp b/cpp/core/src/zxing/common/ECI.cpp index dc382dfb5..5f06c8576 100644 --- a/cpp/core/src/zxing/common/ECI.cpp +++ b/cpp/core/src/zxing/common/ECI.cpp @@ -16,6 +16,7 @@ */ #include +#include #include #include @@ -30,7 +31,9 @@ int ECI::getValue() const { ECI* ECI::getECIByValue(int value) { if (value < 0 || value > 999999) { - throw IllegalArgumentException("Bad ECI value: " + value); + std::ostringstream oss; + oss << "Bad ECI value: " << value; + throw IllegalArgumentException(oss.str().c_str()); } if (value < 900) { // Character set ECIs use 000000 - 000899 return CharacterSetECI::getCharacterSetECIByValue(value); diff --git a/cpp/core/src/zxing/oned/Code128Reader.cpp b/cpp/core/src/zxing/oned/Code128Reader.cpp index fa3fc7142..6fe91645d 100644 --- a/cpp/core/src/zxing/oned/Code128Reader.cpp +++ b/cpp/core/src/zxing/oned/Code128Reader.cpp @@ -1,7 +1,5 @@ +// -*- mode:c++; tab-width:2; indent-tabs-mode:nil; c-basic-offset:2 -*- /* - * Code128Reader.cpp - * ZXing - * * Copyright 2010 ZXing authors All rights reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -178,7 +176,7 @@ namespace zxing { } if (bestMatch >= 0) { // Look for whitespace before start pattern, >= 50% of width of start pattern - if (row->isRange(fmaxl(0, patternStart - (i - patternStart) / 2), patternStart, + if (row->isRange(std::max(0, patternStart - (i - patternStart) / 2), patternStart, false)) { int* resultValue = new int[3]; resultValue[0] = patternStart; @@ -430,7 +428,9 @@ namespace zxing { while (nextStart < width && row->get(nextStart)) { nextStart++; } - if (!row->isRange(nextStart, fminl(width, nextStart + (nextStart - lastStart) / 2), false)) { + if (!row->isRange(nextStart, + std::min(row->getSize(), nextStart + (nextStart - lastStart) / 2), + false)) { throw ReaderException(""); } diff --git a/cpp/core/src/zxing/oned/Code39Reader.cpp b/cpp/core/src/zxing/oned/Code39Reader.cpp index 9a2a82a10..dfde3a1c6 100644 --- a/cpp/core/src/zxing/oned/Code39Reader.cpp +++ b/cpp/core/src/zxing/oned/Code39Reader.cpp @@ -1,7 +1,5 @@ +// -*- mode:c++; tab-width:2; indent-tabs-mode:nil; c-basic-offset:2 -*- /* - * Code39Reader.cpp - * ZXing - * * Copyright 2010 ZXing authors All rights reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -209,9 +207,7 @@ namespace oned { if (toNarrowWidePattern(counters, countersLen) == ASTERISK_ENCODING) { // Look for whitespace before start pattern, >= 50% of width of // start pattern. - long double longPatternOffset = - fmaxl(0, patternStart - (i - patternStart) / 2); - if (row->isRange(longPatternOffset, patternStart, false)) { + if (row->isRange(std::max(0, patternStart - ((i - patternStart) >> 1)), patternStart, false)) { int* resultValue = new int[2]; resultValue[0] = patternStart; resultValue[1] = i;