zxing-cpp v3.0
Loading...
Searching...
No Matches
BarcodeFormat.h
Go to the documentation of this file.
1/*
2 * Copyright 2026 Axel Waggershauser
3 */
4// SPDX-License-Identifier: Apache-2.0
5
6#pragma once
7
8#include "Version.h"
9
10#include <stdint.h>
11
12// FLAGS[0]: l == linear, m == matrix
13// FLAGS[1]: r == readable
14// FLAGS[2]: w == writable (MultiformatWriter))
15// FLAGS[3]: G == GS1
16// FLAGS[4]: R == Retail, I == Industrial, O == Other
17
18// clang-format off
19// NAME, SYM, VAR, FLAGS, ZINT, ENABLED, HRI
20#define ZX_BCF_LIST(X) \
21 X(None, 0 , 0, " ", 0, 1, "None") \
22 X(All, '*', '*', " ", 0, 1, "All") \
23 X(AllReadable, '*', 'r', " ", 0, 1, "All Readable") \
24 X(AllCreatable, '*', 'w', " ", 0, 1, "All Creatable") \
25 X(AllLinear, '*', 'l', " ", 0, 1, "All Linear") \
26 X(AllMatrix, '*', 'm', " ", 0, 1, "All Matrix") \
27 X(AllGS1, '*', 'G', " ", 0, 1, "All GS1") \
28 X(AllRetail, '*', 'R', " ", 0, 1, "All Retail") \
29 X(AllIndustrial, '*', 'I', " ", 0, 1, "All Industrial") \
30 X(Codabar, 'F', ' ', "lrw ", 18, ZXING_ENABLE_1D, "Codabar") \
31 X(Code39, 'A', ' ', "lrw I", 8, ZXING_ENABLE_1D, "Code 39") \
32 X(Code39Std, 'A', 's', "lrw I", 8, ZXING_ENABLE_1D, "Code 39 Standard") \
33 X(Code39Ext, 'A', 'e', "lr I", 9, ZXING_ENABLE_1D, "Code 39 Extended") \
34 X(Code32, 'A', '2', "lr I", 129, ZXING_ENABLE_1D, "Code 32") \
35 X(PZN, 'A', 'p', "lr I", 52, ZXING_ENABLE_1D, "Pharmazentralnummer") \
36 X(Code93, 'G', ' ', "lrw I", 25, ZXING_ENABLE_1D, "Code 93") \
37 X(Code128, 'C', ' ', "lrwGI", 20, ZXING_ENABLE_1D, "Code 128") \
38 X(ITF, 'I', ' ', "lrw I", 3, ZXING_ENABLE_1D, "ITF") \
39 X(ITF14, 'I', '4', "lr I", 89, ZXING_ENABLE_1D, "ITF-14") \
40 X(DataBar, 'e', ' ', "lr GR", 29, ZXING_ENABLE_1D, "DataBar") \
41 X(DataBarOmni, 'e', 'o', "lr GR", 29, ZXING_ENABLE_1D, "DataBar Omni") \
42 X(DataBarStk, 'e', 's', "lr GR", 79, ZXING_ENABLE_1D, "DataBar Stacked") \
43 X(DataBarStkOmni, 'e', 'O', "lr GR", 80, ZXING_ENABLE_1D, "DataBar Stacked Omni") \
44 X(DataBarLtd, 'e', 'l', "lr GR", 30, ZXING_ENABLE_1D, "DataBar Limited") \
45 X(DataBarExp, 'e', 'e', "lr GR", 31, ZXING_ENABLE_1D, "DataBar Expanded") \
46 X(DataBarExpStk, 'e', 'E', "lr GR", 81, ZXING_ENABLE_1D, "DataBar Expanded Stacked") \
47 X(EANUPC, 'E', ' ', "lr R", 15, ZXING_ENABLE_1D, "EAN/UPC") \
48 X(EAN13, 'E', '1', "lrw R", 15, ZXING_ENABLE_1D, "EAN-13") \
49 X(EAN8, 'E', '8', "lrw R", 10, ZXING_ENABLE_1D, "EAN-8") \
50 X(EAN5, 'E', '5', "l R", 12, ZXING_ENABLE_1D, "EAN-5") \
51 X(EAN2, 'E', '2', "l R", 11, ZXING_ENABLE_1D, "EAN-2") \
52 X(ISBN, 'E', 'i', "lr R", 69, ZXING_ENABLE_1D, "ISBN") \
53 X(UPCA, 'E', 'a', "lrw R", 34, ZXING_ENABLE_1D, "UPC-A") \
54 X(UPCE, 'E', 'e', "lrw R", 37, ZXING_ENABLE_1D, "UPC-E") \
55 X(OtherBarcode, 'X', ' ', " r ", 0, ZXING_ENABLE_1D, "Other barcode") /* see ISO/IEC 15424:2025 */ \
56 X(DXFilmEdge, 'X', 'x', "lr ", 147, ZXING_ENABLE_1D, "DX Film Edge") \
57 X(PDF417, 'L', ' ', "mrw ", 55, ZXING_ENABLE_PDF417, "PDF417") \
58 X(CompactPDF417, 'L', 'c', "mr ", 56, ZXING_ENABLE_PDF417, "Compact PDF417") \
59 X(MicroPDF417, 'L', 'm', "m ", 84, ZXING_ENABLE_PDF417, "MicroPDF417") \
60 X(Aztec, 'z', ' ', "mr G ", 92, ZXING_ENABLE_AZTEC, "Aztec") \
61 X(AztecCode, 'z', 'c', "mrwG ", 92, ZXING_ENABLE_AZTEC, "Aztec Code") \
62 X(AztecRune, 'z', 'r', "mr ", 128, ZXING_ENABLE_AZTEC, "Aztec Rune") \
63 X(QRCode, 'Q', ' ', "mrwG ", 58, ZXING_ENABLE_QRCODE, "QR Code") \
64 X(QRCodeModel1, 'Q', '1', "mr ", 0, ZXING_ENABLE_QRCODE, "QR Code Model 1") \
65 X(QRCodeModel2, 'Q', '2', "mr ", 58, ZXING_ENABLE_QRCODE, "QR Code Model 2") \
66 X(MicroQRCode, 'Q', 'm', "mr ", 97, ZXING_ENABLE_QRCODE, "Micro QR Code") \
67 X(RMQRCode, 'Q', 'r', "mr G ", 145, ZXING_ENABLE_QRCODE, "rMQR Code") \
68 X(DataMatrix, 'd', ' ', "mrwG ", 71, ZXING_ENABLE_DATAMATRIX, "Data Matrix") \
69 X(MaxiCode, 'U', ' ', "mr ", 57, ZXING_ENABLE_MAXICODE, "MaxiCode") \
70 /* Add new formats here */
71// clang-format on
72
73#define ZX_BCF_ID(SYM, VAR) (((uint8_t)(SYM) << 0) | ((uint8_t)(VAR) << 8))
74
75#ifdef __cplusplus
76
77#include <array>
78#include <algorithm>
79#include <string>
80#include <string_view>
81#include <utility>
82#include <vector>
83
84namespace ZXing {
85
97enum class BarcodeFormat : unsigned int
98{
99#define ZX_(NAME, SYM, VAR, FLAGS, ZINT, ENABLED, HRI) NAME = ZX_BCF_ID(SYM, VAR),
100 ZX_BCF_LIST(ZX_)
101#undef ZX_
103 DataBarExpanded [[deprecated("Use DataBarExp instead")]] = DataBarExp,
104 DataBarLimited [[deprecated("Use DataBarLtd instead")]] = DataBarLtd,
105 LinearCodes [[deprecated("Use AllLinear instead")]] = AllLinear,
106 MatrixCodes [[deprecated("Use AllMatrix instead")]] = AllMatrix,
107 Any [[deprecated("Use All instead")]] = All,
109};
110
112inline char SymbologyKey(const BarcodeFormat& format)
113{
114 return uint32_t(format) & 0xFF;
115}
116
117inline char VariantKey(const BarcodeFormat& format)
118{
119 return (uint32_t(format) >> 8) & 0xFF;
120}
121
122inline std::string IdStr(const BarcodeFormat& format)
123{
124 return {']', SymbologyKey(format), VariantKey(format)};
125}
127
130
132std::string_view Name(BarcodeFormat format);
133
136
139
140template <std::size_t N>
141using BarcodeFormatArray = std::array<BarcodeFormat, N>;
142
144{
145 return {a, b};
146}
147
148template <std::size_t N>
150{
152 for (std::size_t i = 0; i < N; ++i)
153 ret[i] = bts[i];
154 ret[N] = bt;
155 return ret;
156}
157
158template <std::size_t N>
159constexpr bool operator&(BarcodeFormat lhs, const BarcodeFormatArray<N>& rhs)
160{
161 return std::any_of(rhs.begin(), rhs.end(), [lhs](BarcodeFormat bt) { return lhs & bt; });
162}
163
167
168std::string ToString(BarcodeFormat format);
169
182{
183 std::vector<BarcodeFormat> formats_;
184
185 void normalize();
186
187public:
188 BarcodeFormats() = default;
189 BarcodeFormats(BarcodeFormat f) : formats_{f} {}
190
195 template <std::size_t N>
196 BarcodeFormats(BarcodeFormatArray<N> formats) : formats_{formats.begin(), formats.end()}
197 {
198 normalize();
199 }
200
201 BarcodeFormats(std::vector<BarcodeFormat>&& formats) : formats_(std::move(formats)) { normalize(); }
202
204 explicit BarcodeFormats(std::string_view str);
205
210 bool operator==(const BarcodeFormats& o) const noexcept { return formats_ == o.formats_; }
211 bool operator!=(const BarcodeFormats& o) const noexcept { return !(*this == o); }
212 // ~BarcodeFormats() = default;
213
214 auto begin() const noexcept { return formats_.cbegin(); }
215 auto end() const noexcept { return formats_.cend(); }
216
217 using value_type = typename std::vector<BarcodeFormat>::value_type;
218 using pointer = typename std::vector<BarcodeFormat>::pointer;
219 auto data() const noexcept { return formats_.data(); }
220
221 bool empty() const noexcept { return formats_.empty(); }
222 int size() const noexcept { return static_cast<int>(formats_.size()); }
223
224 // BarcodeFormats&& operator|(BarcodeFormat bt) &&;
225 // BarcodeFormats&& operator|(const BarcodeFormats& other) &&;
226
229
232 static BarcodeFormats list(const BarcodeFormats& filter = {});
233
235 [[deprecated]] inline int count() const noexcept { return size(); }
236 [[deprecated]] inline bool testFlag(BarcodeFormat format) const noexcept
237 {
238 return std::any_of(begin(), end(), [format](BarcodeFormat f) { return f & format; });
239 }
240 [[deprecated]] inline bool testFlags(const BarcodeFormats& formats) const noexcept
241 {
242 return std::any_of(begin(), end(), [formats](BarcodeFormat fo) {
243 return std::any_of(formats.begin(), formats.end(), [fo](BarcodeFormat fi) { return fo & fi; });
244 });
245 }
247};
248
249inline bool operator<=(BarcodeFormat lhs, const BarcodeFormats& rhs)
250{
251 return std::any_of(rhs.begin(), rhs.end(), [lhs](BarcodeFormat bf) { return lhs <= bf; });
252}
253
254inline bool operator&(BarcodeFormat lhs, const BarcodeFormats& rhs)
255{
256 return std::any_of(rhs.begin(), rhs.end(), [lhs](BarcodeFormat bf) { return lhs & bf; });
257}
258
264
265std::string ToString(const BarcodeFormats& formats);
266
267} // namespace ZXing
268
269#endif // __cplusplus
A small container representing a collection of BarcodeFormat values.
Definition BarcodeFormat.h:182
typename std::vector< BarcodeFormat >::value_type value_type
Definition BarcodeFormat.h:217
bool operator==(const BarcodeFormats &o) const noexcept
Definition BarcodeFormat.h:210
bool operator!=(const BarcodeFormats &o) const noexcept
Definition BarcodeFormat.h:211
BarcodeFormats & operator=(BarcodeFormats &&)=default
auto begin() const noexcept
Definition BarcodeFormat.h:214
static BarcodeFormats list(const BarcodeFormats &filter={})
BarcodeFormats(BarcodeFormat f)
Definition BarcodeFormat.h:189
BarcodeFormats(BarcodeFormatArray< N > formats)
Constructs a collection from a compile-time array of BarcodeFormat values.
Definition BarcodeFormat.h:196
BarcodeFormats(const BarcodeFormats &)=default
BarcodeFormats & operator=(const BarcodeFormats &)=default
BarcodeFormats operator&(const BarcodeFormats &other)
Returns a BarcodeFormats containing the intersection of this collection and other.
BarcodeFormats(std::vector< BarcodeFormat > &&formats)
Definition BarcodeFormat.h:201
auto end() const noexcept
Definition BarcodeFormat.h:215
BarcodeFormats(BarcodeFormats &&)=default
bool empty() const noexcept
Definition BarcodeFormat.h:221
typename std::vector< BarcodeFormat >::pointer pointer
Definition BarcodeFormat.h:218
BarcodeFormats(std::string_view str)
Constructs a collection from a textual representation (e.g. a comma-separated list of format identifi...
auto data() const noexcept
Definition BarcodeFormat.h:219
int size() const noexcept
Definition BarcodeFormat.h:222
Definition Barcode.h:26
bool operator<=(BarcodeFormat e, BarcodeFormat s)
Test if left hand side (e == element) is 'inside' right hand side (s == set) (e.g....
BarcodeFormat BarcodeFormatFromString(std::string_view str)
Parse a string into a BarcodeFormat. '-', '_', '/' and ' ' are optional.
BarcodeFormats BarcodeFormatsFromString(std::string_view str)
Parses a string into a set of BarcodeFormats. Separators can be (any combination of) '|' or ',...
constexpr BarcodeFormatArray< 2 > operator|(BarcodeFormat a, BarcodeFormat b)
Definition BarcodeFormat.h:143
BarcodeFormat Symbology(BarcodeFormat format)
Returns the symbology (base type) of the given barcode format (e.g. EAN/UPC for EAN13,...
std::string ToString(BarcodeFormat format)
std::string_view Name(BarcodeFormat format)
Returns the human-readable name of the given barcode format.
BarcodeFormat
Enumerates barcode formats known to this package.
Definition BarcodeFormat.h:98
@ AllLinear
Definition BarcodeFormat.h:100
@ AllMatrix
Definition BarcodeFormat.h:100
@ DataBarLtd
Definition BarcodeFormat.h:100
@ All
Definition BarcodeFormat.h:100
@ DataBarExp
Definition BarcodeFormat.h:100
std::array< BarcodeFormat, N > BarcodeFormatArray
Definition BarcodeFormat.h:141
bool operator&(BarcodeFormat a, BarcodeFormat b)
Test if the two BarcodeFormats have a non-empty intersection (e.g. AllMatrix & QRCode).