|
1 |
| -#ifndef E57EXCEPTION_H |
2 |
| -#define E57EXCEPTION_H |
3 |
| - |
4 | 1 | /*
|
5 | 2 | * Copyright 2009 - 2010 Kevin Ackley ([email protected])
|
6 | 3 | *
|
|
27 | 24 | * DEALINGS IN THE SOFTWARE.
|
28 | 25 | */
|
29 | 26 |
|
| 27 | +#pragma once |
| 28 | + |
30 | 29 | #include <exception>
|
31 | 30 | #include <iostream>
|
32 | 31 | #include <string>
|
33 | 32 |
|
34 |
| -namespace e57 { |
35 |
| - |
36 |
| -//! @brief Numeric error identifiers used in E57Exception |
37 |
| -enum ErrorCode { |
38 |
| - // N.B. *** When changing error strings here, remember to update the error strings in E57Exception.cpp **** |
39 |
| - E57_SUCCESS = 0, //!< operation was successful |
40 |
| - E57_ERROR_BAD_CV_HEADER = 1, //!< a CompressedVector binary header was bad |
41 |
| - E57_ERROR_BAD_CV_PACKET = 2, //!< a CompressedVector binary packet was bad |
42 |
| - E57_ERROR_CHILD_INDEX_OUT_OF_BOUNDS = 3, //!< a numerical index identifying a child was out of bounds |
43 |
| - E57_ERROR_SET_TWICE = 4, //!< attempted to set an existing child element to a new value |
44 |
| - E57_ERROR_HOMOGENEOUS_VIOLATION = 5, //!< attempted to add an E57 Element that would have made the children of a homogenous Vector have different types |
45 |
| - E57_ERROR_VALUE_NOT_REPRESENTABLE = 6, //!< a value could not be represented in the requested type |
46 |
| - E57_ERROR_SCALED_VALUE_NOT_REPRESENTABLE = 7, //!< after scaling the result could not be represented in the requested type |
47 |
| - E57_ERROR_REAL64_TOO_LARGE = 8, //!< a 64 bit IEEE float was too large to store in a 32 bit IEEE float |
48 |
| - E57_ERROR_EXPECTING_NUMERIC = 9, //!< Expecting numeric representation in user's buffer, found ustring |
49 |
| - E57_ERROR_EXPECTING_USTRING = 10, //!< Expecting string representation in user's buffer, found numeric |
50 |
| - E57_ERROR_INTERNAL = 11, //!< An unrecoverable inconsistent internal state was detected |
51 |
| - E57_ERROR_BAD_XML_FORMAT = 12, //!< E57 primitive not encoded in XML correctly |
52 |
| - E57_ERROR_XML_PARSER = 13, //!< XML not well formed |
53 |
| - E57_ERROR_BAD_API_ARGUMENT = 14, //!< bad API function argument provided by user |
54 |
| - E57_ERROR_FILE_IS_READ_ONLY = 15, //!< can't modify read only file |
55 |
| - E57_ERROR_BAD_CHECKSUM = 16, //!< checksum mismatch, file is corrupted |
56 |
| - E57_ERROR_OPEN_FAILED = 17, //!< open() failed |
57 |
| - E57_ERROR_CLOSE_FAILED = 18, //!< close() failed |
58 |
| - E57_ERROR_READ_FAILED = 19, //!< read() failed |
59 |
| - E57_ERROR_WRITE_FAILED = 20, //!< write() failed |
60 |
| - E57_ERROR_LSEEK_FAILED = 21, //!< lseek() failed |
61 |
| - E57_ERROR_PATH_UNDEFINED = 22, //!< E57 element path well formed but not defined |
62 |
| - E57_ERROR_BAD_BUFFER = 23, //!< bad SourceDestBuffer |
63 |
| - E57_ERROR_NO_BUFFER_FOR_ELEMENT = 24, //!< no buffer specified for an element in CompressedVectorNode during write |
64 |
| - E57_ERROR_BUFFER_SIZE_MISMATCH = 25, //!< SourceDestBuffers not all same size |
65 |
| - E57_ERROR_BUFFER_DUPLICATE_PATHNAME = 26, //!< duplicate pathname in CompressedVectorNode read/write |
66 |
| - E57_ERROR_BAD_FILE_SIGNATURE = 27, //!< file signature not "ASTM-E57" |
67 |
| - E57_ERROR_UNKNOWN_FILE_VERSION = 28, //!< incompatible file version |
68 |
| - E57_ERROR_BAD_FILE_LENGTH = 29, //!< size in file header not same as actual |
69 |
| - E57_ERROR_XML_PARSER_INIT = 30, //!< XML parser failed to initialize |
70 |
| - E57_ERROR_DUPLICATE_NAMESPACE_PREFIX = 31, //!< namespace prefix already defined |
71 |
| - E57_ERROR_DUPLICATE_NAMESPACE_URI = 32, //!< namespace URI already defined |
72 |
| - E57_ERROR_BAD_PROTOTYPE = 33, //!< bad prototype in CompressedVectorNode |
73 |
| - E57_ERROR_BAD_CODECS = 34, //!< bad codecs in CompressedVectorNode |
74 |
| - E57_ERROR_VALUE_OUT_OF_BOUNDS = 35, //!< element value out of min/max bounds |
75 |
| - E57_ERROR_CONVERSION_REQUIRED = 36, //!< conversion required to assign element value, but not requested |
76 |
| - E57_ERROR_BAD_PATH_NAME = 37, //!< E57 path name is not well formed |
77 |
| - E57_ERROR_NOT_IMPLEMENTED = 38, //!< functionality not implemented |
78 |
| - E57_ERROR_BAD_NODE_DOWNCAST = 39, //!< bad downcast from Node to specific node type |
79 |
| - E57_ERROR_WRITER_NOT_OPEN = 40, //!< CompressedVectorWriter is no longer open |
80 |
| - E57_ERROR_READER_NOT_OPEN = 41, //!< CompressedVectorReader is no longer open |
81 |
| - E57_ERROR_NODE_UNATTACHED = 42, //!< node is not yet attached to tree of ImageFile |
82 |
| - E57_ERROR_ALREADY_HAS_PARENT = 43, //!< node already has a parent |
83 |
| - E57_ERROR_DIFFERENT_DEST_IMAGEFILE = 44, //!< nodes were constructed with different destImageFiles |
84 |
| - E57_ERROR_IMAGEFILE_NOT_OPEN = 45, //!< destImageFile is no longer open |
85 |
| - E57_ERROR_BUFFERS_NOT_COMPATIBLE = 46, //!< SourceDestBuffers not compatible with previously given ones |
86 |
| - E57_ERROR_TOO_MANY_WRITERS = 47, //!< too many open CompressedVectorWriters of an ImageFile |
87 |
| - E57_ERROR_TOO_MANY_READERS = 48, //!< too many open CompressedVectorReaders of an ImageFile |
88 |
| - E57_ERROR_BAD_CONFIGURATION = 49, //!< bad configuration string |
89 |
| - E57_ERROR_INVARIANCE_VIOLATION = 50 //!< class invariance constraint violation in debug mode |
90 |
| -}; |
91 |
| - |
92 |
| -class E57Exception : public std::exception |
| 33 | +namespace e57 |
93 | 34 | {
|
| 35 | + //! @brief Numeric error identifiers used in E57Exception |
| 36 | + enum ErrorCode |
| 37 | + { |
| 38 | + // N.B. *** When changing error strings here, remember to update the error |
| 39 | + // strings in E57Exception.cpp **** |
| 40 | + E57_SUCCESS = 0, //!< operation was successful |
| 41 | + E57_ERROR_BAD_CV_HEADER = 1, //!< a CompressedVector binary header was bad |
| 42 | + E57_ERROR_BAD_CV_PACKET = 2, //!< a CompressedVector binary packet was bad |
| 43 | + E57_ERROR_CHILD_INDEX_OUT_OF_BOUNDS = 3, //!< a numerical index identifying a child was out of bounds |
| 44 | + E57_ERROR_SET_TWICE = 4, //!< attempted to set an existing child element to a new value |
| 45 | + E57_ERROR_HOMOGENEOUS_VIOLATION = 5, //!< attempted to add an E57 Element that would have made the children |
| 46 | + //!< of a homogenous Vector have different types |
| 47 | + E57_ERROR_VALUE_NOT_REPRESENTABLE = 6, //!< a value could not be represented in the requested type |
| 48 | + E57_ERROR_SCALED_VALUE_NOT_REPRESENTABLE = 7, //!< after scaling the result could not be represented in the |
| 49 | + //!< requested type |
| 50 | + E57_ERROR_REAL64_TOO_LARGE = 8, //!< a 64 bit IEEE float was too large to store in a 32 bit IEEE float |
| 51 | + E57_ERROR_EXPECTING_NUMERIC = 9, //!< Expecting numeric representation in user's buffer, found ustring |
| 52 | + E57_ERROR_EXPECTING_USTRING = 10, //!< Expecting string representation in user's buffer, found numeric |
| 53 | + E57_ERROR_INTERNAL = 11, //!< An unrecoverable inconsistent internal state was detected |
| 54 | + E57_ERROR_BAD_XML_FORMAT = 12, //!< E57 primitive not encoded in XML correctly |
| 55 | + E57_ERROR_XML_PARSER = 13, //!< XML not well formed |
| 56 | + E57_ERROR_BAD_API_ARGUMENT = 14, //!< bad API function argument provided by user |
| 57 | + E57_ERROR_FILE_IS_READ_ONLY = 15, //!< can't modify read only file |
| 58 | + E57_ERROR_BAD_CHECKSUM = 16, //!< checksum mismatch, file is corrupted |
| 59 | + E57_ERROR_OPEN_FAILED = 17, //!< open() failed |
| 60 | + E57_ERROR_CLOSE_FAILED = 18, //!< close() failed |
| 61 | + E57_ERROR_READ_FAILED = 19, //!< read() failed |
| 62 | + E57_ERROR_WRITE_FAILED = 20, //!< write() failed |
| 63 | + E57_ERROR_LSEEK_FAILED = 21, //!< lseek() failed |
| 64 | + E57_ERROR_PATH_UNDEFINED = 22, //!< E57 element path well formed but not defined |
| 65 | + E57_ERROR_BAD_BUFFER = 23, //!< bad SourceDestBuffer |
| 66 | + E57_ERROR_NO_BUFFER_FOR_ELEMENT = 24, //!< no buffer specified for an element in CompressedVectorNode during |
| 67 | + //!< write |
| 68 | + E57_ERROR_BUFFER_SIZE_MISMATCH = 25, //!< SourceDestBuffers not all same size |
| 69 | + E57_ERROR_BUFFER_DUPLICATE_PATHNAME = 26, //!< duplicate pathname in CompressedVectorNode read/write |
| 70 | + E57_ERROR_BAD_FILE_SIGNATURE = 27, //!< file signature not "ASTM-E57" |
| 71 | + E57_ERROR_UNKNOWN_FILE_VERSION = 28, //!< incompatible file version |
| 72 | + E57_ERROR_BAD_FILE_LENGTH = 29, //!< size in file header not same as actual |
| 73 | + E57_ERROR_XML_PARSER_INIT = 30, //!< XML parser failed to initialize |
| 74 | + E57_ERROR_DUPLICATE_NAMESPACE_PREFIX = 31, //!< namespace prefix already defined |
| 75 | + E57_ERROR_DUPLICATE_NAMESPACE_URI = 32, //!< namespace URI already defined |
| 76 | + E57_ERROR_BAD_PROTOTYPE = 33, //!< bad prototype in CompressedVectorNode |
| 77 | + E57_ERROR_BAD_CODECS = 34, //!< bad codecs in CompressedVectorNode |
| 78 | + E57_ERROR_VALUE_OUT_OF_BOUNDS = 35, //!< element value out of min/max bounds |
| 79 | + E57_ERROR_CONVERSION_REQUIRED = 36, //!< conversion required to assign element value, but not requested |
| 80 | + E57_ERROR_BAD_PATH_NAME = 37, //!< E57 path name is not well formed |
| 81 | + E57_ERROR_NOT_IMPLEMENTED = 38, //!< functionality not implemented |
| 82 | + E57_ERROR_BAD_NODE_DOWNCAST = 39, //!< bad downcast from Node to specific node type |
| 83 | + E57_ERROR_WRITER_NOT_OPEN = 40, //!< CompressedVectorWriter is no longer open |
| 84 | + E57_ERROR_READER_NOT_OPEN = 41, //!< CompressedVectorReader is no longer open |
| 85 | + E57_ERROR_NODE_UNATTACHED = 42, //!< node is not yet attached to tree of ImageFile |
| 86 | + E57_ERROR_ALREADY_HAS_PARENT = 43, //!< node already has a parent |
| 87 | + E57_ERROR_DIFFERENT_DEST_IMAGEFILE = 44, //!< nodes were constructed with different destImageFiles |
| 88 | + E57_ERROR_IMAGEFILE_NOT_OPEN = 45, //!< destImageFile is no longer open |
| 89 | + E57_ERROR_BUFFERS_NOT_COMPATIBLE = 46, //!< SourceDestBuffers not compatible with previously given ones |
| 90 | + E57_ERROR_TOO_MANY_WRITERS = 47, //!< too many open CompressedVectorWriters of an ImageFile |
| 91 | + E57_ERROR_TOO_MANY_READERS = 48, //!< too many open CompressedVectorReaders of an ImageFile |
| 92 | + E57_ERROR_BAD_CONFIGURATION = 49, //!< bad configuration string |
| 93 | + E57_ERROR_INVARIANCE_VIOLATION = 50 //!< class invariance constraint violation in debug mode |
| 94 | + }; |
| 95 | + |
| 96 | + class E57Exception : public std::exception |
| 97 | + { |
94 | 98 | public:
|
95 |
| - void report(const char* reportingFileName=nullptr, int reportingLineNumber=0, const char* reportingFunctionName=nullptr, std::ostream& os = std::cout) const; |
96 |
| - ErrorCode errorCode() const; |
| 99 | + void report( const char *reportingFileName = nullptr, int reportingLineNumber = 0, |
| 100 | + const char *reportingFunctionName = nullptr, std::ostream &os = std::cout ) const; |
| 101 | + ErrorCode errorCode() const; |
97 | 102 | std::string context() const;
|
98 |
| - const char* what() const noexcept override; |
| 103 | + const char *what() const noexcept override; |
99 | 104 |
|
100 | 105 | // For debugging purposes:
|
101 |
| - const char* sourceFileName() const; |
102 |
| - const char* sourceFunctionName() const; |
103 |
| - int sourceLineNumber() const; |
| 106 | + const char *sourceFileName() const; |
| 107 | + const char *sourceFunctionName() const; |
| 108 | + int sourceLineNumber() const; |
104 | 109 |
|
105 |
| - //! \cond documentNonPublic The following isn't part of the API, and isn't documented. |
| 110 | + //! \cond documentNonPublic The following isn't part of the API, and isn't |
| 111 | + //! documented. |
106 | 112 | E57Exception() = delete;
|
107 |
| - E57Exception(ErrorCode ecode, const std::string &context, |
108 |
| - const std::string &srcFileName = nullptr, int srcLineNumber = 0, |
109 |
| - const char* srcFunctionName = nullptr); |
| 113 | + E57Exception( ErrorCode ecode, const std::string &context, const std::string &srcFileName = nullptr, |
| 114 | + int srcLineNumber = 0, const char *srcFunctionName = nullptr ); |
110 | 115 | ~E57Exception() noexcept override = default;
|
111 | 116 |
|
112 | 117 | protected:
|
113 |
| - ErrorCode errorCode_; |
| 118 | + ErrorCode errorCode_; |
114 | 119 | std::string context_;
|
115 | 120 | std::string sourceFileName_;
|
116 |
| - const char* sourceFunctionName_; |
117 |
| - int sourceLineNumber_; |
| 121 | + const char *sourceFunctionName_; |
| 122 | + int sourceLineNumber_; |
118 | 123 | //! \endcond
|
119 |
| -}; |
120 |
| - |
| 124 | + }; |
121 | 125 |
|
122 |
| -namespace Utilities { |
123 |
| - // Get latest version of ASTM standard supported, and library id string |
124 |
| - void getVersions(int& astmMajor, int& astmMinor, std::string& libraryId); |
| 126 | + namespace Utilities |
| 127 | + { |
| 128 | + // Get latest version of ASTM standard supported, and library id string |
| 129 | + void getVersions( int &astmMajor, int &astmMinor, std::string &libraryId ); |
125 | 130 |
|
126 |
| - std::string errorCodeToString(ErrorCode ecode); |
| 131 | + std::string errorCodeToString( ErrorCode ecode ); |
| 132 | + } |
127 | 133 | }
|
128 |
| -} |
129 |
| - |
130 |
| -#endif |
|
0 commit comments