IDS peak IPL v1.17.2
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
143{
144 using Exception::Exception;
145};
146
152{
153public:
154 explicit IOException(const std::string& what)
155 : peak::common::Exception(what)
156 , peak::ipl::Exception(what)
157 , peak::common::IOException(what)
158 {}
159
160 explicit IOException(const char* what)
161 : peak::common::Exception(what)
162 , peak::ipl::Exception(what)
163 , peak::common::IOException(what)
164 {}
165
167 : peak::common::Exception(other)
168 , peak::ipl::Exception(other)
169 , peak::common::IOException(other)
170 {}
171};
172
178{
179 using Exception::Exception;
180};
181
187{
188 using Exception::Exception;
189};
190
196{
197public:
198 explicit TimeoutException(const std::string& what)
199 : peak::common::Exception(what)
200 , peak::ipl::Exception(what)
202 {}
203
204 explicit TimeoutException(const char* what)
205 : peak::common::Exception(what)
206 , peak::ipl::Exception(what)
208 {}
209
211 : peak::common::Exception(other)
212 , peak::ipl::Exception(other)
213 , peak::common::TimeoutException(other)
214 {}
215};
216
222{
223 using Exception::Exception;
224};
225
227{
228 std::string entryString;
229
230 switch(entry)
231 {
233 entryString = "PEAK_IPL_RETURN_CODE_SUCCESS";
234 break;
235
237 entryString = "PEAK_IPL_RETURN_CODE_ERROR";
238 break;
239
241 entryString = "PEAK_IPL_RETURN_CODE_BUFFER_TOO_SMALL";
242 break;
243
245 entryString = "PEAK_IPL_RETURN_CODE_INVALID_ARGUMENT";
246 break;
247
249 entryString = "PEAK_IPL_RETURN_CODE_INVALID_HANDLE";
250 break;
251
253 entryString = "PEAK_IPL_RETURN_CODE_OUT_OF_RANGE";
254 break;
255
257 entryString = "PEAK_IPL_RETURN_CODE_IMAGE_FORMAT_NOT_SUPPORTED";
258 break;
259
261 entryString = "PEAK_IPL_RETURN_CODE_IO_ERROR";
262 break;
263
265 entryString = "PEAK_IPL_RETURN_CODE_BUSY";
266 break;
267
269 entryString = "PEAK_IPL_RETURN_CODE_TIMEOUT";
270 break;
271
273 entryString = "PEAK_IPL_RETURN_CODE_FORMAT_INTERPRETATION_ERROR";
274 break;
275
277 entryString = "PEAK_IPL_RETURN_CODE_NOT_SUPPORTED";
278 break;
279
281 entryString = "PEAK_IPL_RETURN_CODE_NOT_PERMITTED";
282 break;
283 }
284
285 return entryString;
286}
287
288template <class CallableType>
289void ExecuteAndMapReturnCodes(const CallableType& callableObject)
290{
291 if (callableObject() != PEAK_IPL_RETURN_CODE_SUCCESS)
292 {
294 size_t lastErrorDescriptionSize = 0;
295 if (PEAK_IPL_C_ABI_PREFIX PEAK_IPL_Library_GetLastError(&lastErrorCode, nullptr, &lastErrorDescriptionSize)
297 {
298 throw Exception("Could not query the last error!");
299 }
300 std::vector<char> lastErrorDescription(lastErrorDescriptionSize);
302 &lastErrorCode, lastErrorDescription.data(), &lastErrorDescriptionSize)
304 {
305 throw Exception("Could not query the last error!");
306 }
307
308 std::stringstream errorText;
309 errorText << "[Error-Code: " << lastErrorCode << " ("
310 << StringFromPEAK_IPL_RETURN_CODE(static_cast<PEAK_IPL_RETURN_CODE_t>(lastErrorCode))
311 << ") | Error-Description: " << lastErrorDescription.data() << "]";
312
313 switch (lastErrorCode)
314 {
316 throw OutOfRangeException(errorText.str().c_str());
318 throw InvalidArgumentException(errorText.str().c_str());
320 throw ImageFormatNotSupportedException(errorText.str().c_str());
322 throw ImageFormatInterpretationException(errorText.str().c_str());
324 throw IOException(errorText.str().c_str());
326 throw BufferTooSmallException(errorText.str().c_str());
328 throw NotPermittedException(errorText.str().c_str());
330 throw BusyException(errorText.str().c_str());
332 throw InvalidHandleException(errorText.str().c_str());
334 throw TimeoutException(errorText.str().c_str());
335 default:
336 throw Exception(errorText.str().c_str());
337 }
338 }
339}
340
341} /* namespace ipl */
342} /* 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:145
Thrown when a function receives an invalid parameter.
Definition peak_common_exceptions.hpp:58
Thrown when an unsupported operation or feature is used.
Definition peak_common_exceptions.hpp:158
Thrown when a parameter is outside the valid range.
Definition peak_common_exceptions.hpp:119
Thrown when an operation exceeds its time limit.
Definition peak_common_exceptions.hpp:132
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 is busy.
Definition peak_ipl_exception.hpp:178
The base class for all exceptions thrown by the library.
Definition peak_ipl_exception.hpp:40
The exception that is thrown when an image input or output operation fails.
Definition peak_ipl_exception.hpp:152
IOException(const std::string &what)
Definition peak_ipl_exception.hpp:154
IOException(const char *what)
Definition peak_ipl_exception.hpp:160
IOException(const IOException &other)
Definition peak_ipl_exception.hpp:166
The exception that is thrown when image data cannot be interpreted using the requested pixel format.
Definition peak_ipl_exception.hpp:143
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:222
The exception thrown when the operation is not permitted.
Definition peak_ipl_exception.hpp:187
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:196
TimeoutException(const TimeoutException &other)
Definition peak_ipl_exception.hpp:210
TimeoutException(const char *what)
Definition peak_ipl_exception.hpp:204
TimeoutException(const std::string &what)
Definition peak_ipl_exception.hpp:198
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:226
void ExecuteAndMapReturnCodes(const CallableType &callableObject)
Definition peak_ipl_exception.hpp:289
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