From e0e905e3d1313ad31bbd8e04ee1100ed3723cec8 Mon Sep 17 00:00:00 2001 From: Project Nayuki Date: Wed, 6 Sep 2017 03:37:43 +0000 Subject: [PATCH] Changed C++ QrSegment::Ecc class to eliminate const from fields, updated related code. --- cpp/QrCode.cpp | 2 +- cpp/QrSegment.cpp | 5 +++++ cpp/QrSegment.hpp | 10 +++++++--- 3 files changed, 13 insertions(+), 4 deletions(-) diff --git a/cpp/QrCode.cpp b/cpp/QrCode.cpp index be47050..d98d2de 100644 --- a/cpp/QrCode.cpp +++ b/cpp/QrCode.cpp @@ -90,7 +90,7 @@ QrCode QrCode::encodeSegments(const vector &segs, const Ecc &ecl, size_t dataCapacityBits = getNumDataCodewords(version, *newEcl) * 8; BitBuffer bb; for (const QrSegment &seg : segs) { - bb.appendBits(seg.mode.modeBits, 4); + bb.appendBits(seg.mode.getModeBits(), 4); bb.appendBits(seg.numChars, seg.mode.numCharCountBits(version)); bb.insert(bb.end(), seg.data.begin(), seg.data.end()); } diff --git a/cpp/QrSegment.cpp b/cpp/QrSegment.cpp index 2579e05..539f396 100644 --- a/cpp/QrSegment.cpp +++ b/cpp/QrSegment.cpp @@ -40,6 +40,11 @@ QrSegment::Mode::Mode(int mode, int cc0, int cc1, int cc2) : } +int QrSegment::Mode::getModeBits() const { + return modeBits; +} + + int QrSegment::Mode::numCharCountBits(int ver) const { if ( 1 <= ver && ver <= 9) return numBitsCharCount[0]; else if (10 <= ver && ver <= 26) return numBitsCharCount[1]; diff --git a/cpp/QrSegment.hpp b/cpp/QrSegment.hpp index e485c15..2ce2fc2 100644 --- a/cpp/QrSegment.hpp +++ b/cpp/QrSegment.hpp @@ -58,8 +58,7 @@ class QrSegment final { /*-- Fields --*/ - /* (Package-private) An unsigned 4-bit integer value (range 0 to 15) representing the mode indicator bits for this mode object. */ - public: const int modeBits; + private: int modeBits; private: int numBitsCharCount[3]; @@ -69,7 +68,12 @@ class QrSegment final { private: Mode(int mode, int cc0, int cc1, int cc2); - /*-- Method --*/ + /*-- Methods --*/ + + /* + * (Package-private) Returns the mode indicator bits, which is an unsigned 4-bit value (range 0 to 15). + */ + public: int getModeBits() const; /* * (Package-private) Returns the bit width of the segment character count field for this mode object at the given version number.