zxing-cpp v3.2
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(Telepen, 'B', ' ', "lr I", 32, ZXING_ENABLE_1D, "Telepen") \
56 X(TelepenAlpha, 'B', '0', "lr I", 32, ZXING_ENABLE_1D, "Telepen Alpha") \
57 X(TelepenNumeric, 'B', '1', "lr I", 87, ZXING_ENABLE_1D, "Telepen Numeric") \
58 X(OtherBarcode, 'X', ' ', " r ", 0, ZXING_ENABLE_1D, "Other barcode") /* see ISO/IEC 15424:2025 */ \
59 X(DXFilmEdge, 'X', 'x', "lr ", 147, ZXING_ENABLE_1D, "DX Film Edge") \
60 X(PDF417, 'L', ' ', "mrw ", 55, ZXING_ENABLE_PDF417, "PDF417") \
61 X(CompactPDF417, 'L', 'c', "mr ", 56, ZXING_ENABLE_PDF417, "Compact PDF417") \
62 X(MicroPDF417, 'L', 'm', "mr ", 84, ZXING_ENABLE_PDF417, "MicroPDF417") \
63 X(Aztec, 'z', ' ', "mrwG ", 92, ZXING_ENABLE_AZTEC, "Aztec") \
64 X(AztecCode, 'z', 'c', "mrwG ", 92, ZXING_ENABLE_AZTEC, "Aztec Code") \
65 X(AztecRune, 'z', 'r', "mr ", 128, ZXING_ENABLE_AZTEC, "Aztec Rune") \
66 X(QRCode, 'Q', ' ', "mrwG ", 58, ZXING_ENABLE_QRCODE, "QR Code") \
67 X(QRCodeModel1, 'Q', '1', "mr ", 0, ZXING_ENABLE_QRCODE, "QR Code Model 1") \
68 X(QRCodeModel2, 'Q', '2', "mrw ", 58, ZXING_ENABLE_QRCODE, "QR Code Model 2") \
69 X(MicroQRCode, 'Q', 'm', "mr ", 97, ZXING_ENABLE_QRCODE, "Micro QR Code") \
70 X(RMQRCode, 'Q', 'r', "mr G ", 145, ZXING_ENABLE_QRCODE, "rMQR Code") \
71 X(DataMatrix, 'd', ' ', "mrwG ", 71, ZXING_ENABLE_DATAMATRIX, "Data Matrix") \
72 X(MaxiCode, 'U', ' ', "mr ", 57, ZXING_ENABLE_MAXICODE, "MaxiCode") \
73 /* Add new formats here */
74// clang-format on
75
76#define ZX_BCF_ID(SYM, VAR) (((uint8_t)(SYM) << 0) | ((uint8_t)(VAR) << 8))
77
78#ifdef __cplusplus
79
80#include <array>
81#include <algorithm>
82#include <string>
83#include <string_view>
84#include <utility>
85#include <vector>
86
87namespace ZXing {
88
100enum class BarcodeFormat : unsigned int
101{
102#define ZX_(NAME, SYM, VAR, FLAGS, ZINT, ENABLED, HRI) NAME = ZX_BCF_ID(SYM, VAR),
103 ZX_BCF_LIST(ZX_)
104#undef ZX_
106 DataBarExpanded [[deprecated("Use DataBarExp instead")]] = DataBarExp,
107 DataBarLimited [[deprecated("Use DataBarLtd instead")]] = DataBarLtd,
108 LinearCodes [[deprecated("Use AllLinear instead")]] = AllLinear,
109 MatrixCodes [[deprecated("Use AllMatrix instead")]] = AllMatrix,
110 Any [[deprecated("Use All instead")]] = All,
112};
113
115inline char SymbologyKey(const BarcodeFormat& format)
116{
117 return uint32_t(format) & 0xFF;
118}
119
120inline char VariantKey(const BarcodeFormat& format)
121{
122 return (uint32_t(format) >> 8) & 0xFF;
123}
124
125inline std::string IdStr(const BarcodeFormat& format)
126{
127 return {']', SymbologyKey(format), VariantKey(format)};
128}
130
133
135std::string_view Name(BarcodeFormat format);
136
138std::string_view EnumName(BarcodeFormat format);
139
142
145
146template <std::size_t N>
147using BarcodeFormatArray = std::array<BarcodeFormat, N>;
148
150{
151 return {a, b};
152}
153
154template <std::size_t N>
156{
158 for (std::size_t i = 0; i < N; ++i)
159 ret[i] = bts[i];
160 ret[N] = bt;
161 return ret;
162}
163
164template <std::size_t N>
165constexpr bool operator&(BarcodeFormat lhs, const BarcodeFormatArray<N>& rhs)
166{
167 return std::any_of(rhs.begin(), rhs.end(), [lhs](BarcodeFormat bt) { return lhs & bt; });
168}
169
173
174std::string ToString(BarcodeFormat format);
175
188{
189 std::vector<BarcodeFormat> formats_;
190
191 void normalize();
192
193public:
194 BarcodeFormats() = default;
195 BarcodeFormats(BarcodeFormat f) : formats_{f} {}
196
201 template <std::size_t N>
202 BarcodeFormats(BarcodeFormatArray<N> formats) : formats_{formats.begin(), formats.end()}
203 {
204 normalize();
205 }
206
207 BarcodeFormats(std::vector<BarcodeFormat>&& formats) : formats_(std::move(formats)) { normalize(); }
208
210 explicit BarcodeFormats(std::string_view str);
211
216 bool operator==(const BarcodeFormats& o) const noexcept { return formats_ == o.formats_; }
217 bool operator!=(const BarcodeFormats& o) const noexcept { return !(*this == o); }
218 // ~BarcodeFormats() = default;
219
220 auto begin() const noexcept { return formats_.cbegin(); }
221 auto end() const noexcept { return formats_.cend(); }
222
223 using value_type = typename std::vector<BarcodeFormat>::value_type;
224 using pointer = typename std::vector<BarcodeFormat>::pointer;
225 auto data() const noexcept { return formats_.data(); }
226
227 bool empty() const noexcept { return formats_.empty(); }
228 int size() const noexcept { return static_cast<int>(formats_.size()); }
229
230 // BarcodeFormats&& operator|(BarcodeFormat bt) &&;
231 // BarcodeFormats&& operator|(const BarcodeFormats& other) &&;
232
235
238 static BarcodeFormats list(const BarcodeFormats& filter = {});
239
241 [[deprecated]] inline int count() const noexcept { return size(); }
242 [[deprecated]] inline bool testFlag(BarcodeFormat format) const noexcept
243 {
244 return std::any_of(begin(), end(), [format](BarcodeFormat f) { return f & format; });
245 }
246 [[deprecated]] inline bool testFlags(const BarcodeFormats& formats) const noexcept
247 {
248 return std::any_of(begin(), end(), [formats](BarcodeFormat fo) {
249 return std::any_of(formats.begin(), formats.end(), [fo](BarcodeFormat fi) { return fo & fi; });
250 });
251 }
253};
254
255inline bool operator<=(BarcodeFormat lhs, const BarcodeFormats& rhs)
256{
257 return std::any_of(rhs.begin(), rhs.end(), [lhs](BarcodeFormat bf) { return lhs <= bf; });
258}
259
260inline bool operator&(BarcodeFormat lhs, const BarcodeFormats& rhs)
261{
262 return std::any_of(rhs.begin(), rhs.end(), [lhs](BarcodeFormat bf) { return lhs & bf; });
263}
264
270
271std::string ToString(const BarcodeFormats& formats);
272
273} // namespace ZXing
274
275#endif // __cplusplus
A small container representing a collection of BarcodeFormat values.
Definition BarcodeFormat.h:188
typename std::vector< BarcodeFormat >::value_type value_type
Definition BarcodeFormat.h:223
bool operator==(const BarcodeFormats &o) const noexcept
Definition BarcodeFormat.h:216
bool operator!=(const BarcodeFormats &o) const noexcept
Definition BarcodeFormat.h:217
BarcodeFormats & operator=(BarcodeFormats &&)=default
auto begin() const noexcept
Definition BarcodeFormat.h:220
static BarcodeFormats list(const BarcodeFormats &filter={})
BarcodeFormats(BarcodeFormat f)
Definition BarcodeFormat.h:195
BarcodeFormats(BarcodeFormatArray< N > formats)
Constructs a collection from a compile-time array of BarcodeFormat values.
Definition BarcodeFormat.h:202
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:207
auto end() const noexcept
Definition BarcodeFormat.h:221
BarcodeFormats(BarcodeFormats &&)=default
bool empty() const noexcept
Definition BarcodeFormat.h:227
typename std::vector< BarcodeFormat >::pointer pointer
Definition BarcodeFormat.h:224
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:225
int size() const noexcept
Definition BarcodeFormat.h:228
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.
std::string_view EnumName(BarcodeFormat format)
Returns the C++ enum identifier of the given barcode format.
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:149
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:101
@ AllLinear
Definition BarcodeFormat.h:103
@ AllMatrix
Definition BarcodeFormat.h:103
@ DataBarLtd
Definition BarcodeFormat.h:103
@ All
Definition BarcodeFormat.h:103
@ DataBarExp
Definition BarcodeFormat.h:103
std::array< BarcodeFormat, N > BarcodeFormatArray
Definition BarcodeFormat.h:147
bool operator&(BarcodeFormat a, BarcodeFormat b)
Test if the two BarcodeFormats have a non-empty intersection (e.g. AllMatrix & QRCode).