| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| |
|
| | #pragma once |
| |
|
| | |
| |
|
| | #include <exception> |
| | #include <iostream> |
| | #include <string> |
| |
|
| | #include "E57Export.h" |
| |
|
| | #ifndef E57_ENABLE_DIAGNOSTIC_OUTPUT |
| | |
| | #define E57_UNUSED( expr ) (void)( expr ) |
| | #endif |
| |
|
| | |
| | |
| | #if ( ( defined( _MSVC_LANG ) && _MSVC_LANG >= 201703L ) || __cplusplus >= 201703L ) |
| | #define E57_DEPRECATED_ENUM( str ) [[deprecated( str )]] |
| | #else |
| | #define E57_DEPRECATED_ENUM( str ) |
| | #endif |
| |
|
| | namespace e57 |
| | { |
| | |
| | enum ErrorCode |
| | { |
| | |
| | |
| |
|
| | Success = 0, |
| |
|
| | ErrorBadCVHeader = 1, |
| | ErrorBadCVPacket = 2, |
| | ErrorChildIndexOutOfBounds = 3, |
| | ErrorSetTwice = 4, |
| |
|
| | |
| | |
| | ErrorHomogeneousViolation = 5, |
| |
|
| | |
| | ErrorValueNotRepresentable = 6, |
| |
|
| | |
| | ErrorScaledValueNotRepresentable = 7, |
| |
|
| | |
| | ErrorReal64TooLarge = 8, |
| |
|
| | |
| | ErrorExpectingNumeric = 9, |
| |
|
| | |
| | ErrorExpectingUString = 10, |
| |
|
| | ErrorInternal = 11, |
| | ErrorBadXMLFormat = 12, |
| | ErrorXMLParser = 13, |
| | ErrorBadAPIArgument = 14, |
| | ErrorFileReadOnly = 15, |
| | ErrorBadChecksum = 16, |
| | ErrorOpenFailed = 17, |
| | ErrorCloseFailed = 18, |
| | ErrorReadFailed = 19, |
| | ErrorWriteFailed = 20, |
| | ErrorSeekFailed = 21, |
| | ErrorPathUndefined = 22, |
| | ErrorBadBuffer = 23, |
| |
|
| | |
| | ErrorNoBufferForElement = 24, |
| |
|
| | ErrorBufferSizeMismatch = 25, |
| | ErrorBufferDuplicatePathName = 26, |
| | ErrorBadFileSignature = 27, |
| | ErrorUnknownFileVersion = 28, |
| | ErrorBadFileLength = 29, |
| | ErrorXMLParserInit = 30, |
| | ErrorDuplicateNamespacePrefix = 31, |
| | ErrorDuplicateNamespaceURI = 32, |
| | ErrorBadPrototype = 33, |
| | ErrorBadCodecs = 34, |
| | ErrorValueOutOfBounds = 35, |
| |
|
| | |
| | ErrorConversionRequired = 36, |
| |
|
| | ErrorBadPathName = 37, |
| | ErrorNotImplemented = 38, |
| | ErrorBadNodeDowncast = 39, |
| | ErrorWriterNotOpen = 40, |
| | ErrorReaderNotOpen = 41, |
| | ErrorNodeUnattached = 42, |
| | ErrorAlreadyHasParent = 43, |
| | ErrorDifferentDestImageFile = 44, |
| | ErrorImageFileNotOpen = 45, |
| |
|
| | |
| | ErrorBuffersNotCompatible = 46, |
| |
|
| | ErrorTooManyWriters = 47, |
| | ErrorTooManyReaders = 48, |
| | ErrorBadConfiguration = 49, |
| | ErrorInvarianceViolation = 50, |
| |
|
| | |
| | ErrorInvalidNodeType = 51, |
| |
|
| | |
| | ErrorInvalidData3DValue = 52, |
| |
|
| | |
| | |
| | ErrorData3DReadInvalidZeroRecords = 53, |
| |
|
| | |
| | E57_SUCCESS E57_DEPRECATED_ENUM( "Will be removed in 4.0. Use Success." ) = Success, |
| | |
| | E57_ERROR_BAD_CV_HEADER E57_DEPRECATED_ENUM( |
| | "Will be removed in 4.0. Use ErrorBadCVHeader." ) = ErrorBadCVHeader, |
| | |
| | E57_ERROR_BAD_CV_PACKET E57_DEPRECATED_ENUM( |
| | "Will be removed in 4.0. Use ErrorBadCVPacket." ) = ErrorBadCVPacket, |
| | |
| | E57_ERROR_CHILD_INDEX_OUT_OF_BOUNDS E57_DEPRECATED_ENUM( |
| | "Will be removed in 4.0. Use ErrorChildIndexOutOfBounds." ) = ErrorChildIndexOutOfBounds, |
| | |
| | E57_ERROR_SET_TWICE E57_DEPRECATED_ENUM( "Will be removed in 4.0. Use ErrorSetTwice." ) = |
| | ErrorSetTwice, |
| | |
| | E57_ERROR_HOMOGENEOUS_VIOLATION E57_DEPRECATED_ENUM( |
| | "Will be removed in 4.0. Use ErrorHomogeneousViolation." ) = ErrorHomogeneousViolation, |
| | |
| | E57_ERROR_VALUE_NOT_REPRESENTABLE E57_DEPRECATED_ENUM( |
| | "Will be removed in 4.0. Use ErrorValueNotRepresentable." ) = ErrorValueNotRepresentable, |
| | |
| | E57_ERROR_SCALED_VALUE_NOT_REPRESENTABLE E57_DEPRECATED_ENUM( |
| | "Will be removed in 4.0. Use ErrorScaledValueNotRepresentable." ) = |
| | ErrorScaledValueNotRepresentable, |
| | |
| | E57_ERROR_REAL64_TOO_LARGE E57_DEPRECATED_ENUM( |
| | "Will be removed in 4.0. Use ErrorReal64TooLarge." ) = ErrorReal64TooLarge, |
| | |
| | E57_ERROR_EXPECTING_NUMERIC E57_DEPRECATED_ENUM( |
| | "Will be removed in 4.0. Use ErrorExpectingNumeric." ) = ErrorExpectingNumeric, |
| | |
| | E57_ERROR_EXPECTING_USTRING E57_DEPRECATED_ENUM( |
| | "Will be removed in 4.0. Use ErrorExpectingUString." ) = ErrorExpectingUString, |
| | |
| | E57_ERROR_INTERNAL E57_DEPRECATED_ENUM( "Will be removed in 4.0. Use ErrorInternal." ) = |
| | ErrorInternal, |
| | |
| | E57_ERROR_BAD_XML_FORMAT E57_DEPRECATED_ENUM( |
| | "Will be removed in 4.0. Use ErrorBadXMLFormat." ) = ErrorBadXMLFormat, |
| | |
| | E57_ERROR_XML_PARSER E57_DEPRECATED_ENUM( "Will be removed in 4.0. Use ErrorXMLParser." ) = |
| | ErrorXMLParser, |
| | |
| | E57_ERROR_BAD_API_ARGUMENT E57_DEPRECATED_ENUM( |
| | "Will be removed in 4.0. Use ErrorBadAPIArgument." ) = ErrorBadAPIArgument, |
| | |
| | E57_ERROR_FILE_IS_READ_ONLY E57_DEPRECATED_ENUM( |
| | "Will be removed in 4.0. Use ErrorFileReadOnly." ) = ErrorFileReadOnly, |
| | |
| | E57_ERROR_BAD_CHECKSUM E57_DEPRECATED_ENUM( |
| | "Will be removed in 4.0. Use ErrorBadChecksum." ) = ErrorBadChecksum, |
| | |
| | E57_ERROR_OPEN_FAILED E57_DEPRECATED_ENUM( "Will be removed in 4.0. Use ErrorOpenFailed." ) = |
| | ErrorOpenFailed, |
| | |
| | E57_ERROR_CLOSE_FAILED E57_DEPRECATED_ENUM( |
| | "Will be removed in 4.0. Use ErrorCloseFailed." ) = ErrorCloseFailed, |
| | |
| | E57_ERROR_READ_FAILED E57_DEPRECATED_ENUM( "Will be removed in 4.0. Use ErrorReadFailed." ) = |
| | ErrorReadFailed, |
| | |
| | E57_ERROR_WRITE_FAILED E57_DEPRECATED_ENUM( |
| | "Will be removed in 4.0. Use ErrorWriteFailed." ) = ErrorWriteFailed, |
| | |
| | E57_ERROR_LSEEK_FAILED E57_DEPRECATED_ENUM( "Will be removed in 4.0. Use ErrorSeekFailed." ) = |
| | ErrorSeekFailed, |
| | |
| | E57_ERROR_PATH_UNDEFINED E57_DEPRECATED_ENUM( |
| | "Will be removed in 4.0. Use ErrorPathUndefined." ) = ErrorPathUndefined, |
| | |
| | E57_ERROR_BAD_BUFFER E57_DEPRECATED_ENUM( "Will be removed in 4.0. Use ErrorBadBuffer." ) = |
| | ErrorBadBuffer, |
| | |
| | E57_ERROR_NO_BUFFER_FOR_ELEMENT E57_DEPRECATED_ENUM( |
| | "Will be removed in 4.0. Use ErrorNoBufferForElement." ) = ErrorNoBufferForElement, |
| | |
| | E57_ERROR_BUFFER_SIZE_MISMATCH E57_DEPRECATED_ENUM( |
| | "Will be removed in 4.0. Use ErrorBufferSizeMismatch." ) = ErrorBufferSizeMismatch, |
| | |
| | E57_ERROR_BUFFER_DUPLICATE_PATHNAME E57_DEPRECATED_ENUM( |
| | "Will be removed in 4.0. Use ErrorBufferDuplicatePathName." ) = |
| | ErrorBufferDuplicatePathName, |
| | |
| | E57_ERROR_BAD_FILE_SIGNATURE E57_DEPRECATED_ENUM( |
| | "Will be removed in 4.0. Use ErrorBadFileSignature." ) = ErrorBadFileSignature, |
| | |
| | E57_ERROR_UNKNOWN_FILE_VERSION E57_DEPRECATED_ENUM( |
| | "Will be removed in 4.0. Use ErrorUnknownFileVersion." ) = ErrorUnknownFileVersion, |
| | |
| | E57_ERROR_BAD_FILE_LENGTH E57_DEPRECATED_ENUM( |
| | "Will be removed in 4.0. Use ErrorBadFileLength." ) = ErrorBadFileLength, |
| | |
| | E57_ERROR_XML_PARSER_INIT E57_DEPRECATED_ENUM( |
| | "Will be removed in 4.0. Use ErrorXMLParserInit." ) = ErrorXMLParserInit, |
| | |
| | E57_ERROR_DUPLICATE_NAMESPACE_PREFIX E57_DEPRECATED_ENUM( |
| | "Will be removed in 4.0. Use ErrorDuplicateNamespacePrefix." ) = |
| | ErrorDuplicateNamespacePrefix, |
| | |
| | E57_ERROR_DUPLICATE_NAMESPACE_URI E57_DEPRECATED_ENUM( |
| | "Will be removed in 4.0. Use ErrorDuplicateNamespaceURI." ) = ErrorDuplicateNamespaceURI, |
| | |
| | E57_ERROR_BAD_PROTOTYPE E57_DEPRECATED_ENUM( |
| | "Will be removed in 4.0. Use ErrorBadPrototype." ) = ErrorBadPrototype, |
| | |
| | E57_ERROR_BAD_CODECS E57_DEPRECATED_ENUM( "Will be removed in 4.0. Use ErrorBadCodecs." ) = |
| | ErrorBadCodecs, |
| | |
| | E57_ERROR_VALUE_OUT_OF_BOUNDS E57_DEPRECATED_ENUM( |
| | "Will be removed in 4.0. Use ErrorValueOutOfBounds." ) = ErrorValueOutOfBounds, |
| | |
| | E57_ERROR_CONVERSION_REQUIRED E57_DEPRECATED_ENUM( |
| | "Will be removed in 4.0. Use ErrorConversionRequired." ) = ErrorConversionRequired, |
| | |
| | E57_ERROR_BAD_PATH_NAME E57_DEPRECATED_ENUM( |
| | "Will be removed in 4.0. Use ErrorBadPathName." ) = ErrorBadPathName, |
| | |
| | E57_ERROR_NOT_IMPLEMENTED E57_DEPRECATED_ENUM( |
| | "Will be removed in 4.0. Use ErrorNotImplemented." ) = ErrorNotImplemented, |
| | |
| | E57_ERROR_BAD_NODE_DOWNCAST E57_DEPRECATED_ENUM( |
| | "Will be removed in 4.0. Use ErrorBadNodeDowncast." ) = ErrorBadNodeDowncast, |
| | |
| | E57_ERROR_WRITER_NOT_OPEN E57_DEPRECATED_ENUM( |
| | "Will be removed in 4.0. Use ErrorWriterNotOpen." ) = ErrorWriterNotOpen, |
| | |
| | E57_ERROR_READER_NOT_OPEN E57_DEPRECATED_ENUM( |
| | "Will be removed in 4.0. Use ErrorReaderNotOpen." ) = ErrorReaderNotOpen, |
| | |
| | E57_ERROR_NODE_UNATTACHED E57_DEPRECATED_ENUM( |
| | "Will be removed in 4.0. Use ErrorNodeUnattached." ) = ErrorNodeUnattached, |
| | |
| | E57_ERROR_ALREADY_HAS_PARENT E57_DEPRECATED_ENUM( |
| | "Will be removed in 4.0. Use ErrorAlreadyHasParent." ) = ErrorAlreadyHasParent, |
| | |
| | E57_ERROR_DIFFERENT_DEST_IMAGEFILE E57_DEPRECATED_ENUM( |
| | "Will be removed in 4.0. Use ErrorDifferentDestImageFile." ) = ErrorDifferentDestImageFile, |
| | |
| | E57_ERROR_IMAGEFILE_NOT_OPEN E57_DEPRECATED_ENUM( |
| | "Will be removed in 4.0. Use ErrorImageFileNotOpen." ) = ErrorImageFileNotOpen, |
| | |
| | E57_ERROR_BUFFERS_NOT_COMPATIBLE E57_DEPRECATED_ENUM( |
| | "Will be removed in 4.0. Use ErrorBuffersNotCompatible." ) = ErrorBuffersNotCompatible, |
| | |
| | E57_ERROR_TOO_MANY_WRITERS E57_DEPRECATED_ENUM( |
| | "Will be removed in 4.0. Use ErrorTooManyWriters." ) = ErrorTooManyWriters, |
| | |
| | E57_ERROR_TOO_MANY_READERS E57_DEPRECATED_ENUM( |
| | "Will be removed in 4.0. Use ErrorTooManyReaders." ) = ErrorTooManyReaders, |
| | |
| | E57_ERROR_BAD_CONFIGURATION E57_DEPRECATED_ENUM( |
| | "Will be removed in 4.0. Use ErrorBadConfiguration." ) = ErrorBadConfiguration, |
| | |
| | E57_ERROR_INVARIANCE_VIOLATION E57_DEPRECATED_ENUM( |
| | "Will be removed in 4.0. Use ErrorInvarianceViolation." ) = ErrorInvarianceViolation, |
| | }; |
| |
|
| | namespace Utilities |
| | { |
| | E57_DLL std::string errorCodeToString( ErrorCode ecode ) noexcept; |
| | } |
| |
|
| | class E57Exception : public std::exception |
| | { |
| | public: |
| | const char *what() const noexcept override |
| | { |
| | return "E57 exception"; |
| | } |
| |
|
| | void report( const char *reportingFileName = nullptr, int reportingLineNumber = 0, |
| | const char *reportingFunctionName = nullptr, |
| | std::ostream &os = std::cout ) const noexcept |
| | { |
| | os << "**** Got an e57 exception: " << errorStr() << std::endl; |
| |
|
| | #ifdef E57_ENABLE_DIAGNOSTIC_OUTPUT |
| | os << " Debug info: " << std::endl; |
| | os << " context: " << context_ << std::endl; |
| | os << " sourceFunctionName: " << sourceFunctionName_ << std::endl; |
| | if ( reportingFunctionName != nullptr ) |
| | { |
| | os << " reportingFunctionName: " << reportingFunctionName << std::endl; |
| | } |
| |
|
| | |
| | |
| | os << sourceFileName_ << "(" << sourceLineNumber_ << ") : error C" << errorCode_ |
| | << ": <--- occurred on" << std::endl; |
| | if ( reportingFileName != nullptr ) |
| | { |
| | os << reportingFileName << "(" << reportingLineNumber |
| | << ") : error C0: <--- reported on" << std::endl; |
| | } |
| | #else |
| | E57_UNUSED( reportingFileName ); |
| | E57_UNUSED( reportingLineNumber ); |
| | E57_UNUSED( reportingFunctionName ); |
| | #endif |
| | } |
| |
|
| | ErrorCode errorCode() const noexcept |
| | { |
| | return errorCode_; |
| | } |
| |
|
| | std::string errorStr() const noexcept |
| | { |
| | return Utilities::errorCodeToString( errorCode_ ); |
| | } |
| |
|
| | const std::string &context() const noexcept |
| | { |
| | return context_; |
| | } |
| |
|
| | |
| | const char *sourceFileName() const noexcept |
| | { |
| | return sourceFileName_.c_str(); |
| | } |
| |
|
| | const char *sourceFunctionName() const noexcept |
| | { |
| | return sourceFunctionName_; |
| | } |
| |
|
| | int sourceLineNumber() const noexcept |
| | { |
| | return sourceLineNumber_; |
| | } |
| |
|
| | |
| | E57Exception() = delete; |
| | E57Exception( ErrorCode ecode, std::string context, const char *srcFileName = nullptr, |
| | int srcLineNumber = 0, const char *srcFunctionName = nullptr ) : |
| | errorCode_( ecode ), context_( std::move( context ) ), sourceFileName_( srcFileName ), |
| | sourceFunctionName_( srcFunctionName ), sourceLineNumber_( srcLineNumber ) |
| | { |
| | } |
| | |
| |
|
| | private: |
| | |
| | ErrorCode errorCode_; |
| | std::string context_; |
| | std::string sourceFileName_; |
| | const char *sourceFunctionName_; |
| | int sourceLineNumber_; |
| | |
| | }; |
| | } |
| |
|