ACloudViewer  3.9.4
A Modern Library for 3D Data Processing
E57Exception.cpp
Go to the documentation of this file.
1 /*
2  * Original work Copyright 2009 - 2010 Kevin Ackley (kackley@gwi.net)
3  * Modified work Copyright 2018 - 2020 Andy Maloney <asmaloney@gmail.com>
4  *
5  * Permission is hereby granted, free of charge, to any person or organization
6  * obtaining a copy of the software and accompanying documentation covered by
7  * this license (the "Software") to use, reproduce, display, distribute,
8  * execute, and transmit the Software, and to prepare derivative works of the
9  * Software, and to permit third-parties to whom the Software is furnished to
10  * do so, all subject to the following:
11  *
12  * The copyright notices in the Software and this entire statement, including
13  * the above license grant, this restriction and the following disclaimer,
14  * must be included in all copies of the Software, in whole or in part, and
15  * all derivative works of the Software, unless such copies or derivative
16  * works are solely in the form of machine-executable object code generated by
17  * a source language processor.
18  *
19  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21  * FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
22  * SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
23  * FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
24  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
25  * DEALINGS IN THE SOFTWARE.
26  */
27 
28 #include "E57Exception.h"
29 #include "E57Version.h"
30 
31 namespace e57
32 {
111  E57Exception::E57Exception( ErrorCode ecode, const std::string &context, const std::string &srcFileName,
112  int srcLineNumber, const char *srcFunctionName ) :
113  errorCode_( ecode ), context_( context ), sourceFunctionName_( srcFunctionName ),
114  sourceLineNumber_( srcLineNumber )
115  {
116  sourceFileName_ = srcFileName.substr( srcFileName.find_last_of( "/\\" ) + 1 );
117  }
119 
137  void E57Exception::report( const char *reportingFileName, int reportingLineNumber, const char *reportingFunctionName,
138  std::ostream &os ) const
139  {
140  os << "**** Got an e57 exception: " << e57::Utilities::errorCodeToString( errorCode() ) << std::endl;
141 
142 #ifdef E57_DEBUG
143  os << " Debug info: " << std::endl;
144  os << " context: " << context_ << std::endl;
145  os << " sourceFunctionName: " << sourceFunctionName_ << std::endl;
146  if ( reportingFunctionName != nullptr )
147  os << " reportingFunctionName: " << reportingFunctionName << std::endl;
148 
149  /*** Add a line in error message that a smart editor (gnu emacs) can
150  * interpret as a link to the source code: */
151  os << sourceFileName_ << "(" << sourceLineNumber_ << ") : error C" << errorCode_ << ": <--- occurred on"
152  << std::endl;
153  if ( reportingFileName != nullptr )
154  os << reportingFileName << "(" << reportingLineNumber << ") : error C0: <--- reported on" << std::endl;
155 #endif
156  }
157 
166  ErrorCode E57Exception::errorCode() const
167  {
168  return errorCode_;
169  }
170 
183  std::string E57Exception::context() const
184  {
185  return context_;
186  }
187 
197  const char *E57Exception::what() const noexcept
198  {
199  return "E57 exception";
200  }
201 
213  const char *E57Exception::sourceFileName() const
214  {
215  return sourceFileName_.c_str();
216  }
217 
230  const char *E57Exception::sourceFunctionName() const
231  {
232  return sourceFunctionName_;
233  }
234 
247  int E57Exception::sourceLineNumber() const
248  {
249  return sourceLineNumber_;
250  }
251 
252  //=====================================================================================
253 
269  void Utilities::getVersions( int &astmMajor, int &astmMinor, std::string &libraryId )
270  {
272 
273 #ifndef REVISION_ID
274 #error "Need to specify REVISION_ID on command line"
275 #endif
276 
277  astmMajor = E57_FORMAT_MAJOR;
278  astmMinor = E57_FORMAT_MINOR;
279  libraryId = REVISION_ID;
280  }
281 
292  {
293  switch ( ecode )
294  {
295  // N.B. *** When changing error strings here, remember to update the
296  // Doxygen strings in E57Exception.h ****
297  case E57_SUCCESS:
298  return "operation was successful (E57_SUCCESS)";
300  return "a CompressedVector binary header was bad "
301  "(E57_ERROR_BAD_CV_HEADER)";
303  return "a CompressedVector binary packet was bad "
304  "(E57_ERROR_BAD_CV_PACKET)";
306  return "a numerical index identifying a child was out of bounds "
307  "(E57_ERROR_CHILD_INDEX_OUT_OF_BOUNDS)";
308  case E57_ERROR_SET_TWICE:
309  return "attempted to set an existing child element to a new value "
310  "(E57_ERROR_SET_TWICE)";
312  return "attempted to add an E57 Element that would have made the "
313  "children of a "
314  "homogenous Vector have different types "
315  "(E57_ERROR_HOMOGENEOUS_VIOLATION)";
317  return "a value could not be represented in the requested type "
318  "(E57_ERROR_VALUE_NOT_REPRESENTABLE)";
320  return "after scaling the result could not be represented in the "
321  "requested type "
322  "(E57_ERROR_SCALED_VALUE_NOT_REPRESENTABLE)";
324  return "a 64 bit IEEE float was too large to store in a 32 bit IEEE "
325  "float "
326  "(E57_ERROR_REAL64_TOO_LARGE)";
328  return "Expecting numeric representation in user's buffer, found "
329  "ustring "
330  "(E57_ERROR_EXPECTING_NUMERIC)";
332  return "Expecting string representation in user's buffer, found "
333  "numeric "
334  "(E57_ERROR_EXPECTING_USTRING)";
335  case E57_ERROR_INTERNAL:
336  return "An unrecoverable inconsistent internal state was detected "
337  "(E57_ERROR_INTERNAL)";
339  return "E57 primitive not encoded in XML correctly "
340  "(E57_ERROR_BAD_XML_FORMAT)";
342  return "XML not well formed (E57_ERROR_XML_PARSER)";
344  return "bad API function argument provided by user "
345  "(E57_ERROR_BAD_API_ARGUMENT)";
347  return "can't modify read only file (E57_ERROR_FILE_IS_READ_ONLY)";
349  return "checksum mismatch, file is corrupted (E57_ERROR_BAD_CHECKSUM)";
351  return "open() failed (E57_ERROR_OPEN_FAILED)";
353  return "close() failed (E57_ERROR_CLOSE_FAILED)";
355  return "read() failed (E57_ERROR_READ_FAILED)";
357  return "write() failed (E57_ERROR_WRITE_FAILED)";
359  return "lseek() failed (E57_ERROR_LSEEK_FAILED)";
361  return "E57 element path well formed but not defined "
362  "(E57_ERROR_PATH_UNDEFINED)";
364  return "bad SourceDestBuffer (E57_ERROR_BAD_BUFFER)";
366  return "no buffer specified for an element in CompressedVectorNode "
367  "during write "
368  "(E57_ERROR_NO_BUFFER_FOR_ELEMENT)";
370  return "SourceDestBuffers not all same size "
371  "(E57_ERROR_BUFFER_SIZE_MISMATCH)";
373  return "duplicate pathname in CompressedVectorNode read/write "
374  "(E57_ERROR_BUFFER_DUPLICATE_PATHNAME)";
376  return "file signature not "
377  "ASTM-E57"
378  " (E57_ERROR_BAD_FILE_SIGNATURE)";
380  return "incompatible file version (E57_ERROR_UNKNOWN_FILE_VERSION)";
382  return "size in file header not same as actual "
383  "(E57_ERROR_BAD_FILE_LENGTH)";
385  return "XML parser failed to initialize (E57_ERROR_XML_PARSER_INIT)";
387  return "namespace prefix already defined "
388  "(E57_ERROR_DUPLICATE_NAMESPACE_PREFIX)";
390  return "namespace URI already defined "
391  "(E57_ERROR_DUPLICATE_NAMESPACE_URI)";
393  return "bad prototype in CompressedVectorNode "
394  "(E57_ERROR_BAD_PROTOTYPE)";
396  return "bad codecs in CompressedVectorNode (E57_ERROR_BAD_CODECS)";
398  return "element value out of min/max bounds "
399  "(E57_ERROR_VALUE_OUT_OF_BOUNDS)";
401  return "conversion required to assign element value, but not "
402  "requested "
403  "(E57_ERROR_CONVERSION_REQUIRED)";
405  return "E57 path name is not well formed (E57_ERROR_BAD_PATH_NAME)";
407  return "functionality not implemented (E57_ERROR_NOT_IMPLEMENTED)";
409  return "bad downcast from Node to specific node type "
410  "(E57_ERROR_BAD_NODE_DOWNCAST)";
412  return "CompressedVectorWriter is no longer open "
413  "(E57_ERROR_WRITER_NOT_OPEN)";
415  return "CompressedVectorReader is no longer open "
416  "(E57_ERROR_READER_NOT_OPEN)";
418  return "node is not yet attached to tree of ImageFile "
419  "(E57_ERROR_NODE_UNATTACHED)";
421  return "node already has a parent (E57_ERROR_ALREADY_HAS_PARENT)";
423  return "nodes were constructed with different destImageFiles "
424  "(E57_ERROR_DIFFERENT_DEST_IMAGEFILE)";
426  return "destImageFile is no longer open "
427  "(E57_ERROR_IMAGEFILE_NOT_OPEN)";
429  return "SourceDestBuffers not compatible with previously given ones "
430  "(E57_ERROR_BUFFERS_NOT_COMPATIBLE)";
432  return "too many open CompressedVectorWriters of an ImageFile "
433  "(E57_ERROR_TOO_MANY_WRITERS)";
435  return "too many open CompressedVectorReaders of an ImageFile "
436  "(E57_ERROR_TOO_MANY_READERS)";
438  return "bad configuration string (E57_ERROR_BAD_CONFIGURATION)";
440  return "class invariance constraint violation in debug mode "
441  "(E57_ERROR_INVARIANCE_VIOLATION)";
442  default:
443  return "unknown error (" + std::to_string( ecode ) + ")";
444  }
445  }
446 
447 }
ImGuiContext * context
Definition: Window.cpp:76
QTextStream & endl(QTextStream &stream)
Definition: QtCompat.h:718
E57_DLL std::string errorCodeToString(ErrorCode ecode)
Get short string description of an E57 ErrorCode.
E57_DLL void getVersions(int &astmMajor, int &astmMinor, std::string &libraryId)
Get the version of ASTM E57 standard that the API implementation supports, and library id string.
constexpr uint32_t E57_FORMAT_MAJOR
Version numbers of ASTM standard that this library supports.
Definition: E57Version.h:10
ErrorCode
Numeric error identifiers used in E57Exception.
Definition: E57Exception.h:40
@ E57_ERROR_FILE_IS_READ_ONLY
can't modify read only file
Definition: E57Exception.h:60
@ E57_ERROR_TOO_MANY_READERS
too many open CompressedVectorReaders of an ImageFile
Definition: E57Exception.h:94
@ E57_ERROR_BUFFERS_NOT_COMPATIBLE
SourceDestBuffers not compatible with previously given ones.
Definition: E57Exception.h:92
@ E57_SUCCESS
operation was successful
Definition: E57Exception.h:43
@ E57_ERROR_CONVERSION_REQUIRED
conversion required to assign element value, but not requested
Definition: E57Exception.h:82
@ E57_ERROR_BUFFER_DUPLICATE_PATHNAME
duplicate pathname in CompressedVectorNode read/write
Definition: E57Exception.h:72
@ E57_ERROR_READ_FAILED
read() failed
Definition: E57Exception.h:64
@ E57_ERROR_INTERNAL
An unrecoverable inconsistent internal state was detected.
Definition: E57Exception.h:56
@ E57_ERROR_VALUE_OUT_OF_BOUNDS
element value out of min/max bounds
Definition: E57Exception.h:81
@ E57_ERROR_OPEN_FAILED
open() failed
Definition: E57Exception.h:62
@ E57_ERROR_BAD_NODE_DOWNCAST
bad downcast from Node to specific node type
Definition: E57Exception.h:85
@ E57_ERROR_SET_TWICE
attempted to set an existing child element to a new value
Definition: E57Exception.h:47
@ E57_ERROR_BAD_API_ARGUMENT
bad API function argument provided by user
Definition: E57Exception.h:59
@ E57_ERROR_BAD_FILE_SIGNATURE
file signature not "ASTM-E57"
Definition: E57Exception.h:73
@ E57_ERROR_WRITE_FAILED
write() failed
Definition: E57Exception.h:65
@ E57_ERROR_HOMOGENEOUS_VIOLATION
Definition: E57Exception.h:48
@ E57_ERROR_NO_BUFFER_FOR_ELEMENT
Definition: E57Exception.h:69
@ E57_ERROR_NODE_UNATTACHED
node is not yet attached to tree of ImageFile
Definition: E57Exception.h:88
@ E57_ERROR_BAD_PROTOTYPE
bad prototype in CompressedVectorNode
Definition: E57Exception.h:79
@ E57_ERROR_REAL64_TOO_LARGE
a 64 bit IEEE float was too large to store in a 32 bit IEEE float
Definition: E57Exception.h:53
@ E57_ERROR_XML_PARSER_INIT
XML parser failed to initialize.
Definition: E57Exception.h:76
@ E57_ERROR_BAD_CV_PACKET
a CompressedVector binary packet was bad
Definition: E57Exception.h:45
@ E57_ERROR_BAD_CHECKSUM
checksum mismatch, file is corrupted
Definition: E57Exception.h:61
@ E57_ERROR_CHILD_INDEX_OUT_OF_BOUNDS
a numerical index identifying a child was out of bounds
Definition: E57Exception.h:46
@ E57_ERROR_IMAGEFILE_NOT_OPEN
destImageFile is no longer open
Definition: E57Exception.h:91
@ E57_ERROR_BAD_XML_FORMAT
E57 primitive not encoded in XML correctly.
Definition: E57Exception.h:57
@ E57_ERROR_NOT_IMPLEMENTED
functionality not implemented
Definition: E57Exception.h:84
@ E57_ERROR_XML_PARSER
XML not well formed.
Definition: E57Exception.h:58
@ E57_ERROR_EXPECTING_NUMERIC
Expecting numeric representation in user's buffer, found ustring.
Definition: E57Exception.h:54
@ E57_ERROR_BUFFER_SIZE_MISMATCH
SourceDestBuffers not all same size.
Definition: E57Exception.h:71
@ E57_ERROR_BAD_CODECS
bad codecs in CompressedVectorNode
Definition: E57Exception.h:80
@ E57_ERROR_TOO_MANY_WRITERS
too many open CompressedVectorWriters of an ImageFile
Definition: E57Exception.h:93
@ E57_ERROR_BAD_FILE_LENGTH
size in file header not same as actual
Definition: E57Exception.h:75
@ E57_ERROR_ALREADY_HAS_PARENT
node already has a parent
Definition: E57Exception.h:89
@ E57_ERROR_UNKNOWN_FILE_VERSION
incompatible file version
Definition: E57Exception.h:74
@ E57_ERROR_INVARIANCE_VIOLATION
class invariance constraint violation in debug mode
Definition: E57Exception.h:96
@ E57_ERROR_READER_NOT_OPEN
CompressedVectorReader is no longer open.
Definition: E57Exception.h:87
@ E57_ERROR_VALUE_NOT_REPRESENTABLE
a value could not be represented in the requested type
Definition: E57Exception.h:50
@ E57_ERROR_BAD_CV_HEADER
a CompressedVector binary header was bad
Definition: E57Exception.h:44
@ E57_ERROR_CLOSE_FAILED
close() failed
Definition: E57Exception.h:63
@ E57_ERROR_BAD_CONFIGURATION
bad configuration string
Definition: E57Exception.h:95
@ E57_ERROR_DIFFERENT_DEST_IMAGEFILE
nodes were constructed with different destImageFiles
Definition: E57Exception.h:90
@ E57_ERROR_WRITER_NOT_OPEN
CompressedVectorWriter is no longer open.
Definition: E57Exception.h:86
@ E57_ERROR_SCALED_VALUE_NOT_REPRESENTABLE
Definition: E57Exception.h:51
@ E57_ERROR_BAD_BUFFER
bad SourceDestBuffer
Definition: E57Exception.h:68
@ E57_ERROR_BAD_PATH_NAME
E57 path name is not well formed.
Definition: E57Exception.h:83
@ E57_ERROR_EXPECTING_USTRING
Expecting string representation in user's buffer, found numeric.
Definition: E57Exception.h:55
@ E57_ERROR_DUPLICATE_NAMESPACE_PREFIX
namespace prefix already defined
Definition: E57Exception.h:77
@ E57_ERROR_LSEEK_FAILED
lseek() failed
Definition: E57Exception.h:66
@ E57_ERROR_PATH_UNDEFINED
E57 element path well formed but not defined.
Definition: E57Exception.h:67
@ E57_ERROR_DUPLICATE_NAMESPACE_URI
namespace URI already defined
Definition: E57Exception.h:78
constexpr uint32_t E57_FORMAT_MINOR
Definition: E57Version.h:11
std::string to_string(const T &n)
Definition: Common.h:20