IDS peak IPL v1.18.0
Loading...
Searching...
No Matches
peak_ipl_exception.hpp
Go to the documentation of this file.
1
5
6#pragma once
7
9
11
12#include <cstddef>
13#include <cstdlib>
14#include <cstring>
15#include <sstream>
16#include <stdexcept>
17#include <string>
18#include <vector>
19
24
25namespace peak
26{
27namespace ipl
28{
29
34class Exception : public virtual peak::common::Exception
35{
36 using peak::common::Exception::Exception;
37};
38
44{
45public:
46 explicit OutOfRangeException(const std::string& what)
47 : peak::common::Exception(what)
48 , peak::ipl::Exception(what)
50 {}
51
52 explicit OutOfRangeException(const char* what)
53 : peak::common::Exception(what)
54 , peak::ipl::Exception(what)
56 {}
57
59 : peak::common::Exception(other)
60 , peak::ipl::Exception(other)
62 {}
63};
64
70{
71 using Exception::Exception;
72};
73
79{
80public:
81 explicit InvalidArgumentException(const std::string& what)
82 : peak::common::Exception(what)
83 , peak::ipl::Exception(what)
84 , peak::common::InvalidParameterException(what)
85 {}
86
87 explicit InvalidArgumentException(const char* what)
88 : peak::common::Exception(what)
89 , peak::ipl::Exception(what)
90 , peak::common::InvalidParameterException(what)
91 {}
92
94 : peak::common::Exception(other)
95 , peak::ipl::Exception(other)
96 , peak::common::InvalidParameterException(other)
97 {}
98};
99
105{
106public:
107 explicit ImageFormatNotSupportedException(const std::string& what)
108 : peak::common::Exception(what)
109 , peak::ipl::Exception(what)
110 , peak::common::NotSupportedException(what)
111 {}
112
113 explicit ImageFormatNotSupportedException(const char* what)
114 : peak::common::Exception(what)
115 , peak::ipl::Exception(what)
116 , peak::common::NotSupportedException(what)
117 {}
118
120 : peak::common::Exception(other)
121 , peak::ipl::Exception(other)
122 , peak::common::NotSupportedException(other)
123 {}
124};
125
138{
139 using Exception::Exception;
140};
141
147{
148public:
149 explicit IOException(const std::string& what)
150 : peak::common::Exception(what)
151 , peak::ipl::Exception(what)
152 , peak::common::IOException(what)
153 {}
154
155 explicit IOException(const char* what)
156 : peak::common::Exception(what)
157 , peak::ipl::Exception(what)
158 , peak::common::IOException(what)
159 {}
160
162 : peak::common::Exception(other)
163 , peak::ipl::Exception(other)
164 , peak::common::IOException(other)
165 {}
166};
167
173{
174 using Exception::Exception;
175};
176
182{
183 using Exception::Exception;
184};
185
191{
192public:
193 explicit TimeoutException(const std::string& what)
194 : peak::common::Exception(what)
195 , peak::ipl::Exception(what)
197 {}
198
199 explicit TimeoutException(const char* what)
200 : peak::common::Exception(what)
201 , peak::ipl::Exception(what)
203 {}
204
206 : peak::common::Exception(other)
207 , peak::ipl::Exception(other)
208 , peak::common::TimeoutException(other)
209 {}
210};
211
217{
218 using Exception::Exception;
219};
220
222{
223 std::string entryString;
224
225 switch(entry)
226 {
228 entryString = "PEAK_IPL_RETURN_CODE_SUCCESS";
229 break;
230
232 entryString = "PEAK_IPL_RETURN_CODE_ERROR";
233 break;
234
236 entryString = "PEAK_IPL_RETURN_CODE_BUFFER_TOO_SMALL";
237 break;
238
240 entryString = "PEAK_IPL_RETURN_CODE_INVALID_ARGUMENT";
241 break;
242
244 entryString = "PEAK_IPL_RETURN_CODE_INVALID_HANDLE";
245 break;
246
248 entryString = "PEAK_IPL_RETURN_CODE_OUT_OF_RANGE";
249 break;
250
252 entryString = "PEAK_IPL_RETURN_CODE_IMAGE_FORMAT_NOT_SUPPORTED";
253 break;
254
256 entryString = "PEAK_IPL_RETURN_CODE_IO_ERROR";
257 break;
258
260 entryString = "PEAK_IPL_RETURN_CODE_BUSY";
261 break;
262
264 entryString = "PEAK_IPL_RETURN_CODE_TIMEOUT";
265 break;
266
268 entryString = "PEAK_IPL_RETURN_CODE_FORMAT_INTERPRETATION_ERROR";
269 break;
270
272 entryString = "PEAK_IPL_RETURN_CODE_NOT_SUPPORTED";
273 break;
274
276 entryString = "PEAK_IPL_RETURN_CODE_NOT_PERMITTED";
277 break;
278 }
279
280 return entryString;
281}
282
283template <class CallableType>
284void ExecuteAndMapReturnCodes(const CallableType& callableObject)
285{
286 if (callableObject() != PEAK_IPL_RETURN_CODE_SUCCESS)
287 {
289 size_t lastErrorDescriptionSize = 0;
290 if (PEAK_IPL_C_ABI_PREFIX PEAK_IPL_Library_GetLastError(&lastErrorCode, nullptr, &lastErrorDescriptionSize)
292 {
293 throw Exception("Could not query the last error!");
294 }
295 std::vector<char> lastErrorDescription(lastErrorDescriptionSize);
297 &lastErrorCode, lastErrorDescription.data(), &lastErrorDescriptionSize)
299 {
300 throw Exception("Could not query the last error!");
301 }
302
303 std::stringstream errorText;
304 errorText << "[Error-Code: " << lastErrorCode << " ("
305 << StringFromPEAK_IPL_RETURN_CODE(static_cast<PEAK_IPL_RETURN_CODE_t>(lastErrorCode))
306 << ") | Error-Description: " << lastErrorDescription.data() << "]";
307
308 switch (lastErrorCode)
309 {
311 throw OutOfRangeException(errorText.str().c_str());
313 throw InvalidArgumentException(errorText.str().c_str());
315 throw ImageFormatNotSupportedException(errorText.str().c_str());
317 throw ImageFormatInterpretationException(errorText.str().c_str());
319 throw IOException(errorText.str().c_str());
321 throw BufferTooSmallException(errorText.str().c_str());
323 throw NotPermittedException(errorText.str().c_str());
325 throw BusyException(errorText.str().c_str());
327 throw InvalidHandleException(errorText.str().c_str());
329 throw TimeoutException(errorText.str().c_str());
330 default:
331 throw Exception(errorText.str().c_str());
332 }
333 }
334}
335
336} /* namespace ipl */
337} /* namespace peak */
Base class for all exceptions thrown by the library.
Definition peak_common_exceptions.hpp:31
Thrown when an input, output, file or device communication error occurs.
Definition peak_common_exceptions.hpp:140
Thrown when a function receives an invalid parameter.
Definition peak_common_exceptions.hpp:53
Thrown when an unsupported operation or feature is used.
Definition peak_common_exceptions.hpp:153
Thrown when a parameter is outside the valid range.
Definition peak_common_exceptions.hpp:114
Thrown when an operation exceeds its time limit.
Definition peak_common_exceptions.hpp:127
The exception thrown when a given buffer is too small for the data.
Definition peak_ipl_exception.hpp:70
The exception thrown when the resource is busy.
Definition peak_ipl_exception.hpp:173
The base class for all exceptions thrown by the library.
Definition peak_ipl_exception.hpp:35
The exception that is thrown when an image input or output operation fails.
Definition peak_ipl_exception.hpp:147
IOException(const std::string &what)
Definition peak_ipl_exception.hpp:149
IOException(const char *what)
Definition peak_ipl_exception.hpp:155
IOException(const IOException &other)
Definition peak_ipl_exception.hpp:161
The exception that is thrown when image data cannot be interpreted using the requested pixel format.
Definition peak_ipl_exception.hpp:138
The exception thrown when an image format isn't supported by a function.
Definition peak_ipl_exception.hpp:105
ImageFormatNotSupportedException(const char *what)
Definition peak_ipl_exception.hpp:113
ImageFormatNotSupportedException(const ImageFormatNotSupportedException &other)
Definition peak_ipl_exception.hpp:119
ImageFormatNotSupportedException(const std::string &what)
Definition peak_ipl_exception.hpp:107
The exception thrown when passing an invalid parameter to a function.
Definition peak_ipl_exception.hpp:79
InvalidArgumentException(const std::string &what)
Definition peak_ipl_exception.hpp:81
InvalidArgumentException(const char *what)
Definition peak_ipl_exception.hpp:87
InvalidArgumentException(const InvalidArgumentException &other)
Definition peak_ipl_exception.hpp:93
The exception thrown when passing an invalid handle to a function.
Definition peak_ipl_exception.hpp:217
The exception thrown when the operation is not permitted.
Definition peak_ipl_exception.hpp:182
The exception thrown for trying to access a value being out of range.
Definition peak_ipl_exception.hpp:44
OutOfRangeException(const char *what)
Definition peak_ipl_exception.hpp:52
OutOfRangeException(const OutOfRangeException &other)
Definition peak_ipl_exception.hpp:58
OutOfRangeException(const std::string &what)
Definition peak_ipl_exception.hpp:46
The exception thrown when the operation times out.
Definition peak_ipl_exception.hpp:191
TimeoutException(const TimeoutException &other)
Definition peak_ipl_exception.hpp:205
TimeoutException(const char *what)
Definition peak_ipl_exception.hpp:199
TimeoutException(const std::string &what)
Definition peak_ipl_exception.hpp:193
Root namespace for common types and interfaces shared across multiple libraries.
Definition peak_common_math.hpp:17
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:221
void ExecuteAndMapReturnCodes(const CallableType &callableObject)
Definition peak_ipl_exception.hpp:284
int32_t PEAK_IPL_RETURN_CODE
Definition peak_ipl_backend.h:43
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:27
@ PEAK_IPL_RETURN_CODE_SUCCESS
Definition peak_ipl_backend.h:28
@ PEAK_IPL_RETURN_CODE_OUT_OF_RANGE
Definition peak_ipl_backend.h:34
@ PEAK_IPL_RETURN_CODE_IO_ERROR
Definition peak_ipl_backend.h:31
@ PEAK_IPL_RETURN_CODE_FORMAT_INTERPRETATION_ERROR
Definition peak_ipl_backend.h:36
@ PEAK_IPL_RETURN_CODE_INVALID_HANDLE
Definition peak_ipl_backend.h:30
@ PEAK_IPL_RETURN_CODE_INVALID_ARGUMENT
Definition peak_ipl_backend.h:33
@ PEAK_IPL_RETURN_CODE_BUFFER_TOO_SMALL
Definition peak_ipl_backend.h:32
@ PEAK_IPL_RETURN_CODE_ERROR
Definition peak_ipl_backend.h:29
@ PEAK_IPL_RETURN_CODE_NOT_PERMITTED
Definition peak_ipl_backend.h:38
@ PEAK_IPL_RETURN_CODE_BUSY
Definition peak_ipl_backend.h:39
@ PEAK_IPL_RETURN_CODE_IMAGE_FORMAT_NOT_SUPPORTED
Definition peak_ipl_backend.h:35
@ PEAK_IPL_RETURN_CODE_TIMEOUT
Definition peak_ipl_backend.h:40
@ PEAK_IPL_RETURN_CODE_NOT_SUPPORTED
Definition peak_ipl_backend.h:37
#define PEAK_IPL_C_ABI_PREFIX
Definition peak_ipl_dll_defines.h:11