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
This commit is contained in:
smparkes@smparkes.net 2011-11-29 18:50:25 +00:00
parent 6de693fa06
commit 46cd54ab64
5 changed files with 20 additions and 20 deletions

View file

@ -16,6 +16,7 @@
*/ */
#include <zxing/common/CharacterSetECI.h> #include <zxing/common/CharacterSetECI.h>
#include <sstream>
#include <zxing/common/IllegalArgumentException.h> #include <zxing/common/IllegalArgumentException.h>
using std::string; using std::string;
@ -77,7 +78,9 @@ void CharacterSetECI::addCharacterSet(int value, char const* const* encodingName
CharacterSetECI* CharacterSetECI::getCharacterSetECIByValue(int value) { CharacterSetECI* CharacterSetECI::getCharacterSetECIByValue(int value) {
if (value < 0 || value >= 900) { 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]; return VALUE_TO_ECI[value];
} }

View file

@ -1,10 +1,8 @@
// -*- mode:c++; tab-width:2; indent-tabs-mode:nil; c-basic-offset:2 -*-
#ifndef __COUNTED_H__ #ifndef __COUNTED_H__
#define __COUNTED_H__ #define __COUNTED_H__
/* /*
* Counted.h
* zxing
*
* Copyright 2010 ZXing authors All rights reserved. * Copyright 2010 ZXing authors All rights reserved.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
@ -177,8 +175,8 @@ public:
return object_; return object_;
} }
bool operator==(const int x) { bool operator==(const T* that) {
return x == 0 ? object_ == 0 : false; return object_ == that;
} }
bool operator==(const Ref &other) const { bool operator==(const Ref &other) const {
return object_ == other.object_ || *object_ == *(other.object_); return object_ == other.object_ || *object_ == *(other.object_);
@ -188,8 +186,8 @@ public:
return object_ == other.object_ || *object_ == *(other.object_); return object_ == other.object_ || *object_ == *(other.object_);
} }
bool operator!=(const int x) { bool operator!=(const T* that) {
return x == 0 ? object_ != 0 : true; return !(*this == that);
} }
bool empty() const { bool empty() const {

View file

@ -16,6 +16,7 @@
*/ */
#include <zxing/common/ECI.h> #include <zxing/common/ECI.h>
#include <sstream>
#include <zxing/common/CharacterSetECI.h> #include <zxing/common/CharacterSetECI.h>
#include <zxing/common/IllegalArgumentException.h> #include <zxing/common/IllegalArgumentException.h>
@ -30,7 +31,9 @@ int ECI::getValue() const {
ECI* ECI::getECIByValue(int value) { ECI* ECI::getECIByValue(int value) {
if (value < 0 || value > 999999) { 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 if (value < 900) { // Character set ECIs use 000000 - 000899
return CharacterSetECI::getCharacterSetECIByValue(value); return CharacterSetECI::getCharacterSetECIByValue(value);

View file

@ -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. * Copyright 2010 ZXing authors All rights reserved.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
@ -178,7 +176,7 @@ namespace zxing {
} }
if (bestMatch >= 0) { if (bestMatch >= 0) {
// Look for whitespace before start pattern, >= 50% of width of start pattern // 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)) { false)) {
int* resultValue = new int[3]; int* resultValue = new int[3];
resultValue[0] = patternStart; resultValue[0] = patternStart;
@ -430,7 +428,9 @@ namespace zxing {
while (nextStart < width && row->get(nextStart)) { while (nextStart < width && row->get(nextStart)) {
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(""); throw ReaderException("");
} }

View file

@ -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. * Copyright 2010 ZXing authors All rights reserved.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
@ -209,9 +207,7 @@ namespace oned {
if (toNarrowWidePattern(counters, countersLen) == ASTERISK_ENCODING) { if (toNarrowWidePattern(counters, countersLen) == ASTERISK_ENCODING) {
// Look for whitespace before start pattern, >= 50% of width of // Look for whitespace before start pattern, >= 50% of width of
// start pattern. // start pattern.
long double longPatternOffset = if (row->isRange(std::max(0, patternStart - ((i - patternStart) >> 1)), patternStart, false)) {
fmaxl(0, patternStart - (i - patternStart) / 2);
if (row->isRange(longPatternOffset, patternStart, false)) {
int* resultValue = new int[2]; int* resultValue = new int[2];
resultValue[0] = patternStart; resultValue[0] = patternStart;
resultValue[1] = i; resultValue[1] = i;