IDS peak IPL v1.17.1
Loading...
Searching...
No Matches
peak_ipl_exception.hpp
Go to the documentation of this file.
1
10
11#pragma once
12
14
16
17#include <cstddef>
18#include <cstdlib>
19#include <cstring>
20#include <sstream>
21#include <stdexcept>
22#include <string>
23#include <vector>
24
29
30namespace peak
31{
32namespace ipl
33{
34
39class Exception : public virtual peak::common::Exception
40{
41 using peak::common::Exception::Exception;
42};
43
49{
50public:
51 explicit OutOfRangeException(const std::string& what)
52 : peak::common::Exception(what)
53 , peak::ipl::Exception(what)
55 {}
56
57 explicit OutOfRangeException(const char* what)
58 : peak::common::Exception(what)
59 , peak::ipl::Exception(what)
61 {}
62
64 : peak::common::Exception(other)
65 , peak::ipl::Exception(other)
67 {}
68};
69
75{
76 using Exception::Exception;
77};
78
84{
85public:
86 explicit InvalidArgumentException(const std::string& what)
87 : peak::common::Exception(what)
88 , peak::ipl::Exception(what)
89 , peak::common::InvalidParameterException(what)
90 {}
91
92 explicit InvalidArgumentException(const char* what)
93 : peak::common::Exception(what)
94 , peak::ipl::Exception(what)
95 , peak::common::InvalidParameterException(what)
96 {}
97
99 : peak::common::Exception(other)
100 , peak::ipl::Exception(other)
101 , peak::common::InvalidParameterException(other)
102 {}
103};
104
110{
111public:
112 explicit ImageFormatNotSupportedException(const std::string& what)
113 : peak::common::Exception(what)
114 , peak::ipl::Exception(what)
115 , peak::common::NotSupportedException(what)
116 {}
117
118 explicit ImageFormatNotSupportedException(const char* what)
119 : peak::common::Exception(what)
120 , peak::ipl::Exception(what)
121 , peak::common::NotSupportedException(what)
122 {}
123
125 : peak::common::Exception(other)
126 , peak::ipl::Exception(other)
127 , peak::common::NotSupportedException(other)
128 {}
129};
130
136{
137 using Exception::Exception;
138};
139
145{
146public:
147 explicit IOException(const std::string& what)
148 : peak::common::Exception(what)
149 , peak::ipl::Exception(what)
150 , peak::common::IOException(what)
151 {}
152
153 explicit IOException(const char* what)
154 : peak::common::Exception(what)
155 , peak::ipl::Exception(what)
156 , peak::common::IOException(what)
157 {}
158
160 : peak::common::Exception(other)
161 , peak::ipl::Exception(other)
162 , peak::common::IOException(other)
163 {}
164};
165
171{
172 using Exception::Exception;
173};
174
180{
181 using Exception::Exception;
182};
183
189{
190public:
191 explicit TimeoutException(const std::string& what)
192 : peak::common::Exception(what)
193 , peak::ipl::Exception(what)
195 {}
196
197 explicit TimeoutException(const char* what)
198 : peak::common::Exception(what)
199 , peak::ipl::Exception(what)
201 {}
202
204 : peak::common::Exception(other)
205 , peak::ipl::Exception(other)
206 , peak::common::TimeoutException(other)
207 {}
208};
209
215{
216 using Exception::Exception;
217};
218
220{
221 std::string entryString;
222
223 switch(entry)
224 {
226 entryString = "PEAK_IPL_RETURN_CODE_SUCCESS";
227 break;
228
230 entryString = "PEAK_IPL_RETURN_CODE_ERROR";
231 break;
232
234 entryString = "PEAK_IPL_RETURN_CODE_BUFFER_TOO_SMALL";
235 break;
236
238 entryString = "PEAK_IPL_RETURN_CODE_INVALID_ARGUMENT";
239 break;
240
242 entryString = "PEAK_IPL_RETURN_CODE_INVALID_HANDLE";
243 break;
244
246 entryString = "PEAK_IPL_RETURN_CODE_OUT_OF_RANGE";
247 break;
248
250 entryString = "PEAK_IPL_RETURN_CODE_IMAGE_FORMAT_NOT_SUPPORTED";
251 break;
252
254 entryString = "PEAK_IPL_RETURN_CODE_IO_ERROR";
255 break;
256
258 entryString = "PEAK_IPL_RETURN_CODE_BUSY";
259 break;
260
262 entryString = "PEAK_IPL_RETURN_CODE_TIMEOUT";
263 break;
264
266 entryString = "PEAK_IPL_RETURN_CODE_FORMAT_INTERPRETATION_ERROR";
267 break;
268
270 entryString = "PEAK_IPL_RETURN_CODE_NOT_SUPPORTED";
271 break;
272
274 entryString = "PEAK_IPL_RETURN_CODE_NOT_PERMITTED";
275 break;
276 }
277
278 return entryString;
279}
280
281template <class CallableType>
282void ExecuteAndMapReturnCodes(const CallableType& callableObject)
283{
284 if (callableObject() != PEAK_IPL_RETURN_CODE_SUCCESS)
285 {
287 size_t lastErrorDescriptionSize = 0;
288 if (PEAK_IPL_C_ABI_PREFIX PEAK_IPL_Library_GetLastError(&lastErrorCode, nullptr, &lastErrorDescriptionSize)
290 {
291 throw Exception("Could not query the last error!");
292 }
293 std::vector<char> lastErrorDescription(lastErrorDescriptionSize);
295 &lastErrorCode, lastErrorDescription.data(), &lastErrorDescriptionSize)
297 {
298 throw Exception("Could not query the last error!");
299 }
300
301 std::stringstream errorText;
302 errorText << "[Error-Code: " << lastErrorCode << " ("
303 << StringFromPEAK_IPL_RETURN_CODE(static_cast<PEAK_IPL_RETURN_CODE_t>(lastErrorCode))
304 << ") | Error-Description: " << lastErrorDescription.data() << "]";
305
306 switch (lastErrorCode)
307 {
309 throw OutOfRangeException(errorText.str().c_str());
311 throw InvalidArgumentException(errorText.str().c_str());
313 throw ImageFormatNotSupportedException(errorText.str().c_str());
315 throw ImageFormatInterpretationException(errorText.str().c_str());
317 throw IOException(errorText.str().c_str());
319 throw BufferTooSmallException(errorText.str().c_str());
321 throw NotPermittedException(errorText.str().c_str());
323 throw BusyException(errorText.str().c_str());
325 throw InvalidHandleException(errorText.str().c_str());
327 throw TimeoutException(errorText.str().c_str());
328 default:
329 throw Exception(errorText.str().c_str());
330 }
331 }
332}
333
334} /* namespace ipl */
335} /* namespace peak */
Base class for all exceptions thrown by the library.
Definition peak_common_exceptions.hpp:36
Thrown when an input, output, file or device communication error occurs.
Definition peak_common_exceptions.hpp:136
Thrown when a function receives an invalid parameter.
Definition peak_common_exceptions.hpp:49
Thrown when an unsupported operation or feature is used.
Definition peak_common_exceptions.hpp:149
Thrown when a parameter is outside the valid range.
Definition peak_common_exceptions.hpp:110
Thrown when an operation exceeds its time limit.
Definition peak_common_exceptions.hpp:123
The exception thrown when a given buffer is too small for the data.
Definition peak_ipl_exception.hpp:75
The exception thrown when the resource busy.
Definition peak_ipl_exception.hpp:171
The base class for all exceptions thrown by the library.
Definition peak_ipl_exception.hpp:40
The exception thrown when a given image format can't be used on this data, e.g. during reading from f...
Definition peak_ipl_exception.hpp:145
IOException(const std::string &what)
Definition peak_ipl_exception.hpp:147
IOException(const char *what)
Definition peak_ipl_exception.hpp:153
IOException(const IOException &other)
Definition peak_ipl_exception.hpp:159
The exception thrown when a given image format can't be used on this data, e.g. during reading from f...
Definition peak_ipl_exception.hpp:136
The exception thrown when an image format isn't supported by a function.
Definition peak_ipl_exception.hpp:110
ImageFormatNotSupportedException(const char *what)
Definition peak_ipl_exception.hpp:118
ImageFormatNotSupportedException(const ImageFormatNotSupportedException &other)
Definition peak_ipl_exception.hpp:124
ImageFormatNotSupportedException(const std::string &what)
Definition peak_ipl_exception.hpp:112
The exception thrown when passing an invalid parameter to a function.
Definition peak_ipl_exception.hpp:84
InvalidArgumentException(const std::string &what)
Definition peak_ipl_exception.hpp:86
InvalidArgumentException(const char *what)
Definition peak_ipl_exception.hpp:92
InvalidArgumentException(const InvalidArgumentException &other)
Definition peak_ipl_exception.hpp:98
The exception thrown when passing an invalid handle to a function.
Definition peak_ipl_exception.hpp:215
The exception thrown when the operation not permitted.
Definition peak_ipl_exception.hpp:180
The exception thrown for trying to access a value being out of range.
Definition peak_ipl_exception.hpp:49
OutOfRangeException(const char *what)
Definition peak_ipl_exception.hpp:57
OutOfRangeException(const OutOfRangeException &other)
Definition peak_ipl_exception.hpp:63
OutOfRangeException(const std::string &what)
Definition peak_ipl_exception.hpp:51
The exception thrown when the operation times out.
Definition peak_ipl_exception.hpp:189
TimeoutException(const TimeoutException &other)
Definition peak_ipl_exception.hpp:203
TimeoutException(const char *what)
Definition peak_ipl_exception.hpp:197
TimeoutException(const std::string &what)
Definition peak_ipl_exception.hpp:191
Root namespace for common types and interfaces shared across multiple libraries.
Definition peak_common_math.hpp:22
The "peak::ipl" namespace contains the whole image processing library.
std::string StringFromPEAK_IPL_RETURN_CODE(PEAK_IPL_RETURN_CODE_t entry)
Definition peak_ipl_exception.hpp:219
void ExecuteAndMapReturnCodes(const CallableType &callableObject)
Definition peak_ipl_exception.hpp:282
int32_t PEAK_IPL_RETURN_CODE
Definition peak_ipl_backend.h:46
PEAK_IPL_C_API PEAK_IPL_Library_GetLastError(PEAK_IPL_RETURN_CODE *lastErrorCode, char *lastErrorDescription, size_t *lastErrorDescriptionSize)
Queries the last error.
PEAK_IPL_RETURN_CODE_t
Definition peak_ipl_backend.h:30
@ PEAK_IPL_RETURN_CODE_SUCCESS
Definition peak_ipl_backend.h:31
@ PEAK_IPL_RETURN_CODE_OUT_OF_RANGE
Definition peak_ipl_backend.h:37
@ PEAK_IPL_RETURN_CODE_IO_ERROR
Definition peak_ipl_backend.h:34
@ PEAK_IPL_RETURN_CODE_FORMAT_INTERPRETATION_ERROR
Definition peak_ipl_backend.h:39
@ PEAK_IPL_RETURN_CODE_INVALID_HANDLE
Definition peak_ipl_backend.h:33
@ PEAK_IPL_RETURN_CODE_INVALID_ARGUMENT
Definition peak_ipl_backend.h:36
@ PEAK_IPL_RETURN_CODE_BUFFER_TOO_SMALL
Definition peak_ipl_backend.h:35
@ PEAK_IPL_RETURN_CODE_ERROR
Definition peak_ipl_backend.h:32
@ PEAK_IPL_RETURN_CODE_NOT_PERMITTED
Definition peak_ipl_backend.h:41
@ PEAK_IPL_RETURN_CODE_BUSY
Definition peak_ipl_backend.h:42
@ PEAK_IPL_RETURN_CODE_IMAGE_FORMAT_NOT_SUPPORTED
Definition peak_ipl_backend.h:38
@ PEAK_IPL_RETURN_CODE_TIMEOUT
Definition peak_ipl_backend.h:43
@ PEAK_IPL_RETURN_CODE_NOT_SUPPORTED
Definition peak_ipl_backend.h:40
#define PEAK_IPL_C_ABI_PREFIX
Definition peak_ipl_dll_defines.h:16