/src/bag/api/bag_exceptions.h
Line | Count | Source (jump to first uncovered line) |
1 | | #ifndef BAG_EXCEPTIONS_H |
2 | | #define BAG_EXCEPTIONS_H |
3 | | |
4 | | #include "bag_config.h" |
5 | | #include "bag_errors.h" |
6 | | #include "bag_types.h" |
7 | | |
8 | | #include <exception> |
9 | | #include <sstream> |
10 | | |
11 | | |
12 | | namespace BAG { |
13 | | |
14 | | #ifdef _MSC_VER |
15 | | #pragma warning(push) |
16 | | #pragma warning(disable: 4275) |
17 | | #pragma warning(disable: 4251) // class 'std::basic_string<char,std::char_traits<char>,std::allocator<char>>' needs to have dll-interface to be used by clients of struct 'BAG::UknownMetadataProfile' |
18 | | #endif |
19 | | |
20 | | // General |
21 | | //! Compression was requested, but no chunking was specified. |
22 | | struct BAG_API CompressionNeedsChunkingSet final : virtual std::exception |
23 | | { |
24 | | const char* what() const noexcept override |
25 | 0 | { |
26 | 0 | return "If compression is desired, a chunk positive chunk size must be set."; |
27 | 0 | } |
28 | | }; |
29 | | |
30 | | // Attribute related. |
31 | | //! Attribute type not supported (yet) |
32 | | struct BAG_API UnsupportedAttributeType final : virtual std::exception |
33 | | { |
34 | | const char* what() const noexcept override |
35 | 0 | { |
36 | 0 | return "The H5 type of this attribute is not float. Not supported (yet)."; |
37 | 0 | } |
38 | | }; |
39 | | |
40 | | |
41 | | // CompoundDataType related. |
42 | | //! Layer not found. |
43 | | struct BAG_API InvalidType final : virtual std::exception |
44 | | { |
45 | | const char* what() const noexcept override |
46 | 0 | { |
47 | 0 | return "The type specified does not match what is stored."; |
48 | 0 | } |
49 | | }; |
50 | | |
51 | | //! Invalid descriptor found. |
52 | | struct BAG_API InvalidDescriptor final : virtual std::exception |
53 | | { |
54 | | const char* what() const noexcept override |
55 | 0 | { |
56 | 0 | return "The descriptor is not a CompoundDataDescriptor."; |
57 | 0 | } |
58 | | }; |
59 | | |
60 | | //! Invalid key type specified. |
61 | | struct BAG_API InvalidKeyType final : virtual std::exception |
62 | | { |
63 | | const char* what() const noexcept override |
64 | 0 | { |
65 | 0 | return "The type specified for the key type is not valid."; |
66 | 0 | } |
67 | | }; |
68 | | |
69 | | //! A name is required to find a unique georeferenced metadata layer. |
70 | | struct BAG_API NameRequired final : virtual std::exception |
71 | | { |
72 | | const char* what() const noexcept override |
73 | 0 | { |
74 | 0 | return "A name is required to find a unique georeferenced metadata layer."; |
75 | 0 | } |
76 | | }; |
77 | | |
78 | | |
79 | | // Dataset related. |
80 | | //! Layer not found. |
81 | | struct BAG_API DatasetNotFound final : virtual std::exception |
82 | | { |
83 | | const char* what() const noexcept override |
84 | 0 | { |
85 | 0 | return "There is no dataset to work with."; |
86 | 0 | } |
87 | | }; |
88 | | |
89 | | //! Invalid layer id. |
90 | | struct BAG_API InvalidLayerId final : virtual std::exception |
91 | | { |
92 | | const char* what() const noexcept override |
93 | 0 | { |
94 | 0 | return "Invalid layer id specified."; |
95 | 0 | } |
96 | | }; |
97 | | |
98 | | |
99 | | // Group related. |
100 | | //! Attempt to use an unknown layer type. |
101 | | struct BAG_API UnsupportedGroupType final : virtual std::exception |
102 | | { |
103 | | const char* what() const noexcept override |
104 | 0 | { |
105 | 0 | return "An unsupported group type was specified."; |
106 | 0 | } |
107 | | }; |
108 | | |
109 | | |
110 | | // Layer related. |
111 | | //! Invalid buffer provided for the write. |
112 | | struct BAG_API InvalidBuffer final : virtual std::exception |
113 | | { |
114 | | const char* what() const noexcept override |
115 | 0 | { |
116 | 0 | return "The specified buffer is NULL."; |
117 | 0 | } |
118 | | }; |
119 | | |
120 | | //! Invalid dimensions specified for the read. |
121 | | struct BAG_API InvalidReadSize final : virtual std::exception |
122 | | { |
123 | | const char* what() const noexcept override |
124 | 0 | { |
125 | 0 | return "The dimensions specified for reading are not valid."; |
126 | 0 | } |
127 | | }; |
128 | | |
129 | | //! Invalid dimensions specified for the write. |
130 | | struct BAG_API InvalidWriteSize final : virtual std::exception |
131 | | { |
132 | | const char* what() const noexcept override |
133 | 0 | { |
134 | 0 | return "The dimensions specified for writing are not valid."; |
135 | 0 | } |
136 | | }; |
137 | | |
138 | | //! Layer already exists. |
139 | | struct BAG_API LayerExists final : virtual std::exception |
140 | | { |
141 | | const char* what() const noexcept override |
142 | 0 | { |
143 | 0 | return "The specified layer already exists."; |
144 | 0 | } |
145 | | }; |
146 | | |
147 | | //! Layer not found. |
148 | | struct BAG_API LayerNotFound final : virtual std::exception |
149 | | { |
150 | | const char* what() const noexcept override |
151 | 0 | { |
152 | 0 | return "The specified layer was not found."; |
153 | 0 | } |
154 | | }; |
155 | | |
156 | | //! Attempted to modify a read only Dataset. |
157 | | struct BAG_API ReadOnlyError final : virtual std::exception |
158 | | { |
159 | | const char* what() const noexcept override |
160 | 0 | { |
161 | 0 | return "Attempted to modify a read only Dataset."; |
162 | 0 | } |
163 | | }; |
164 | | |
165 | | //! Attempt to use get the element size of an unsupported layer type. |
166 | | struct BAG_API UnsupportedElementSize final : virtual std::exception |
167 | | { |
168 | | const char* what() const noexcept override |
169 | 0 | { |
170 | 0 | return "Element size not supported for this type of layer."; |
171 | 0 | } |
172 | | }; |
173 | | |
174 | | //! Attempt to use an unknown layer type. |
175 | | struct BAG_API UnsupportedLayerType final : virtual std::exception |
176 | | { |
177 | | const char* what() const noexcept override |
178 | 0 | { |
179 | 0 | return "An unsupported layer type was specified."; |
180 | 0 | } |
181 | | }; |
182 | | |
183 | | //! Attempt to use an incorrect layer type. |
184 | | struct BAG_API UnsupportedSimpleLayerType final : virtual std::exception |
185 | | { |
186 | | const char* what() const noexcept override |
187 | 0 | { |
188 | 0 | return "Attempted to specify an unsupported combination of group and " |
189 | 0 | "layer type when making an interleaved layer."; |
190 | 0 | } |
191 | | }; |
192 | | |
193 | | //! Attempt to make an unsupported interleaved layer. |
194 | | struct BAG_API UnsupportedInterleavedLayer final : virtual std::exception |
195 | | { |
196 | | const char* what() const noexcept override |
197 | 0 | { |
198 | 0 | return "Attempted to specify an unsupported combination of group and " |
199 | 0 | "layer type when making an interleaved layer."; |
200 | 0 | } |
201 | | }; |
202 | | |
203 | | |
204 | | // LayerDescriptor related. |
205 | | //! The layer descriptor is not valid. |
206 | | struct BAG_API InvalidLayerDescriptor final : virtual std::exception |
207 | | { |
208 | | const char* what() const noexcept override |
209 | 0 | { |
210 | 0 | return "The specified layer descriptor is not valid."; |
211 | 0 | } |
212 | | }; |
213 | | |
214 | | |
215 | | // LayerItems related. |
216 | | //! The type cannot be cast to the specified type. |
217 | | struct BAG_API InvalidCast final : virtual std::exception |
218 | | { |
219 | | const char* what() const noexcept override |
220 | 0 | { |
221 | 0 | return "The LayerItems cannot be cast to the specified type."; |
222 | 0 | } |
223 | | }; |
224 | | |
225 | | |
226 | | //! Legacy CRS related. |
227 | | //! Ran into a problem (internal). |
228 | | struct CoordSysError : virtual std::exception |
229 | | { |
230 | | const char* what() const noexcept override |
231 | 0 | { |
232 | 0 | return "Conversion Error"; |
233 | 0 | }; |
234 | | }; |
235 | | |
236 | | //! Can not convert the datum. |
237 | | struct InvalidDatumError final : virtual CoordSysError {}; |
238 | | |
239 | | //! Can not convert the ellipsoid. |
240 | | struct InvalidEllipsoidError final : virtual CoordSysError {}; |
241 | | |
242 | | |
243 | | // Metadata related. |
244 | | //! Attempt to make an unsupported interleaved layer. |
245 | | struct BAG_API MetadataNotFound final : virtual std::exception |
246 | | { |
247 | | const char* what() const noexcept override |
248 | 0 | { |
249 | 0 | return "The mandatory Metadata dataset was not found."; |
250 | 0 | } |
251 | | }; |
252 | | |
253 | | //! An unknown metadata profile was specified when a known profile was expected. |
254 | | struct BAG_API UknownMetadataProfile final : virtual std::exception |
255 | | { |
256 | | UknownMetadataProfile(std::string profile) |
257 | 0 | { |
258 | 0 | m_message = "Metadata profile '" + profile + |
259 | 0 | "' is unknown, but a known profile was expected."; |
260 | 0 | } Unexecuted instantiation: BAG::UknownMetadataProfile::UknownMetadataProfile(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >) Unexecuted instantiation: BAG::UknownMetadataProfile::UknownMetadataProfile(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >) |
261 | | |
262 | | const char* what() const noexcept override |
263 | 0 | { |
264 | 0 | return m_message.c_str(); |
265 | 0 | } |
266 | | |
267 | | std::string m_message; |
268 | | }; |
269 | | |
270 | | //! An unrecognized metadata profile was specified. |
271 | | struct BAG_API UnrecognizedMetadataProfile final : virtual std::exception |
272 | | { |
273 | | UnrecognizedMetadataProfile(std::string profile) |
274 | 0 | { |
275 | 0 | m_message = "Metadata profile '" + profile + |
276 | 0 | "' is not recognized."; |
277 | 0 | } |
278 | | |
279 | | const char* what() const noexcept override |
280 | 0 | { |
281 | 0 | return m_message.c_str(); |
282 | 0 | } |
283 | | |
284 | | std::string m_message; |
285 | | }; |
286 | | |
287 | | //! An error occurred loading metadata. |
288 | | struct BAG_API ErrorLoadingMetadata final : virtual std::exception |
289 | | { |
290 | 0 | ErrorLoadingMetadata(BagError bagError) : m_error(bagError) |
291 | 0 | { |
292 | 0 | m_message = "While importing metadata as XML, an error value " + |
293 | 0 | std::to_string(m_error) + " was returned."; |
294 | 0 | } |
295 | | |
296 | | const char* what() const noexcept override |
297 | 0 | { |
298 | 0 | return m_message.c_str(); |
299 | 0 | } |
300 | | |
301 | | // TODO: Shouldn't this be non-zero? |
302 | | BagError m_error = BAG_SUCCESS; |
303 | | std::string m_message; |
304 | | }; |
305 | | |
306 | | |
307 | | // SimpleLayer related. |
308 | | //! Cannot convert DataType to an HDF5 DataType. |
309 | | struct BAG_API UnsupportedDataType final : virtual std::exception |
310 | | { |
311 | | const char* what() const noexcept override |
312 | 0 | { |
313 | 0 | return "The specified DataType cannot be converted to an HDF5 DataType."; |
314 | 0 | } |
315 | | }; |
316 | | |
317 | | |
318 | | // SurfaceCorrections related. |
319 | | //! Too many corrections specified. |
320 | | struct BAG_API TooManyCorrections final : virtual std::exception |
321 | | { |
322 | | const char* what() const noexcept override |
323 | 0 | { |
324 | 0 | return "Too many corrections specified. The limit is 10."; |
325 | 0 | } |
326 | | }; |
327 | | |
328 | | //! Attempt to use an unknown surface type. |
329 | | struct BAG_API UnknownSurfaceType final : virtual std::exception |
330 | | { |
331 | | const char* what() const noexcept override |
332 | 0 | { |
333 | 0 | return "Unknown surface type specified."; |
334 | 0 | } |
335 | | }; |
336 | | |
337 | | //! Unknown reason why number of corrections could not be read from the BAG. |
338 | | struct BAG_API CannotReadNumCorrections final : virtual std::exception |
339 | | { |
340 | | const char* what() const noexcept override |
341 | 0 | { |
342 | 0 | return "Cannot read the number of corrections from the surface " |
343 | 0 | "corrections dataset."; |
344 | 0 | } |
345 | | }; |
346 | | |
347 | | //! Invalid corrector specified (1-10). |
348 | | struct BAG_API InvalidCorrector final : virtual std::exception |
349 | | { |
350 | | const char* what() const noexcept override |
351 | 0 | { |
352 | 0 | return "Invalid corrector specified. The range is 1-10, but a Surface " |
353 | 0 | "Corrections layer may contain less."; |
354 | 0 | } |
355 | | }; |
356 | | |
357 | | //! The surface type is not supported for this operation. |
358 | | struct BAG_API UnsupportedSurfaceType final : virtual std::exception |
359 | | { |
360 | | const char* what() const noexcept override |
361 | 0 | { |
362 | 0 | return "The type of Surface Correction layer (gridded or sparse) is not" |
363 | 0 | " support for this operation."; |
364 | 0 | } |
365 | | }; |
366 | | |
367 | | |
368 | | // Value Table related. |
369 | | //! The specified field does not exist. |
370 | | struct BAG_API FieldNotFound final : virtual std::exception |
371 | | { |
372 | | const char* what() const noexcept override |
373 | 0 | { |
374 | 0 | return "The specified field does not exist."; |
375 | 0 | } |
376 | | }; |
377 | | |
378 | | //! Attempt to use an invalid value. |
379 | | struct BAG_API InvalidValue final : virtual std::exception |
380 | | { |
381 | | const char* what() const noexcept override |
382 | 0 | { |
383 | 0 | return "Invalid value encountered. Either an unknown type is present " |
384 | 0 | "or it does not match the definition"; |
385 | 0 | } |
386 | | }; |
387 | | |
388 | | //! The dimensions of the values in the GeorefMetadataLayer are invalid. |
389 | | struct BAG_API InvalidValueSize final : virtual std::exception |
390 | | { |
391 | | const char* what() const noexcept override |
392 | 0 | { |
393 | 0 | return "Invalid dimensions of the values in the spatial data has been " |
394 | 0 | "encountered."; |
395 | 0 | } |
396 | | }; |
397 | | |
398 | | //! Layer requires chunking set because it is dynamically sized. |
399 | | struct BAG_API LayerRequiresChunkingSet final : virtual std::exception |
400 | | { |
401 | | const char* what() const noexcept override |
402 | 0 | { |
403 | 0 | return "This layer requires a chunk size because it is dynamically " |
404 | 0 | "sized."; |
405 | 0 | } |
406 | | }; |
407 | | |
408 | | //! The dataset must use variable resolution to read or write variable resolution metadata using the GeorefMetadataLayer. |
409 | | struct BAG_API DatasetRequiresVariableResolution final : virtual std::exception |
410 | | { |
411 | | const char* what() const noexcept override |
412 | 0 | { |
413 | 0 | return "The dataset must use variable resolution to read or write " |
414 | 0 | "variable resolution metadata using the GeorefMetadataLayer."; |
415 | 0 | } |
416 | | }; |
417 | | |
418 | | //! Attempt to write a value to an invalid key. |
419 | | struct BAG_API InvalidValueKey final : virtual std::exception |
420 | | { |
421 | | const char* what() const noexcept override |
422 | 0 | { |
423 | 0 | return "Invalid key specified while writing a spatial metadata value."; |
424 | 0 | } |
425 | | }; |
426 | | |
427 | | //! Attempt to use an invalid key. |
428 | | struct BAG_API ValueNotFound final : virtual std::exception |
429 | | { |
430 | | const char* what() const noexcept override |
431 | 0 | { |
432 | 0 | return "Invalid key specified. The key must be greater " |
433 | 0 | "than 0, and less than the number of existing values."; |
434 | 0 | } |
435 | | }; |
436 | | |
437 | | |
438 | | // VRRefinement related. |
439 | | //! VR Refinements are the wrong dimensions. |
440 | | struct BAG_API InvalidVRRefinementDimensions final : virtual std::exception |
441 | | { |
442 | | const char* what() const noexcept override |
443 | 0 | { |
444 | 0 | return "The variable resolution refinement layer is not 1 dimensional."; |
445 | 0 | } |
446 | | }; |
447 | | |
448 | | #ifdef _MSC_VER |
449 | | #pragma warning(pop) |
450 | | #endif |
451 | | |
452 | | } // namespace BAG |
453 | | |
454 | | #endif // BAG_EXCEPTIONS_H |
455 | | |