Simplified some C++ code, updated comments.

pull/16/head
Project Nayuki 7 years ago
parent 8bbfa3938b
commit a26947e533

@ -120,21 +120,17 @@ QrCode QrCode::encodeSegments(const vector<QrSegment> &segs, Ecc ecl,
QrCode::QrCode(int ver, Ecc ecl, const vector<uint8_t> &dataCodewords, int mask) : QrCode::QrCode(int ver, Ecc ecl, const vector<uint8_t> &dataCodewords, int mask) :
// Initialize scalar fields // Initialize fields
version(ver), version(ver),
size(1 <= ver && ver <= 40 ? ver * 4 + 17 : -1), // Avoid signed overflow undefined behavior size(1 <= ver && ver <= 40 ? ver * 4 + 17 : -1), // Avoid signed overflow undefined behavior
errorCorrectionLevel(ecl) { errorCorrectionLevel(ecl),
modules(size, vector<bool>(size)), // Entirely white grid
isFunction(size, vector<bool>(size)) {
// Check arguments // Check arguments
if (ver < 1 || ver > 40 || mask < -1 || mask > 7) if (ver < 1 || ver > 40 || mask < -1 || mask > 7)
throw "Value out of range"; throw "Value out of range";
vector<bool> row(size);
for (int i = 0; i < size; i++) {
modules.push_back(row);
isFunction.push_back(row);
}
// Draw function patterns, draw all codewords, do masking // Draw function patterns, draw all codewords, do masking
drawFunctionPatterns(); drawFunctionPatterns();
const vector<uint8_t> allCodewords(appendErrorCorrection(dataCodewords)); const vector<uint8_t> allCodewords(appendErrorCorrection(dataCodewords));
@ -147,16 +143,15 @@ QrCode::QrCode(const QrCode &qr, int mask) :
// Copy scalar fields // Copy scalar fields
version(qr.version), version(qr.version),
size(qr.size), size(qr.size),
errorCorrectionLevel(qr.errorCorrectionLevel) { errorCorrectionLevel(qr.errorCorrectionLevel),
// Handle grid fields
modules(qr.modules),
isFunction(qr.isFunction) {
// Check arguments // Check arguments
if (mask < -1 || mask > 7) if (mask < -1 || mask > 7)
throw "Mask value out of range"; throw "Mask value out of range";
// Handle grid fields
modules = qr.modules;
isFunction = qr.isFunction;
// Handle masking // Handle masking
applyMask(qr.mask); // Undo old mask applyMask(qr.mask); // Undo old mask
this->mask = handleConstructorMasking(mask); this->mask = handleConstructorMasking(mask);

Loading…
Cancel
Save