comparison mupdf-source/thirdparty/zxing-cpp/core/src/DecoderResult.h @ 2:b50eed0cc0ef upstream

ADD: MuPDF v1.26.7: the MuPDF source as downloaded by a default build of PyMuPDF 1.26.4. The directory name has changed: no version number in the expanded directory now.
author Franz Glasner <fzglas.hg@dom66.de>
date Mon, 15 Sep 2025 11:43:07 +0200
parents
children
comparison
equal deleted inserted replaced
1:1d09e1dec1d9 2:b50eed0cc0ef
1 /*
2 * Copyright 2016 Nu-book Inc.
3 * Copyright 2016 ZXing authors
4 */
5 // SPDX-License-Identifier: Apache-2.0
6
7 #pragma once
8
9 #include "Content.h"
10 #include "Error.h"
11 #include "StructuredAppend.h"
12
13 #include <memory>
14 #include <string>
15 #include <utility>
16
17 namespace ZXing {
18
19 class CustomData;
20
21 class DecoderResult
22 {
23 Content _content;
24 std::string _ecLevel;
25 int _lineCount = 0;
26 int _versionNumber = 0;
27 int _dataMask = 0;
28 StructuredAppendInfo _structuredAppend;
29 bool _isMirrored = false;
30 bool _readerInit = false;
31 Error _error;
32 std::shared_ptr<CustomData> _extra;
33
34 DecoderResult(const DecoderResult &) = delete;
35 DecoderResult& operator=(const DecoderResult &) = delete;
36
37 public:
38 DecoderResult() = default;
39 DecoderResult(Error error) : _error(std::move(error)) {}
40 DecoderResult(Content&& bytes) : _content(std::move(bytes)) {}
41
42 DecoderResult(DecoderResult&&) noexcept = default;
43 DecoderResult& operator=(DecoderResult&&) noexcept = default;
44
45 bool isValid(bool includeErrors = false) const
46 {
47 return (!_content.bytes.empty() && !_error) || (includeErrors && !!_error);
48 }
49
50 const Content& content() const & { return _content; }
51 Content&& content() && { return std::move(_content); }
52
53 // to keep the unit tests happy for now:
54 std::wstring text() const { return _content.utfW(); }
55 std::string symbologyIdentifier() const { return _content.symbology.toString(false); }
56
57 // Simple macro to set up getter/setter methods that save lots of boilerplate.
58 // It sets up a standard 'const & () const', 2 setters for setting lvalues via
59 // copy and 2 for setting rvalues via move. They are provided each to work
60 // either on lvalues (normal 'void (...)') or on rvalues (returning '*this' as
61 // rvalue). The latter can be used to optionally initialize a temporary in a
62 // return statement, e.g.
63 // return DecoderResult(bytes, text).setEcLevel(level);
64 #define ZX_PROPERTY(TYPE, GETTER, SETTER) \
65 const TYPE& GETTER() const & { return _##GETTER; } \
66 TYPE&& GETTER() && { return std::move(_##GETTER); } \
67 void SETTER(const TYPE& v) & { _##GETTER = v; } \
68 void SETTER(TYPE&& v) & { _##GETTER = std::move(v); } \
69 DecoderResult&& SETTER(const TYPE& v) && { _##GETTER = v; return std::move(*this); } \
70 DecoderResult&& SETTER(TYPE&& v) && { _##GETTER = std::move(v); return std::move(*this); }
71
72 ZX_PROPERTY(std::string, ecLevel, setEcLevel)
73 ZX_PROPERTY(int, lineCount, setLineCount)
74 ZX_PROPERTY(int, versionNumber, setVersionNumber)
75 ZX_PROPERTY(int, dataMask, setDataMask)
76 ZX_PROPERTY(StructuredAppendInfo, structuredAppend, setStructuredAppend)
77 ZX_PROPERTY(Error, error, setError)
78 ZX_PROPERTY(bool, isMirrored, setIsMirrored)
79 ZX_PROPERTY(bool, readerInit, setReaderInit)
80 ZX_PROPERTY(std::shared_ptr<CustomData>, extra, setExtra)
81
82 #undef ZX_PROPERTY
83 };
84
85 } // ZXing