c++ port of the relevant parts of r2581

git-svn-id: https://zxing.googlecode.com/svn/trunk@2624 59b500cc-1b3d-0410-9834-0bbf25fbcc57
This commit is contained in:
smparkes@smparkes.net 2013-04-06 20:07:24 +00:00
parent 44e85392eb
commit 7640573424
11 changed files with 52 additions and 59 deletions

View file

@ -21,21 +21,8 @@
#include <zxing/ChecksumException.h>
namespace zxing {
using zxing::ChecksumException;
ChecksumException::ChecksumException() {}
ChecksumException::ChecksumException(const char *msg) :
ReaderException(msg) {
}
ChecksumException::~ChecksumException() throw() {
}
ChecksumException const&
ChecksumException::getChecksumInstance() {
static ChecksumException instance;
return instance;
}
}
ChecksumException::ChecksumException() throw() {}
ChecksumException::ChecksumException(const char *msg) throw() : ReaderException(msg) {}
ChecksumException::~ChecksumException() throw() {}

View file

@ -25,10 +25,9 @@ namespace zxing {
class ChecksumException : public ReaderException {
typedef ReaderException Base;
public:
ChecksumException();
ChecksumException(const char *msg);
ChecksumException() throw();
ChecksumException(const char *msg) throw();
~ChecksumException() throw();
static ChecksumException const& getChecksumInstance();
};
}

View file

@ -24,17 +24,14 @@
#include <zxing/datamatrix/decoder/DecodedBitStreamParser.h>
#include <zxing/datamatrix/Version.h>
#include <zxing/ReaderException.h>
#include <zxing/ChecksumException.h>
#include <zxing/common/reedsolomon/ReedSolomonException.h>
namespace zxing {
namespace datamatrix {
using namespace std;
Decoder::Decoder() :
rsDecoder_(GenericGF::DATA_MATRIX_FIELD_256) {
}
using zxing::Ref;
using zxing::DecoderResult;
using zxing::datamatrix::Decoder;
Decoder::Decoder() : rsDecoder_(GenericGF::DATA_MATRIX_FIELD_256) {}
void Decoder::correctErrors(ArrayRef<char> codewordBytes, int numDataCodewords) {
int numCodewords = codewordBytes->size();
@ -45,9 +42,8 @@ void Decoder::correctErrors(ArrayRef<char> codewordBytes, int numDataCodewords)
int numECCodewords = numCodewords - numDataCodewords;
try {
rsDecoder_.decode(codewordInts, numECCodewords);
} catch (ReedSolomonException const& ex) {
ReaderException rex(ex.what());
throw rex;
} catch (ReedSolomonException const& ignored) {
throw ChecksumException();
}
// Copy back into array of bytes -- only need to worry about the bytes that were data
// We don't care about errors in the error-correction codewords
@ -90,5 +86,3 @@ Ref<DecoderResult> Decoder::decode(Ref<BitMatrix> bits) {
DecodedBitStreamParser decodedBSParser;
return Ref<DecoderResult> (decodedBSParser.decode(resultBytes));
}
}
}

View file

@ -44,7 +44,7 @@ void GenericMultipleBarcodeReader::doDecodeMultiple(Ref<BinaryBitmap> image,
Ref<Result> result;
try {
result = delegate_.decode(image, hints);
} catch (ReaderException const& re) {
} catch (ReaderException const& ignored) {
return;
}
bool alreadyFound = false;

View file

@ -279,6 +279,6 @@ void Code93Reader::checkOneChecksum(string const& result,
}
}
if (result[checkPosition] != ALPHABET[total % 47]) {
throw ChecksumException::getChecksumInstance();
throw ChecksumException();
}
}

View file

@ -65,7 +65,7 @@ Ref<Result> MultiFormatUPCEANReader::decodeRow(int rowNumber, Ref<BitArray> row)
Ref<Result> result;
try {
result = reader->decodeRow(rowNumber, row, startGuardPattern);
} catch (ReaderException const& re) {
} catch (ReaderException const& ignored) {
continue;
}

View file

@ -105,7 +105,7 @@ Ref<Result> OneDReader::doDecode(Ref<BinaryBitmap> image, DecodeHints hints) {
// Estimate black point for this row and load it:
try {
row = image->getBlackRow(rowNumber, row);
} catch (NotFoundException const& nfe) {
} catch (NotFoundException const& ignored) {
continue;
}

View file

@ -26,22 +26,23 @@
#include <zxing/DecodeHints.h>
namespace zxing {
namespace qrcode {
namespace qrcode {
class QRCodeReader : public Reader {
private:
Decoder decoder_;
class QRCodeReader : public Reader {
private:
Decoder decoder_;
protected:
Decoder& getDecoder();
protected:
Decoder& getDecoder();
public:
QRCodeReader();
virtual Ref<Result> decode(Ref<BinaryBitmap> image, DecodeHints hints);
virtual ~QRCodeReader();
public:
QRCodeReader();
virtual ~QRCodeReader();
};
}
Ref<Result> decode(Ref<BinaryBitmap> image, DecodeHints hints);
};
}
}
#endif // __QR_CODE_READER_H__

View file

@ -20,13 +20,16 @@
#include <zxing/qrcode/Version.h>
#include <zxing/qrcode/FormatInformation.h>
#include <zxing/FormatException.h>
#include <limits>
#include <iostream>
#include <cstdarg>
using std::vector;
using std::numeric_limits;
namespace zxing {
namespace qrcode {
using namespace std;
ECB::ECB(int count, int dataCodewords) :
count_(count), dataCodewords_(dataCodewords) {
@ -94,9 +97,13 @@ ECBlocks& Version::getECBlocksForLevel(ErrorCorrectionLevel &ecLevel) {
Version *Version::getProvisionalVersionForDimension(int dimension) {
if (dimension % 4 != 1) {
throw ReaderException("Dimension must be 1 mod 4");
throw FormatException();
}
try {
return Version::getVersionForNumber((dimension - 17) >> 2);
} catch (IllegalArgumentException const& ignored) {
throw FormatException();
}
return Version::getVersionForNumber((dimension - 17) >> 2);
}
Version *Version::getVersionForNumber(int versionNumber) {
@ -547,5 +554,6 @@ int Version::buildVersions() {
new ECB(61, 16)))));
return VERSIONS.size();
}
}
}

View file

@ -133,7 +133,7 @@ void DecodedBitStreamParser::decodeHanziSegment(Ref<BitSource> bits_,
try {
append(result, buffer, nBytes, StringUtils::GB2312);
} catch (ReaderException const& re) {
} catch (ReaderException const& ignored) {
delete [] buffer;
throw FormatException();
}
@ -164,8 +164,12 @@ void DecodedBitStreamParser::decodeKanjiSegment(Ref<BitSource> bits, std::string
offset += 2;
count--;
}
append(result, buffer, nBytes, StringUtils::SHIFT_JIS);
try {
append(result, buffer, nBytes, StringUtils::SHIFT_JIS);
} catch (ReaderException const& ignored) {
delete [] buffer;
throw FormatException();
}
delete[] buffer;
}
@ -200,7 +204,7 @@ void DecodedBitStreamParser::decodeByteSegment(Ref<BitSource> bits_,
}
try {
append(result, readBytes, nBytes, encoding.c_str());
} catch (ReaderException const& re) {
} catch (ReaderException const& ignored) {
throw FormatException();
}
byteSegments->values().push_back(bytes_);

View file

@ -26,6 +26,7 @@
#include <zxing/qrcode/decoder/DataBlock.h>
#include <zxing/qrcode/decoder/DecodedBitStreamParser.h>
#include <zxing/ReaderException.h>
#include <zxing/ChecksumException.h>
#include <zxing/common/reedsolomon/ReedSolomonException.h>
using zxing::qrcode::Decoder;
@ -46,9 +47,8 @@ void Decoder::correctErrors(ArrayRef<char> codewordBytes, int numDataCodewords)
try {
rsDecoder_.decode(codewordInts, numECCodewords);
} catch (ReedSolomonException const& ex) {
ReaderException rex(ex.what());
throw rex;
} catch (ReedSolomonException const& ignored) {
throw ChecksumException();
}
for (int i = 0; i < numDataCodewords; i++) {