zxing-cpp v3.0
Loading...
Searching...
No Matches
Error.h
Go to the documentation of this file.
1/*
2 * Copyright 2022 Axel Waggershauser
3 */
4// SPDX-License-Identifier: Apache-2.0
5
6#pragma once
7
8#include <string>
9#include <cstdint>
10
11namespace ZXing {
12
25
26class Error
27{
28public:
29 enum class Type : uint8_t
30 {
35 };
36 Type type() const noexcept { return _type; }
37 const std::string& msg() const noexcept { return _msg; }
38 explicit operator bool() const noexcept { return _type != Type::None; }
39
41 std::string location() const;
42
43 Error() = default;
44 Error(Type type, std::string msg = {}) : _msg(std::move(msg)), _type(type) {}
45 Error(const char* file, short line, Type type, std::string msg = {}) : _msg(std::move(msg)), _file(file), _line(line), _type(type) {}
46
47 static constexpr auto Format = Type::Format;
48 static constexpr auto Checksum = Type::Checksum;
49 static constexpr auto Unsupported = Type::Unsupported;
50
51 inline bool operator==(const Error& o) const noexcept
52 {
53 return _type == o._type && _msg == o._msg && _file == o._file && _line == o._line;
54 }
55 inline bool operator!=(const Error& o) const noexcept { return !(*this == o); }
56
57protected:
59 std::string _msg;
60 const char* _file = nullptr;
61 short _line = -1;
62 Type _type = Type::None;
64};
65
67inline bool operator==(const Error& e, Error::Type t) noexcept { return e.type() == t; }
68inline bool operator!=(const Error& e, Error::Type t) noexcept { return !(e == t); }
69inline bool operator==(Error::Type t, const Error& e) noexcept { return e.type() == t; }
70inline bool operator!=(Error::Type t, const Error& e) noexcept { return !(t == e); }
71
72#define FormatError(...) Error(__FILE__, __LINE__, Error::Format, std::string(__VA_ARGS__))
73#define ChecksumError(...) Error(__FILE__, __LINE__, Error::Checksum, std::string(__VA_ARGS__))
74#define UnsupportedError(...) Error(__FILE__, __LINE__, Error::Unsupported, std::string(__VA_ARGS__))
76
77std::string ToString(const Error& e);
78
79}
The Error class is a value type for the error() member of Barcode.
Definition Error.h:27
bool operator!=(const Error &o) const noexcept
Definition Error.h:55
Type
Definition Error.h:30
@ Format
Format error (i.e. the decoded data is not valid for the detected symbology).
Definition Error.h:32
@ None
No error.
Definition Error.h:31
@ Checksum
Checksum error (i.e. the decoded data does not pass the checksum validation).
Definition Error.h:33
@ Unsupported
Unsupported error (i.e. a particular feature detected is not supported by zxing-cpp).
Definition Error.h:34
static constexpr auto Unsupported
Definition Error.h:49
bool operator==(const Error &o) const noexcept
Definition Error.h:51
Error(Type type, std::string msg={})
Definition Error.h:44
const std::string & msg() const noexcept
Definition Error.h:37
Error(const char *file, short line, Type type, std::string msg={})
Definition Error.h:45
Error()=default
static constexpr auto Format
Definition Error.h:47
static constexpr auto Checksum
Definition Error.h:48
std::string location() const
The source code location where the error was detected (if available).
Type type() const noexcept
Definition Error.h:36
Definition Barcode.h:26
std::string ToString(BarcodeFormat format)