IDS peak IPL v1.17.0
Loading...
Searching...
No Matches
peak_ipl_exception.hpp
Go to the documentation of this file.
1
10
11#pragma once
12
14
15#include <peak_common/exceptions/peak_common_exceptions.hpp>
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
38class Exception : public virtual peak::common::Exception
39{
40 using peak::common::Exception::Exception;
41};
42
46class OutOfRangeException : public Exception, public peak::common::OutOfRangeException
47{
48public:
49 explicit OutOfRangeException(const std::string& what)
50 : peak::common::Exception(what)
51 , peak::ipl::Exception(what)
52 , peak::common::OutOfRangeException(what)
53 {}
54
55 explicit OutOfRangeException(const char* what)
56 : peak::common::Exception(what)
57 , peak::ipl::Exception(what)
58 , peak::common::OutOfRangeException(what)
59 {}
60
62 : peak::common::Exception(other)
63 , peak::ipl::Exception(other)
64 , peak::common::OutOfRangeException(other)
65 {}
66};
67
72{
73 using Exception::Exception;
74};
75
79class InvalidArgumentException : public Exception, public peak::common::InvalidParameterException
80{
81public:
82 explicit InvalidArgumentException(const std::string& what)
83 : peak::common::Exception(what)
84 , peak::ipl::Exception(what)
85 , peak::common::InvalidParameterException(what)
86 {}
87
88 explicit InvalidArgumentException(const char* what)
89 : peak::common::Exception(what)
90 , peak::ipl::Exception(what)
91 , peak::common::InvalidParameterException(what)
92 {}
93
95 : peak::common::Exception(other)
96 , peak::ipl::Exception(other)
97 , peak::common::InvalidParameterException(other)
98 {}
99};
100
104class ImageFormatNotSupportedException : public Exception, public peak::common::NotSupportedException
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
130{
131 using Exception::Exception;
132};
133
137class IOException : public Exception, public peak::common::IOException
138{
139public:
140 explicit IOException(const std::string& what)
141 : peak::common::Exception(what)
142 , peak::ipl::Exception(what)
143 , peak::common::IOException(what)
144 {}
145
146 explicit IOException(const char* what)
147 : peak::common::Exception(what)
148 , peak::ipl::Exception(what)
149 , peak::common::IOException(what)
150 {}
151
153 : peak::common::Exception(other)
154 , peak::ipl::Exception(other)
155 , peak::common::IOException(other)
156 {}
157};
158
163{
164 using Exception::Exception;
165};
166
171{
172 using Exception::Exception;
173};
174
178class TimeoutException : public Exception, public peak::common::TimeoutException
179{
180public:
181 explicit TimeoutException(const std::string& what)
182 : peak::common::Exception(what)
183 , peak::ipl::Exception(what)
184 , peak::common::TimeoutException(what)
185 {}
186
187 explicit TimeoutException(const char* what)
188 : peak::common::Exception(what)
189 , peak::ipl::Exception(what)
190 , peak::common::TimeoutException(what)
191 {}
192
194 : peak::common::Exception(other)
195 , peak::ipl::Exception(other)
196 , peak::common::TimeoutException(other)
197 {}
198};
199
204{
205 using Exception::Exception;
206};
207
209{
210 std::string entryString;
211
212 switch(entry)
213 {
215 entryString = "PEAK_IPL_RETURN_CODE_SUCCESS";
216 break;
217
219 entryString = "PEAK_IPL_RETURN_CODE_ERROR";
220 break;
221
223 entryString = "PEAK_IPL_RETURN_CODE_BUFFER_TOO_SMALL";
224 break;
225
227 entryString = "PEAK_IPL_RETURN_CODE_INVALID_ARGUMENT";
228 break;
229
231 entryString = "PEAK_IPL_RETURN_CODE_INVALID_HANDLE";
232 break;
233
235 entryString = "PEAK_IPL_RETURN_CODE_OUT_OF_RANGE";
236 break;
237
239 entryString = "PEAK_IPL_RETURN_CODE_IMAGE_FORMAT_NOT_SUPPORTED";
240 break;
241
243 entryString = "PEAK_IPL_RETURN_CODE_IO_ERROR";
244 break;
245
247 entryString = "PEAK_IPL_RETURN_CODE_BUSY";
248 break;
249
251 entryString = "PEAK_IPL_RETURN_CODE_TIMEOUT";
252 break;
253
255 entryString = "PEAK_IPL_RETURN_CODE_FORMAT_INTERPRETATION_ERROR";
256 break;
257
259 entryString = "PEAK_IPL_RETURN_CODE_NOT_SUPPORTED";
260 break;
261
263 entryString = "PEAK_IPL_RETURN_CODE_NOT_PERMITTED";
264 break;
265 }
266
267 return entryString;
268}
269
270template <class CallableType>
271void ExecuteAndMapReturnCodes(const CallableType& callableObject)
272{
273 if (callableObject() != PEAK_IPL_RETURN_CODE_SUCCESS)
274 {
276 size_t lastErrorDescriptionSize = 0;
277 if (PEAK_IPL_C_ABI_PREFIX PEAK_IPL_Library_GetLastError(&lastErrorCode, nullptr, &lastErrorDescriptionSize)
279 {
280 throw Exception("Could not query the last error!");
281 }
282 std::vector<char> lastErrorDescription(lastErrorDescriptionSize);
284 &lastErrorCode, lastErrorDescription.data(), &lastErrorDescriptionSize)
286 {
287 throw Exception("Could not query the last error!");
288 }
289
290 std::stringstream errorText;
291 errorText << "[Error-Code: " << lastErrorCode << " ("
292 << StringFromPEAK_IPL_RETURN_CODE(static_cast<PEAK_IPL_RETURN_CODE_t>(lastErrorCode))
293 << ") | Error-Description: " << lastErrorDescription.data() << "]";
294
295 switch (lastErrorCode)
296 {
298 throw OutOfRangeException(errorText.str().c_str());
300 throw InvalidArgumentException(errorText.str().c_str());
302 throw ImageFormatNotSupportedException(errorText.str().c_str());
304 throw ImageFormatInterpretationException(errorText.str().c_str());
306 throw IOException(errorText.str().c_str());
308 throw BufferTooSmallException(errorText.str().c_str());
310 throw NotPermittedException(errorText.str().c_str());
312 throw BusyException(errorText.str().c_str());
314 throw InvalidHandleException(errorText.str().c_str());
316 throw TimeoutException(errorText.str().c_str());
317 default:
318 throw Exception(errorText.str().c_str());
319 }
320 }
321}
322
323} /* namespace ipl */
324} /* namespace peak */
The exception thrown when a given buffer is too small for the data.
Definition peak_ipl_exception.hpp:72
The exception thrown when the resource busy.
Definition peak_ipl_exception.hpp:163
The base class for all exceptions thrown by the library.
Definition peak_ipl_exception.hpp:39
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:138
IOException(const std::string &what)
Definition peak_ipl_exception.hpp:140
IOException(const char *what)
Definition peak_ipl_exception.hpp:146
IOException(const IOException &other)
Definition peak_ipl_exception.hpp:152
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:130
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:80
InvalidArgumentException(const std::string &what)
Definition peak_ipl_exception.hpp:82
InvalidArgumentException(const char *what)
Definition peak_ipl_exception.hpp:88
InvalidArgumentException(const InvalidArgumentException &other)
Definition peak_ipl_exception.hpp:94
The exception thrown when passing an invalid handle to a function.
Definition peak_ipl_exception.hpp:204
The exception thrown when the operation not permitted.
Definition peak_ipl_exception.hpp:171
The exception thrown for trying to access a value being out of range.
Definition peak_ipl_exception.hpp:47
OutOfRangeException(const char *what)
Definition peak_ipl_exception.hpp:55
OutOfRangeException(const OutOfRangeException &other)
Definition peak_ipl_exception.hpp:61
OutOfRangeException(const std::string &what)
Definition peak_ipl_exception.hpp:49
The exception thrown when the operation times out.
Definition peak_ipl_exception.hpp:179
TimeoutException(const TimeoutException &other)
Definition peak_ipl_exception.hpp:193
TimeoutException(const char *what)
Definition peak_ipl_exception.hpp:187
TimeoutException(const std::string &what)
Definition peak_ipl_exception.hpp:181
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:208
void ExecuteAndMapReturnCodes(const CallableType &callableObject)
Definition peak_ipl_exception.hpp:271
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