NDEVR
API Documentation
QrSegmentfinal

A segment of character, binary, or control data in a QR Code symbol. More...

Classes

class  Mode
 Describes how a segment's data bits are interpreted. More...

Public Member Functions

 QrSegment (const Mode &md, int numCh, Buffer< bool > &&dt)
 Creates a new QR Code segment with the given attributes and data (move).
 QrSegment (const Mode &md, int numCh, const Buffer< bool > &dt)
 Creates a new QR Code segment with the given attributes and data (copy).
const Buffer< bool > & getData () const
 Returns the data bits of this segment.
const ModegetMode () const
 Returns the mode field of this segment.
int getNumChars () const
 Returns the character count field of this segment.

Static Public Member Functions

static int getTotalBits (const QrSegmentBuffer &segs, int version)
 Calculates the total number of bits needed to encode the given segments at the given version.
static bool isAlphanumeric (const char *text)
 Tests whether the given string can be encoded as a segment in alphanumeric mode.
static bool isNumeric (const char *text)
 Tests whether the given string can be encoded as a segment in numeric mode.
static QrSegment makeAlphanumeric (const char *text)
 Returns a segment representing the given text string encoded in alphanumeric mode.
static QrSegment makeBytes (const uint01 *data, uint04 size)
 Returns a segment representing the given binary data encoded in byte mode.
static QrSegment makeEci (long assignVal)
 Returns a segment representing an Extended Channel Interpretation (ECI) designator with the given assignment value.
static QrSegment makeNumeric (const char *digits)
 Returns a segment representing the given string of decimal digits encoded in numeric mode.
static QrSegmentBuffer makeSegments (const char *text)
 Returns a list of zero or more segments to represent the given text string.

Detailed Description

A segment of character, binary, or control data in a QR Code symbol.

Instances of this class are immutable. The mid-level way to create a segment is to take the payload data and call a static factory function such as QrSegment::makeNumeric(). The low-level way to create a segment is to custom-make the bit buffer and call the QrSegment() constructor with appropriate values. This segment class imposes no length restrictions, but QR Codes have restrictions. 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.

Definition at line 48 of file QRCode.h.

Constructor & Destructor Documentation

◆ QrSegment() [1/2]

QrSegment::QrSegment ( const Mode & md,
int numCh,
const Buffer< bool > & dt )

Creates a new QR Code segment with the given attributes and data (copy).

The character count (numCh) must agree with the mode and the bit buffer length, but the constraint is not checked. The given bit buffer is copied and stored.

Parameters
[in]mdThe encoding mode for this segment.
[in]numChThe number of characters in the original data.
[in]dtThe bit buffer containing the encoded data (copied).

Referenced by makeAlphanumeric(), makeBytes(), makeEci(), and makeNumeric().

◆ QrSegment() [2/2]

QrSegment::QrSegment ( const Mode & md,
int numCh,
Buffer< bool > && dt )

Creates a new QR Code segment with the given attributes and data (move).

The character count (numCh) must agree with the mode and the bit buffer length, but the constraint is not checked. The given bit buffer is moved and stored.

Parameters
[in]mdThe encoding mode for this segment.
[in]numChThe number of characters in the original data.
[in]dtThe bit buffer containing the encoded data (moved).

Member Function Documentation

◆ getData()

const Buffer< bool > & QrSegment::getData ( ) const

Returns the data bits of this segment.

Returns
A const reference to the bit buffer.

◆ getMode()

const Mode & QrSegment::getMode ( ) const

Returns the mode field of this segment.

Returns
A reference to the Mode of this segment.

◆ getNumChars()

int QrSegment::getNumChars ( ) const

Returns the character count field of this segment.

Returns
The number of characters in this segment's unencoded data.

◆ getTotalBits()

int QrSegment::getTotalBits ( const QrSegmentBuffer & segs,
int version )
static

Calculates the total number of bits needed to encode the given segments at the given version.

Returns a non-negative number if successful. Otherwise returns -1 if a segment has too many characters to fit its length field, or the total bits exceeds INT_MAX.

Parameters
[in]segsThe buffer of segments to measure.
[in]versionThe QR Code version number (1 to 40).
Returns
The total number of bits, or -1 on failure.

◆ isAlphanumeric()

bool QrSegment::isAlphanumeric ( const char * text)
static

Tests whether the given string can be encoded as a segment in alphanumeric mode.

A string is encodable if and only if each character is in the following set: 0 to 9, A to Z (uppercase only), space, dollar, percent, asterisk, plus, hyphen, period, slash, colon.

Parameters
[in]textA null-terminated string to test.
Returns
True if the string is encodable in alphanumeric mode, false otherwise.

◆ isNumeric()

bool QrSegment::isNumeric ( const char * text)
static

Tests whether the given string can be encoded as a segment in numeric mode.

A string is encodable if and only if each character is in the range '0' to '9'.

Parameters
[in]textA null-terminated string to test.
Returns
True if the string is encodable in numeric mode, false otherwise.

◆ makeAlphanumeric()

QrSegment QrSegment::makeAlphanumeric ( const char * text)
static

Returns a segment representing the given text string encoded in alphanumeric mode.

The characters allowed are: 0 to 9, A to Z (uppercase only), space, dollar, percent, asterisk, plus, hyphen, period, slash, colon.

Parameters
[in]textA null-terminated string of alphanumeric characters.
Returns
A QrSegment encoding the given alphanumeric text.

References QrSegment().

◆ makeBytes()

QrSegment QrSegment::makeBytes ( const uint01 * data,
uint04 size )
static

Returns a segment representing the given binary data encoded in byte mode.

All input byte arrays are acceptable. Any text string can be converted to UTF-8 bytes and encoded as a byte mode segment.

Parameters
[in]dataPointer to the raw byte data to encode.
[in]sizeThe number of bytes in the data array.
Returns
A QrSegment encoding the given binary data.

References QrSegment().

◆ makeEci()

QrSegment QrSegment::makeEci ( long assignVal)
static

Returns a segment representing an Extended Channel Interpretation (ECI) designator with the given assignment value.

Parameters
[in]assignValThe ECI assignment value.
Returns
A QrSegment encoding the ECI designator.

References QrSegment().

◆ makeNumeric()

QrSegment QrSegment::makeNumeric ( const char * digits)
static

Returns a segment representing the given string of decimal digits encoded in numeric mode.

Parameters
[in]digitsA null-terminated string of characters in the range '0' to '9'.
Returns
A QrSegment encoding the given numeric string.

References QrSegment().

◆ makeSegments()

QrSegmentBuffer QrSegment::makeSegments ( const char * text)
static

Returns a list of zero or more segments to represent the given text string.

The result may use various segment modes and switch modes to optimize the length of the bit stream.

Parameters
[in]textA null-terminated string to encode.
Returns
A buffer of QrSegment objects representing the text.

The documentation for this class was generated from the following file: