From 70a181753af0b97f2d8dbc49959647abc00b6b9b Mon Sep 17 00:00:00 2001 From: Project Nayuki Date: Wed, 6 Sep 2017 03:56:06 +0000 Subject: [PATCH] Changed C++ QrSegment class to eliminate const from fields, updated related code. --- cpp/QrCode.cpp | 6 +++--- cpp/QrSegment.cpp | 15 +++++++++++++++ cpp/QrSegment.hpp | 17 ++++++++++++++--- 3 files changed, 32 insertions(+), 6 deletions(-) diff --git a/cpp/QrCode.cpp b/cpp/QrCode.cpp index 5fda688..34b1dfc 100644 --- a/cpp/QrCode.cpp +++ b/cpp/QrCode.cpp @@ -100,9 +100,9 @@ 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.getModeBits(), 4); - bb.appendBits(seg.numChars, seg.mode.numCharCountBits(version)); - bb.insert(bb.end(), seg.data.begin(), seg.data.end()); + bb.appendBits(seg.getMode().getModeBits(), 4); + bb.appendBits(seg.getNumChars(), seg.getMode().numCharCountBits(version)); + bb.insert(bb.end(), seg.getData().begin(), seg.getData().end()); } // Add terminator and pad up to a byte if applicable diff --git a/cpp/QrSegment.cpp b/cpp/QrSegment.cpp index 539f396..202e6c9 100644 --- a/cpp/QrSegment.cpp +++ b/cpp/QrSegment.cpp @@ -208,6 +208,21 @@ bool QrSegment::isNumeric(const char *text) { } +QrSegment::Mode QrSegment::getMode() const { + return mode; +} + + +int QrSegment::getNumChars() const { + return numChars; +} + + +const std::vector &QrSegment::getData() const { + return data; +} + + const char *QrSegment::ALPHANUMERIC_CHARSET = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ $%*+-./:"; } diff --git a/cpp/QrSegment.hpp b/cpp/QrSegment.hpp index 2ce2fc2..a19c53f 100644 --- a/cpp/QrSegment.hpp +++ b/cpp/QrSegment.hpp @@ -138,13 +138,13 @@ class QrSegment final { /*---- Instance fields ----*/ /* The mode indicator for this segment. */ - public: const Mode mode; + private: Mode mode; /* The length of this segment's unencoded data, measured in characters. Always zero or positive. */ - public: const int numChars; + private: int numChars; /* The data bits of this segment. */ - public: const std::vector data; + private: std::vector data; /*---- Constructor ----*/ @@ -161,6 +161,17 @@ class QrSegment final { public: QrSegment(const Mode &md, int numCh, std::vector &&dt); + /*---- Methods ----*/ + + public: Mode getMode() const; + + + public: int getNumChars() const; + + + public: const std::vector &getData() const; + + // Package-private helper function. public: static int getTotalBits(const std::vector &segs, int version);