From 49e0902d9f460f4f08db8aae1a6984f1d3f1ed63 Mon Sep 17 00:00:00 2001 From: Project Nayuki Date: Thu, 4 Oct 2018 19:56:07 +0000 Subject: [PATCH] Updated, added, synchronized section comments to show abstraction level in classes QrCode and QrSegment, in all languages except C. --- cpp/QrCode.hpp | 6 ++++-- cpp/QrSegment.hpp | 4 ++-- java/io/nayuki/qrcodegen/QrCode.java | 6 ++++-- java/io/nayuki/qrcodegen/QrSegment.java | 4 ++-- javascript/qrcodegen.js | 9 ++++++--- python/qrcodegen.py | 10 ++++++---- rust/src/lib.rs | 10 +++++++--- typescript/qrcodegen.ts | 10 ++++++---- 8 files changed, 37 insertions(+), 22 deletions(-) diff --git a/cpp/QrCode.hpp b/cpp/QrCode.hpp index d4115cf..3166edd 100644 --- a/cpp/QrCode.hpp +++ b/cpp/QrCode.hpp @@ -55,7 +55,7 @@ class QrCode final { - /*---- Public static factory functions ----*/ + /*---- Static factory functions (high level) ----*/ /* * Returns a QR Code symbol representing the given Unicode text string at the given error correction level. @@ -76,6 +76,8 @@ class QrCode final { public: static QrCode encodeBinary(const std::vector &data, Ecc ecl); + /*---- Static factory functions (mid level) ----*/ + /* * Returns a QR Code symbol representing the given segments with the given encoding parameters. * The smallest possible QR Code version within the given range is automatically chosen for the output. @@ -113,7 +115,7 @@ class QrCode final { - /*---- Constructor ----*/ + /*---- Constructor (low level) ----*/ /* * Creates a new QR Code symbol with the given version number, error correction level, binary data array, diff --git a/cpp/QrSegment.hpp b/cpp/QrSegment.hpp index 3cd0ec3..2bb0c3b 100644 --- a/cpp/QrSegment.hpp +++ b/cpp/QrSegment.hpp @@ -85,7 +85,7 @@ class QrSegment final { - /*---- Public static factory functions ----*/ + /*---- Static factory functions (mid level) ----*/ /* * Returns a segment representing the given binary data encoded in byte mode. @@ -148,7 +148,7 @@ class QrSegment final { private: std::vector data; - /*---- Constructors ----*/ + /*---- Constructors (low level) ----*/ /* * Creates a new QR Code segment with the given parameters and data. diff --git a/java/io/nayuki/qrcodegen/QrCode.java b/java/io/nayuki/qrcodegen/QrCode.java index c694f13..d8f601e 100644 --- a/java/io/nayuki/qrcodegen/QrCode.java +++ b/java/io/nayuki/qrcodegen/QrCode.java @@ -37,7 +37,7 @@ import java.util.Objects; */ public final class QrCode { - /*---- Public static factory functions ----*/ + /*---- Static factory functions (high level) ----*/ /** * Returns a QR Code symbol representing the specified Unicode text string at the specified error correction level. @@ -80,6 +80,8 @@ public final class QrCode { } + /*---- Static factory functions (mid level) ----*/ + /** * Returns a QR Code symbol representing the specified segments at the specified error correction * level. The smallest possible QR Code version is automatically chosen for the output. The ECC level @@ -192,7 +194,7 @@ public final class QrCode { - /*---- Constructor ----*/ + /*---- Constructor (low level) ----*/ /** * Constructs a QR Code symbol with the specified version number, error correction level, binary data array, and mask number. diff --git a/java/io/nayuki/qrcodegen/QrSegment.java b/java/io/nayuki/qrcodegen/QrSegment.java index 264c735..f997be5 100644 --- a/java/io/nayuki/qrcodegen/QrSegment.java +++ b/java/io/nayuki/qrcodegen/QrSegment.java @@ -39,7 +39,7 @@ import java.util.regex.Pattern; */ public final class QrSegment { - /*---- Static factory functions ----*/ + /*---- Static factory functions (mid level) ----*/ /** * Returns a segment representing the specified binary data encoded in byte mode. @@ -166,7 +166,7 @@ public final class QrSegment { final BitBuffer data; - /*---- Constructor ----*/ + /*---- Constructor (low level) ----*/ /** * Constructs a QR Code segment with the specified parameters and data. diff --git a/javascript/qrcodegen.js b/javascript/qrcodegen.js index a78bc1a..bb556e3 100644 --- a/javascript/qrcodegen.js +++ b/javascript/qrcodegen.js @@ -70,7 +70,7 @@ var qrcodegen = new function() { */ this.QrCode = function(datacodewords, mask, version, errCorLvl) { - /*---- Constructor ----*/ + /*---- Constructor (low level) ----*/ // Check arguments and handle simple scalar fields if (mask < -1 || mask > 7) @@ -510,7 +510,7 @@ var qrcodegen = new function() { }; - /*---- Public static factory functions for QrCode ----*/ + /*---- Static factory functions (high level) for QrCode ----*/ /* * Returns a QR Code symbol representing the given Unicode text string at the given error correction level. @@ -537,6 +537,8 @@ var qrcodegen = new function() { }; + /*---- Static factory functions (mid level) for QrCode ----*/ + /* * Returns a QR Code symbol representing the given segments with the given encoding parameters. * The smallest possible QR Code version within the given range is automatically chosen for the output. @@ -698,6 +700,7 @@ var qrcodegen = new function() { * Any segment longer than this is meaningless for the purpose of generating QR Codes. */ this.QrSegment = function(mode, numChars, bitData) { + /*---- Constructor (low level) ----*/ if (numChars < 0 || !(mode instanceof Mode)) throw "Invalid argument"; bitData = bitData.slice(); // Make defensive copy @@ -715,7 +718,7 @@ var qrcodegen = new function() { }; - /*---- Public static factory functions for QrSegment ----*/ + /*---- Static factory functions (mid level) for QrSegment ----*/ /* * Returns a segment representing the given binary data encoded in byte mode. diff --git a/python/qrcodegen.py b/python/qrcodegen.py index f0462f7..223e8d0 100644 --- a/python/qrcodegen.py +++ b/python/qrcodegen.py @@ -66,7 +66,7 @@ class QrCode(object): This class covers the QR Code Model 2 specification, supporting all versions (sizes) from 1 to 40, all 4 error correction levels, and 4 character encoding modes.""" - # ---- Public static factory functions ---- + # ---- Static factory functions (high level) ---- @staticmethod def encode_text(text, ecl): @@ -90,6 +90,8 @@ class QrCode(object): return QrCode.encode_segments([QrSegment.make_bytes(data)], ecl) + # ---- Static factory functions (mid level) ---- + @staticmethod def encode_segments(segs, ecl, minversion=1, maxversion=40, mask=-1, boostecl=True): """Returns a QR Code symbol representing the given segments with the given encoding parameters. @@ -142,7 +144,7 @@ class QrCode(object): return QrCode(bb.get_bytes(), mask, version, ecl) - # ---- Constructor ---- + # ---- Constructor (low level) ---- def __init__(self, datacodewords, mask, version, errcorlvl): """Creates a new QR Code symbol with the given version number, error correction level, binary data array, @@ -588,7 +590,7 @@ class QrSegment(object): Even in the most favorable conditions, a QR Code can only hold 7089 characters of data. Any segment longer than this is meaningless for the purpose of generating QR Codes.""" - # ---- Public static factory functions ---- + # ---- Static factory functions (mid level) ---- @staticmethod def make_bytes(data): @@ -673,7 +675,7 @@ class QrSegment(object): return QrSegment(QrSegment.Mode.ECI, 0, bb) - # ---- Constructor ---- + # ---- Constructor (low level) ---- def __init__(self, mode, numch, bitdata): """Creates a new QR Code segment with the given parameters and data.""" diff --git a/rust/src/lib.rs b/rust/src/lib.rs index a43958a..93de6c5 100644 --- a/rust/src/lib.rs +++ b/rust/src/lib.rs @@ -57,7 +57,7 @@ pub struct QrCode { impl QrCode { - /*---- Public static factory functions ----*/ + /*---- Static factory functions (high level) ----*/ // Returns a QR Code symbol representing the given Unicode text string at the given error correction level. // As a conservative upper bound, this function is guaranteed to succeed for strings that have 738 or fewer Unicode @@ -83,6 +83,8 @@ impl QrCode { } + /*---- Static factory functions (mid level) ----*/ + // Returns a QR Code symbol representing the given segments at the given error correction level. // The smallest possible QR Code version is automatically chosen for the output. The ECC level // of the result may be higher than the ecl argument if it can be done without increasing the version. @@ -167,7 +169,7 @@ impl QrCode { } - /*---- Constructor ----*/ + /*---- Constructor (low level) ----*/ // Creates a new QR Code symbol with the given version number, error correction level, // binary data array, and mask number. This is a cumbersome low-level constructor that @@ -841,7 +843,7 @@ pub struct QrSegment { impl QrSegment { - /*---- Static factory functions ----*/ + /*---- Static factory functions (mid level) ----*/ // Returns a segment representing the given binary data encoded in byte mode. pub fn make_bytes(data: &[u8]) -> Self { @@ -938,6 +940,8 @@ impl QrSegment { } + /*---- Constructor (low level) ----*/ + // Creates a new QR Code segment with the given parameters and data. pub fn new(mode: QrSegmentMode, numchars: usize, data: Vec) -> Self { Self { diff --git a/typescript/qrcodegen.ts b/typescript/qrcodegen.ts index 3c11da2..cb5d71d 100644 --- a/typescript/qrcodegen.ts +++ b/typescript/qrcodegen.ts @@ -44,7 +44,7 @@ namespace qrcodegen { */ export class QrCode { - /*-- Public static factory functions --*/ + /*-- Static factory functions (high level) --*/ // Returns a QR Code symbol representing the given Unicode text string at the given error correction level. // As a conservative upper bound, this function is guaranteed to succeed for strings that have 738 or fewer @@ -67,6 +67,8 @@ namespace qrcodegen { } + /*-- Static factory functions (mid level) --*/ + // Returns a QR Code symbol representing the given segments with the given encoding parameters. // The smallest possible QR Code version within the given range is automatically chosen for the output. // This function allows the user to create a custom sequence of segments that switches @@ -142,7 +144,7 @@ namespace qrcodegen { private readonly isFunction: Array> = []; - /*-- Constructor and fields --*/ + /*-- Constructor (low level) and fields --*/ public constructor( datacodewords: Array, @@ -654,7 +656,7 @@ namespace qrcodegen { */ export class QrSegment { - /*-- Static factory functions --*/ + /*-- Static factory functions (mid level) --*/ // Returns a segment representing the given binary data encoded in byte mode. public static makeBytes(data: Array): QrSegment { @@ -733,7 +735,7 @@ namespace qrcodegen { } - /*-- Constructor and fields --*/ + /*-- Constructor (low level) and fields --*/ // Creates a new QR Code segment with the given parameters and data. public constructor(