zxing-cpp
v3.1
Toggle main menu visibility
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
11
namespace
ZXing
{
12
25
26
class
Error
27
{
28
public
:
29
enum class
Type
: uint8_t
30
{
31
None
,
32
Format
,
33
Checksum
,
34
Unsupported
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
57
protected
:
59
std::string _msg;
60
const
char
* _file =
nullptr
;
61
short
_line = -1;
62
Type
_type =
Type::None
;
64
};
65
67
inline
bool
operator==(
const
Error& e,
Error::Type
t)
noexcept
{
return
e.type() == t; }
68
inline
bool
operator!=(
const
Error
& e,
Error::Type
t)
noexcept
{
return
!(e == t); }
69
inline
bool
operator==(
Error::Type
t,
const
Error
& e)
noexcept
{
return
e.type() == t; }
70
inline
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
77
std::string
ToString
(
const
Error
& e);
78
79
}
ZXing::Error
The Error class is a value type for the error() member of Barcode.
Definition
Error.h:27
ZXing::Error::operator!=
bool operator!=(const Error &o) const noexcept
Definition
Error.h:55
ZXing::Error::Type
Type
Definition
Error.h:30
ZXing::Error::Type::Format
@ Format
Format error (i.e. the decoded data is not valid for the detected symbology).
Definition
Error.h:32
ZXing::Error::Type::None
@ None
No error.
Definition
Error.h:31
ZXing::Error::Type::Checksum
@ Checksum
Checksum error (i.e. the decoded data does not pass the checksum validation).
Definition
Error.h:33
ZXing::Error::Type::Unsupported
@ Unsupported
Unsupported error (i.e. a particular feature detected is not supported by zxing-cpp).
Definition
Error.h:34
ZXing::Error::Unsupported
static constexpr auto Unsupported
Definition
Error.h:49
ZXing::Error::operator==
bool operator==(const Error &o) const noexcept
Definition
Error.h:51
ZXing::Error::Error
Error(Type type, std::string msg={})
Definition
Error.h:44
ZXing::Error::msg
const std::string & msg() const noexcept
Definition
Error.h:37
ZXing::Error::Error
Error(const char *file, short line, Type type, std::string msg={})
Definition
Error.h:45
ZXing::Error::Error
Error()=default
ZXing::Error::Format
static constexpr auto Format
Definition
Error.h:47
ZXing::Error::Checksum
static constexpr auto Checksum
Definition
Error.h:48
ZXing::Error::location
std::string location() const
The source code location where the error was detected (if available).
ZXing::Error::type
Type type() const noexcept
Definition
Error.h:36
ZXing
Definition
Barcode.h:26
ZXing::ToString
std::string ToString(BarcodeFormat format)
Error.h
Generated by
1.17.0