IDS peak ICV v1.2.0
Loading...
Searching...
No Matches
peak_icv_code_reader_result.hpp
Go to the documentation of this file.
1
11#pragma once
14#include <peak_icv_c/algorithms/code_reader/peak_icv_code_reader.h>
15#include <string>
16#include <vector>
17
18namespace peak
19{
20namespace icv
21{
22namespace experimental
23{
32class CodeReaderResult : public detail::IBackendAccessible<CodeReaderResult>
33{
34public:
48 ~CodeReaderResult() override;
49
50 CodeReaderResult(const CodeReaderResult& other) = delete;
57 CodeReaderResult(CodeReaderResult&& other) noexcept;
66
73 PEAK_COMMON_NO_DISCARD std::string GetText() const;
74
81 PEAK_COMMON_NO_DISCARD CodeType GetType() const;
82
83private:
84 friend peak::common::detail::BackendAccessor<CodeReaderResult>;
85 explicit CodeReaderResult(peak_icv_code_reader_result_handle handle);
86
87 PEAK_COMMON_NO_DISCARD peak_icv_code_reader_result_handle GetHandle() const override;
88 static peak_icv_code_reader_result_handle createHandle();
89 peak_icv_code_reader_result_handle m_handle;
90};
91
93{
94 m_handle = std::exchange(other.m_handle, nullptr);
95}
96
98{
99 if (m_handle != other.m_handle)
100 {
101 if (m_handle != nullptr)
102 {
104 return PEAK_ICV_C_ABI_PREFIX peak_icv_BarcodeReaderResult_Destroy(m_handle);
105 });
106 }
107
108 m_handle = std::exchange(other.m_handle, nullptr);
109 }
110
111 return *this;
112}
113
114inline CodeReaderResult::CodeReaderResult(peak_icv_code_reader_result_handle handle)
115 : m_handle{ handle }
116{}
117
118inline peak_icv_code_reader_result_handle CodeReaderResult::GetHandle() const
119{
120 return m_handle;
121}
122
123inline peak_icv_code_reader_result_handle CodeReaderResult::createHandle()
124{
125 peak_icv_code_reader_result_handle handle{};
127 return PEAK_ICV_C_ABI_PREFIX peak_icv_BarcodeReaderResult_Create(&handle);
128 });
129 return handle;
130}
131
133 : m_handle{ createHandle() }
134{}
135
137{
138 if (m_handle != nullptr)
139 {
140 std::ignore = PEAK_ICV_C_ABI_PREFIX peak_icv_BarcodeReaderResult_Destroy(m_handle);
141 }
142}
143
144inline std::string CodeReaderResult::GetText() const
145{
146 size_t text_size_in_bytes{};
148 return PEAK_ICV_C_ABI_PREFIX peak_icv_BarcodeReaderResult_GetText_GetSizeInBytes(m_handle, &text_size_in_bytes);
149 });
150
151 std::vector<char> data(text_size_in_bytes);
153 return PEAK_ICV_C_ABI_PREFIX peak_icv_BarcodeReaderResult_GetText(m_handle, data.data(), data.size());
154 });
155
156 return { data.begin(), data.end() - 1 };
157}
158
160{
161 peak_icv_code_type cType{};
163 return PEAK_ICV_C_ABI_PREFIX peak_icv_BarcodeReaderResult_GetType(m_handle, &cType);
164 });
165
166 return static_cast<CodeType>(cType);
167}
168
169} // namespace experimental
170} // namespace icv
171} // namespace peak
Class that represents a code that was found in an image.
CodeType GetType() const
Provides the type of the code.
std::string GetText() const
Provides the decoded text of the code.
CodeReaderResult & operator=(const CodeReaderResult &other)=delete
CodeReaderResult(const CodeReaderResult &other)=delete
CodeReaderResult()
Creates an empty instance of a code result.
CodeType
Enum that holds the possible code types for detection and identification.
void ExecuteAndMapReturnCodes(const CallableType &callableObject)